Skip to content

Commit

Permalink
Fix #1973
Browse files Browse the repository at this point in the history
  • Loading branch information
yhirose committed Nov 13, 2024
1 parent 15ba61b commit 4d2e9b0
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -2910,8 +2910,14 @@ inline bool mmap::open(const char *path) {

#if defined(_WIN32)
std::wstring wpath;
for (size_t i = 0; i < strlen(path); i++) {
wpath += path[i];
{
auto len = static_cast<int>(strlen(path));
auto wlen = ::MultiByteToWideChar(CP_UTF8, 0, path, len, nullptr, 0);
if (!wlen) { return false; }
wpath.resize(wlen);
wlen = ::MultiByteToWideChar(CP_UTF8, 0, path, len,
reinterpret_cast<LPWSTR>(wpath.data()), wlen);
if (wlen != wpath.size()) { return false; }
}

#if _WIN32_WINNT >= _WIN32_WINNT_WIN8
Expand Down Expand Up @@ -7679,6 +7685,19 @@ inline bool ClientImpl::write_request(Stream &strm, Request &req,

if (!req.has_header("Accept")) { req.set_header("Accept", "*/*"); }

// TODO: #1975: 'Accept-Encoding'
if (!req.has_header("Accept-Encoding")) {
std::string accept_encoding;
#ifdef CPPHTTPLIB_BROTLI_SUPPORT
accept_encoding = "br";
#endif
#ifdef CPPHTTPLIB_ZLIB_SUPPORT
if (!accept_encoding.empty()) { accept_encoding += ", "; }
accept_encoding += "gzip, deflate";
#endif
req.set_header("Accept-Encoding", accept_encoding);
}

#ifndef CPPHTTPLIB_NO_DEFAULT_USER_AGENT
if (!req.has_header("User-Agent")) {
auto agent = std::string("cpp-httplib/") + CPPHTTPLIB_VERSION;
Expand Down

0 comments on commit 4d2e9b0

Please sign in to comment.