Commit 72aef67c authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

nghttp: Replace build-in headers completely with -H option

parent d647799c
...@@ -922,16 +922,6 @@ int submit_request ...@@ -922,16 +922,6 @@ int submit_request
const std::vector<std::pair<std::string, std::string>>& headers, const std::vector<std::pair<std::string, std::string>>& headers,
Request *req) Request *req)
{ {
enum eStaticHeaderPosition
{
POS_METHOD = 0,
POS_PATH,
POS_SCHEME,
POS_AUTHORITY,
POS_ACCEPT,
POS_ACCEPT_ENCODING,
POS_USERAGENT
};
auto path = req->make_reqpath(); auto path = req->make_reqpath();
auto scheme = get_uri_field(req->uri.c_str(), req->u, UF_SCHEMA); auto scheme = get_uri_field(req->uri.c_str(), req->u, UF_SCHEMA);
auto build_headers = std::vector<std::pair<std::string, std::string>> auto build_headers = std::vector<std::pair<std::string, std::string>>
...@@ -942,24 +932,22 @@ int submit_request ...@@ -942,24 +932,22 @@ int submit_request
{"accept", "*/*"}, {"accept", "*/*"},
{"accept-encoding", "gzip, deflate"}, {"accept-encoding", "gzip, deflate"},
{"user-agent", "nghttp2/" NGHTTP2_VERSION}}; {"user-agent", "nghttp2/" NGHTTP2_VERSION}};
auto num_initial_headers = build_headers.size();
if(req->data_prd) { if(req->data_prd) {
build_headers.emplace_back("content-length", util::utos(req->data_length)); build_headers.emplace_back("content-length", util::utos(req->data_length));
} }
for(auto& kv : headers) { for(auto& kv : headers) {
auto key = kv.first.c_str(); size_t i;
if ( util::strieq( key, "accept" ) ) { for(i = 0; i < num_initial_headers; ++i) {
build_headers[POS_ACCEPT].second = kv.second; if(util::strieq(kv.first, build_headers[i].first)) {
} build_headers[i].second = kv.second;
else if ( util::strieq( key, "user-agent" ) ) { break;
build_headers[POS_USERAGENT].second = kv.second; }
}
else if ( util::strieq( key, ":authority" ) ) {
build_headers[POS_AUTHORITY].second = kv.second;
} }
else { if(i < num_initial_headers) {
build_headers.push_back(kv); continue;
} }
build_headers.push_back(kv);
} }
std::stable_sort(std::begin(build_headers), std::end(build_headers), std::stable_sort(std::begin(build_headers), std::end(build_headers),
[](const std::pair<std::string, std::string>& lhs, [](const std::pair<std::string, std::string>& lhs,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment