From bff0beacb477bdefc4c8fc363ba3f04a9c6d79f7 Mon Sep 17 00:00:00 2001 From: Benedikt Christoph Wolters Date: Sat, 14 Jan 2017 11:33:39 +0100 Subject: [PATCH] Fix authority for --get-assets if IP adress is used in conjunction with user-defined :authority header --- src/nghttp.cc | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/nghttp.cc b/src/nghttp.cc index 7615fe36..d01e7638 100644 --- a/src/nghttp.cc +++ b/src/nghttp.cc @@ -1596,20 +1596,32 @@ void update_html_parser(HttpClient *client, Request *req, const uint8_t *data, auto res_type = p.second; http_parser_url u{}; - if (http_parser_parse_url(uri.c_str(), uri.size(), 0, &u) == 0 && - util::fieldeq(uri.c_str(), u, req->uri.c_str(), req->u, UF_SCHEMA) && - util::fieldeq(uri.c_str(), u, req->uri.c_str(), req->u, UF_HOST) && - util::porteq(uri.c_str(), u, req->uri.c_str(), req->u)) { - // No POST data for assets - auto pri_spec = resolve_dep(res_type); + if (http_parser_parse_url(uri.c_str(), uri.size(), 0, &u) == 0) { - if (client->add_request(uri, nullptr, 0, pri_spec, req->level + 1)) { - - submit_request(client, config.headers, client->reqvec.back().get()); + const char *host_string = nullptr; + auto found = + std::find_if(std::begin(req->req_nva), std::end(req->req_nva), + [](const Header &nv) { + return ":authority" == nv.name || "host" == nv.name; + }); + if (found != std::end(config.headers)) { + host_string = (*found).value.c_str(); } + + if(util::fieldeq(uri.c_str(), u, req->uri.c_str(), req->u, UF_SCHEMA) && + (util::fieldeq(uri.c_str(), u, req->uri.c_str(), req->u, UF_HOST) || + (host_string!= nullptr && util::fieldeq(uri.c_str(), u, UF_HOST, host_string))) && + util::porteq(uri.c_str(), u, req->uri.c_str(), req->u)) { + // No POST data for assets + auto pri_spec = resolve_dep(res_type); + + if (client->add_request(uri, nullptr, 0, pri_spec, req->level + 1)) { + submit_request(client, config.headers, client->reqvec.back().get()); + } + } + req->html_parser->clear_links(); } } - req->html_parser->clear_links(); } } // namespace