diff --git a/src/core/hle/service/http/http_c.cpp b/src/core/hle/service/http/http_c.cpp index 0eed95c4a4..8d3de3d911 100644 --- a/src/core/hle/service/http/http_c.cpp +++ b/src/core/hle/service/http/http_c.cpp @@ -137,8 +137,8 @@ static ssize_t WriteHeaders(httplib::Stream& strm, return write_len; } -static size_t HeaderWriteHandler(std::vector& pending_headers, - httplib::Stream& strm, httplib::Headers& httplib_headers) { +static size_t HandleHeaderWrite(std::vector& pending_headers, + httplib::Stream& strm, httplib::Headers& httplib_headers) { std::vector final_headers; std::vector::iterator it_p; httplib::Headers::iterator it_h; @@ -148,6 +148,7 @@ static size_t HeaderWriteHandler(std::vector& pending_he [&str](Context::RequestHeader& rh) { return rh.name == str; }); }; + // Watch out for header ordering!! // First: Host it_p = find_pending_header("Host"); if (it_p != pending_headers.end()) { @@ -160,14 +161,13 @@ static size_t HeaderWriteHandler(std::vector& pending_he } } - // Second: Content-Type (optional, ignore httplib) - it_p = find_pending_header("Content-Type"); - if (it_p != pending_headers.end()) { - final_headers.push_back(Context::RequestHeader(it_p->name, it_p->value)); - pending_headers.erase(it_p); + // Second, user defined headers + // Third, Content-Type (optional, appended by MakeRequest) + for (const auto& header : pending_headers) { + final_headers.push_back(header); } - // Third: Content-Length + // Fourth: Content-Length it_p = find_pending_header("Content-Length"); if (it_p != pending_headers.end()) { final_headers.push_back(Context::RequestHeader(it_p->name, it_p->value)); @@ -179,11 +179,6 @@ static size_t HeaderWriteHandler(std::vector& pending_he } } - // Finally, user defined headers - for (const auto& header : pending_headers) { - final_headers.push_back(header); - } - return WriteHeaders(strm, final_headers); }; @@ -212,12 +207,15 @@ void Context::MakeRequest() { return true; }; - // Watch out for header ordering!! auto header_writter = [&pending_headers](httplib::Stream& strm, httplib::Headers& httplib_headers) { - return HeaderWriteHandler(pending_headers, strm, httplib_headers); + return HandleHeaderWrite(pending_headers, strm, httplib_headers); }; + for (const auto& header : headers) { + pending_headers.push_back(header); + } + if (!post_data.empty()) { pending_headers.push_back( Context::RequestHeader("Content-Type", "application/x-www-form-urlencoded")); @@ -225,10 +223,6 @@ void Context::MakeRequest() { boost::replace_all(request.body, "*", "%2A"); } - for (const auto& header : headers) { - pending_headers.push_back(header); - } - if (!post_data_raw.empty()) { request.body = post_data_raw; }