nghttp: Allow multiple same headers in -H
This commit is contained in:
parent
3d863ed254
commit
0c669898a4
|
@ -92,7 +92,7 @@ struct Config {
|
||||||
std::string keyfile;
|
std::string keyfile;
|
||||||
int window_bits;
|
int window_bits;
|
||||||
int connection_window_bits;
|
int connection_window_bits;
|
||||||
std::map<std::string, std::string> headers;
|
std::vector<std::pair<std::string, std::string>> headers;
|
||||||
std::string datafile;
|
std::string datafile;
|
||||||
size_t output_upper_thres;
|
size_t output_upper_thres;
|
||||||
ssize_t peer_max_concurrent_streams;
|
ssize_t peer_max_concurrent_streams;
|
||||||
|
@ -399,8 +399,9 @@ struct HttpClient;
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
int submit_request(HttpClient *client,
|
int submit_request
|
||||||
const std::map<std::string, std::string>& headers,
|
(HttpClient *client,
|
||||||
|
const std::vector<std::pair<std::string, std::string>>& headers,
|
||||||
Request *req);
|
Request *req);
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -494,8 +495,13 @@ struct HttpClient {
|
||||||
// If the user overrode the host header, use that value for the
|
// If the user overrode the host header, use that value for the
|
||||||
// SNI extension
|
// SNI extension
|
||||||
const char *host_string = nullptr;
|
const char *host_string = nullptr;
|
||||||
auto i = config.headers.find( "Host" );
|
auto i = std::find_if(std::begin(config.headers),
|
||||||
if ( i != config.headers.end() ) {
|
std::end(config.headers),
|
||||||
|
[](const std::pair<std::string, std::string>& nv)
|
||||||
|
{
|
||||||
|
return util::strieq("host", nv.first.c_str());
|
||||||
|
});
|
||||||
|
if ( i != std::end(config.headers) ) {
|
||||||
host_string = (*i).second.c_str();
|
host_string = (*i).second.c_str();
|
||||||
} else {
|
} else {
|
||||||
host_string = host.c_str();
|
host_string = host.c_str();
|
||||||
|
@ -897,8 +903,9 @@ http_parser_settings htp_hooks = {
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
int submit_request(HttpClient *client,
|
int submit_request
|
||||||
const std::map<std::string, std::string>& headers,
|
(HttpClient *client,
|
||||||
|
const std::vector<std::pair<std::string, std::string>>& headers,
|
||||||
Request *req)
|
Request *req)
|
||||||
{
|
{
|
||||||
enum eStaticHeaderPosition
|
enum eStaticHeaderPosition
|
||||||
|
@ -934,9 +941,6 @@ int submit_request(HttpClient *client,
|
||||||
|
|
||||||
memcpy(nv.get(), static_nv, hardcoded_entry_count * sizeof(*static_nv));
|
memcpy(nv.get(), static_nv, hardcoded_entry_count * sizeof(*static_nv));
|
||||||
|
|
||||||
auto i = std::begin(headers);
|
|
||||||
auto end = std::end(headers);
|
|
||||||
|
|
||||||
int pos = hardcoded_entry_count;
|
int pos = hardcoded_entry_count;
|
||||||
|
|
||||||
std::string content_length_str;
|
std::string content_length_str;
|
||||||
|
@ -945,9 +949,9 @@ int submit_request(HttpClient *client,
|
||||||
nv[pos++] = "content-length";
|
nv[pos++] = "content-length";
|
||||||
nv[pos++] = content_length_str.c_str();
|
nv[pos++] = content_length_str.c_str();
|
||||||
}
|
}
|
||||||
while( i != end ) {
|
for(auto& kv : headers) {
|
||||||
auto key = (*i).first.c_str();
|
auto key = kv.first.c_str();
|
||||||
auto value = (*i).second.c_str();
|
auto value = kv.second.c_str();
|
||||||
if ( util::strieq( key, "accept" ) ) {
|
if ( util::strieq( key, "accept" ) ) {
|
||||||
nv[POS_ACCEPT*2+1] = value;
|
nv[POS_ACCEPT*2+1] = value;
|
||||||
}
|
}
|
||||||
|
@ -962,7 +966,6 @@ int submit_request(HttpClient *client,
|
||||||
nv[pos+1] = value;
|
nv[pos+1] = value;
|
||||||
pos += 2;
|
pos += 2;
|
||||||
}
|
}
|
||||||
++i;
|
|
||||||
}
|
}
|
||||||
nv[pos] = nullptr;
|
nv[pos] = nullptr;
|
||||||
|
|
||||||
|
@ -1734,7 +1737,7 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
// Note that there is no processing currently to handle multiple
|
// Note that there is no processing currently to handle multiple
|
||||||
// message-header fields with the same field name
|
// message-header fields with the same field name
|
||||||
config.headers.insert(std::pair<std::string,std::string>(header, value));
|
config.headers.emplace_back(header, value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'a':
|
case 'a':
|
||||||
|
|
Loading…
Reference in New Issue