nghttp: Replace build-in headers completely with -H option
This commit is contained in:
parent
d647799c6f
commit
72aef67cca
|
@ -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,25 +932,23 @@ 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;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if ( util::strieq( key, "user-agent" ) ) {
|
|
||||||
build_headers[POS_USERAGENT].second = kv.second;
|
|
||||||
}
|
}
|
||||||
else if ( util::strieq( key, ":authority" ) ) {
|
if(i < num_initial_headers) {
|
||||||
build_headers[POS_AUTHORITY].second = kv.second;
|
continue;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
build_headers.push_back(kv);
|
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,
|
||||||
const std::pair<std::string, std::string>& rhs)
|
const std::pair<std::string, std::string>& rhs)
|
||||||
|
|
Loading…
Reference in New Issue