Skip to content

Commit

Permalink
・CUtil::getMimeTypeでContent-Typeをレジストリから拡張子を検索して返すように変更
Browse files Browse the repository at this point in the history
・local.ptronで日本語のファイルをリクエストされても返せるようにした
・seekposが常に0を返すようになっていたので、streamoffへキャストするように変更
  • Loading branch information
amate committed Aug 14, 2018
1 parent 573ed40 commit 6255613
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
25 changes: 20 additions & 5 deletions Proxydomo/RequestManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1048,11 +1048,19 @@ bool CRequestManager::_HandleLocalPtron()
return true;
}

wstring filename = CUtil::makePath(subpath);
if (::PathFileExists(Misc::GetFullPath_ForExe(filename.c_str()))) {
_FakeResponse("200 OK", filename);
path filepath = CUtil::makePath(subpath);
path fullpath = (LPCWSTR)Misc::GetFullPath_ForExe(filepath.native().c_str());
if (exists(fullpath)) {
_FakeResponse("200 OK", filepath.native());
} else {
_FakeResponse("404 Not Found");
filepath = UTF16fromUTF8(CUtil::UESC(filepath.string().c_str()));
path fullpath = (LPCWSTR)Misc::GetFullPath_ForExe(filepath.native().c_str());
if (exists(fullpath)) {
_FakeResponse("200 OK", filepath.native());

} else {
_FakeResponse("404 Not Found");
}
}
while (_SendIn()); // 最後まで送信してしまう

Expand Down Expand Up @@ -1088,7 +1096,14 @@ bool CRequestManager::_HandleLocalPtron()
if (exists(fullpath)) {
_FakeResponse("200 OK", filepath.native());
} else {
_FakeResponse("404 Not Found");
filepath = UTF16fromUTF8(CUtil::UESC(filepath.string().c_str()));
path fullpath = (LPCWSTR)Misc::GetFullPath_ForExe(filepath.native().c_str());
if (exists(fullpath)) {
_FakeResponse("200 OK", filepath.native());

} else {
_FakeResponse("404 Not Found");
}
}
while (_SendIn()); // 最後まで送信してしまう

Expand Down
22 changes: 18 additions & 4 deletions Proxydomo/proximodo/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
#include <iomanip>
#include <boost\optional.hpp>
#include <Windows.h>
#include <atlbase.h>
#include "..\Misc.h"
#include "..\CodeConvert.h"

using namespace std;

Expand Down Expand Up @@ -623,7 +625,7 @@ string CUtil::getFile(string filename) {
auto eofPos = fs.tellg();
fs.clear();
fs.seekg(0, std::ios::beg);
size_t fileSize = (size_t)eofPos.seekpos();
auto fileSize = (streamoff)eofPos;

std::string content;
content.resize(fileSize);
Expand All @@ -644,8 +646,8 @@ string CUtil::getFile(wstring filename) {
auto eofPos = fs.tellg();
fs.clear();
fs.seekg(0, std::ios::beg);
size_t fileSize = (size_t)eofPos.seekpos();

auto fileSize = (streamoff)eofPos;
std::string content;
content.resize(fileSize);
fs.read(const_cast<char*>(content.data()), fileSize);
Expand All @@ -659,6 +661,7 @@ string CUtil::getMimeType(string filename) {
if (dot == string::npos)
return "application/octet-stream";
string ext = filename.substr(dot+1);
lower(ext);
//wxString mime;
//wxFileType* type = wxTheMimeTypesManager->GetFileTypeFromExtension(S2W(ext));
//if (type != NULL && type->GetMimeType(&mime))
Expand All @@ -682,6 +685,17 @@ string CUtil::getMimeType(string filename) {
else if (ext == "json")
return "application/json";

CRegKey reg;
LSTATUS ret = reg.Open(HKEY_CLASSES_ROOT, CodeConvert::UTF16fromUTF8((std::string(".") + ext)).c_str(), KEY_READ);
if (ret == ERROR_SUCCESS) {
WCHAR contentType[128] = L"";
ULONG length = 128;
ret = reg.QueryStringValue(L"Content Type", contentType, &length);
if (ret == ERROR_SUCCESS) {
return CodeConvert::UTF8fromUTF16(contentType);
}
}

return "application/octet-stream";
}

Expand Down Expand Up @@ -987,7 +1001,7 @@ std::vector<uint8_t> CUtil::LoadBinaryFile(const std::wstring& filePath)
auto eofPos = fs.tellg();
fs.clear();
fs.seekg(0, std::ios::beg);
size_t fileSize = (size_t)eofPos.seekpos();
auto fileSize = (streamoff)eofPos;

std::vector<uint8_t> vec(fileSize);
fs.read((char*)vec.data(), fileSize);
Expand Down

0 comments on commit 6255613

Please sign in to comment.