nghttp: Use Headers to store custom headers

This commit is contained in:
Tatsuhiro Tsujikawa 2014-10-21 23:24:50 +09:00
parent 73955f0519
commit e3af9d8bd3
1 changed files with 14 additions and 20 deletions

View File

@ -80,7 +80,7 @@ namespace nghttp2 {
namespace { namespace {
struct Config { struct Config {
std::vector<std::pair<std::string, std::string>> headers; Headers headers;
std::string certfile; std::string certfile;
std::string keyfile; std::string keyfile;
std::string datafile; std::string datafile;
@ -410,9 +410,7 @@ struct HttpClient;
namespace { namespace {
int submit_request int submit_request
(HttpClient *client, (HttpClient *client, const Headers& headers, Request *req);
const std::vector<std::pair<std::string, std::string>>& headers,
Request *req);
} // namespace } // namespace
namespace { namespace {
@ -532,12 +530,12 @@ struct HttpClient {
const char *host_string = nullptr; const char *host_string = nullptr;
auto i = std::find_if(std::begin(config.headers), auto i = std::find_if(std::begin(config.headers),
std::end(config.headers), std::end(config.headers),
[](const std::pair<std::string, std::string>& nv) [](const Header& nv)
{ {
return "host" == nv.first; return "host" == nv.name;
}); });
if ( i != std::end(config.headers) ) { if ( i != std::end(config.headers) ) {
host_string = (*i).second.c_str(); host_string = (*i).value.c_str();
} else { } else {
host_string = host.c_str(); host_string = host.c_str();
} }
@ -1015,9 +1013,7 @@ http_parser_settings htp_hooks = {
namespace { namespace {
int submit_request int submit_request
(HttpClient *client, (HttpClient *client, const Headers& headers, Request *req)
const std::vector<std::pair<std::string, std::string>>& headers,
Request *req)
{ {
auto path = req->make_reqpath(); auto path = req->make_reqpath();
auto scheme = util::get_uri_field(req->uri.c_str(), req->u, UF_SCHEMA); auto scheme = util::get_uri_field(req->uri.c_str(), req->u, UF_SCHEMA);
@ -1042,8 +1038,8 @@ int submit_request
for(auto& kv : headers) { for(auto& kv : headers) {
size_t i; size_t i;
for(i = 0; i < num_initial_headers; ++i) { for(i = 0; i < num_initial_headers; ++i) {
if(kv.first == build_headers[i].name) { if(kv.name == build_headers[i].name) {
build_headers[i].value = kv.second; build_headers[i].value = kv.value;
break; break;
} }
} }
@ -1051,10 +1047,7 @@ int submit_request
continue; continue;
} }
// To test "never index" repr, don't index authorization header build_headers.emplace_back(kv.name, kv.value, kv.no_index);
// field unconditionally.
auto no_index = kv.first == "authorization";
build_headers.emplace_back(kv.first, kv.second, no_index);
} }
std::stable_sort(std::begin(build_headers), std::end(build_headers), std::stable_sort(std::begin(build_headers), std::end(build_headers),
http2::name_less); http2::name_less);
@ -2127,10 +2120,11 @@ int main(int argc, char **argv)
<< std::endl; << std::endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
// Note that there is no processing currently to handle multiple // To test "never index" repr, don't index authorization header
// message-header fields with the same field name // field unconditionally.
config.headers.emplace_back(header, value); auto no_index = util::strieq("authorization", header);
util::inp_strlower(config.headers.back().first); config.headers.emplace_back(header, value, no_index);
util::inp_strlower(config.headers.back().name);
break; break;
} }
case 'a': case 'a':