Commit e9555989 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

nghttpx: Remove downstream_port from location rewrite code

parent 9afebcb2
......@@ -443,8 +443,7 @@ std::string rewrite_location_uri(const std::string& uri,
const http_parser_url& u,
const std::string& request_host,
const std::string& upstream_scheme,
uint16_t upstream_port,
uint16_t downstream_port)
uint16_t upstream_port)
{
// We just rewrite host and optionally port. We don't rewrite https
// link. Not sure it happens in practice.
......
......@@ -175,8 +175,7 @@ void dump_nv(FILE *out, const nghttp2_nv *nva, size_t nvlen);
// stores the result of parsed |uri|. The |request_host| is the host
// or :authority header field value in the request. The
// |upstream_scheme| is either "https" or "http" in the upstream
// interface. The |downstream_port| is the port in the downstream
// connection.
// interface.
//
// This function returns the new rewritten URI on success. If the
// location URI is not subject to the rewrite, this function returns
......@@ -185,8 +184,7 @@ std::string rewrite_location_uri(const std::string& uri,
const http_parser_url& u,
const std::string& request_host,
const std::string& upstream_scheme,
uint16_t upstream_port,
uint16_t downstream_port);
uint16_t upstream_port);
} // namespace http2
......
......@@ -229,15 +229,13 @@ void check_rewrite_location_uri(const std::string& new_uri,
const std::string& uri,
const std::string& req_host,
const std::string& upstream_scheme,
uint16_t upstream_port,
uint16_t downstream_port)
uint16_t upstream_port)
{
http_parser_url u;
CU_ASSERT(0 == http_parser_parse_url(uri.c_str(), uri.size(), 0, &u));
CU_ASSERT(new_uri ==
http2::rewrite_location_uri(uri, u, req_host,
upstream_scheme, upstream_port,
downstream_port));
upstream_scheme, upstream_port));
}
} // namespace
......@@ -245,31 +243,31 @@ void test_http2_rewrite_location_uri(void)
{
check_rewrite_location_uri("https://localhost:3000/alpha?bravo#charlie",
"http://localhost:3001/alpha?bravo#charlie",
"localhost:3001", "https", 3000, 3001);
"localhost:3001", "https", 3000);
check_rewrite_location_uri("https://localhost/",
"http://localhost:3001/",
"localhost:3001", "https", 443, 3001);
"localhost:3001", "https", 443);
check_rewrite_location_uri("http://localhost/",
"http://localhost:3001/",
"localhost:3001", "http", 80, 3001);
"localhost:3001", "http", 80);
check_rewrite_location_uri("http://localhost:443/",
"http://localhost:3001/",
"localhost:3001", "http", 443, 3001);
"localhost:3001", "http", 443);
check_rewrite_location_uri("https://localhost:80/",
"http://localhost:3001/",
"localhost:3001", "https", 80, 3001);
"localhost:3001", "https", 80);
check_rewrite_location_uri("",
"http://localhost:3001/",
"127.0.0.1", "https", 3000, 3001);
"127.0.0.1", "https", 3000);
check_rewrite_location_uri("https://localhost:3000/",
"http://localhost:3001/",
"localhost", "https", 3000, 3001);
"localhost", "https", 3000);
check_rewrite_location_uri("",
"https://localhost:3001/",
"localhost", "https", 3000, 3001);
"localhost", "https", 3000);
check_rewrite_location_uri("https://localhost:3000/",
"http://localhost/",
"localhost", "https", 3000, 80);
"localhost", "https", 3000);
}
} // namespace shrpx
......@@ -489,8 +489,7 @@ Headers::const_iterator Downstream::get_norm_response_header
void Downstream::rewrite_norm_location_response_header
(const std::string& upstream_scheme,
uint16_t upstream_port,
uint16_t downstream_port)
uint16_t upstream_port)
{
auto hd = get_norm_header(response_headers_, "location");
if(hd == std::end(response_headers_)) {
......@@ -506,8 +505,7 @@ void Downstream::rewrite_norm_location_response_header
if(!request_http2_authority_.empty()) {
new_uri = http2::rewrite_location_uri((*hd).second, u,
request_http2_authority_,
upstream_scheme, upstream_port,
downstream_port);
upstream_scheme, upstream_port);
}
if(new_uri.empty()) {
auto host = get_norm_request_header("host");
......@@ -515,8 +513,7 @@ void Downstream::rewrite_norm_location_response_header
return;
}
new_uri = http2::rewrite_location_uri((*hd).second, u, (*host).second,
upstream_scheme, upstream_port,
downstream_port);
upstream_scheme, upstream_port);
}
if(!new_uri.empty()) {
(*hd).second = std::move(new_uri);
......
......@@ -160,8 +160,7 @@ public:
// normalize_request_headers().
void rewrite_norm_location_response_header
(const std::string& upstream_scheme,
uint16_t upstream_port,
uint16_t downstream_port);
uint16_t upstream_port);
void add_response_header(std::string name, std::string value);
void set_last_response_header_value(std::string value);
......
......@@ -152,7 +152,7 @@ void test_downstream_rewrite_norm_location_response_header(void)
Downstream d(nullptr, 0, 0);
d.add_request_header("host", "localhost:3000");
d.add_response_header("location", "http://localhost:3000/");
d.rewrite_norm_location_response_header("https", 443, 3000);
d.rewrite_norm_location_response_header("https", 443);
auto location = d.get_norm_response_header("location");
CU_ASSERT("https://localhost/" == (*location).second);
}
......@@ -160,7 +160,7 @@ void test_downstream_rewrite_norm_location_response_header(void)
Downstream d(nullptr, 0, 0);
d.set_request_http2_authority("localhost");
d.add_response_header("location", "http://localhost/");
d.rewrite_norm_location_response_header("https", 443, 80);
d.rewrite_norm_location_response_header("https", 443);
auto location = d.get_norm_response_header("location");
CU_ASSERT("https://localhost/" == (*location).second);
}
......
......@@ -946,8 +946,7 @@ int Http2Upstream::on_downstream_header_complete(Downstream *downstream)
}
downstream->normalize_response_headers();
downstream->rewrite_norm_location_response_header
(get_client_handler()->get_upstream_scheme(), get_config()->port,
get_config()->downstream_port);
(get_client_handler()->get_upstream_scheme(), get_config()->port);
downstream->concat_norm_response_headers();
auto end_headers = std::end(downstream->get_response_headers());
size_t nheader = downstream->get_response_headers().size();
......
......@@ -657,8 +657,7 @@ int HttpsUpstream::on_downstream_header_complete(Downstream *downstream)
hdrs += "\r\n";
downstream->normalize_response_headers();
downstream->rewrite_norm_location_response_header
(get_client_handler()->get_upstream_scheme(), get_config()->port,
get_config()->downstream_port);
(get_client_handler()->get_upstream_scheme(), get_config()->port);
auto end_headers = std::end(downstream->get_response_headers());
http2::build_http1_headers_from_norm_headers
(hdrs, downstream->get_response_headers());
......
......@@ -841,8 +841,7 @@ int SpdyUpstream::on_downstream_header_complete(Downstream *downstream)
}
downstream->normalize_response_headers();
downstream->rewrite_norm_location_response_header
(get_client_handler()->get_upstream_scheme(), get_config()->port,
get_config()->downstream_port);
(get_client_handler()->get_upstream_scheme(), get_config()->port);
size_t nheader = downstream->get_response_headers().size();
// 6 means :status, :version and possible via header field.
auto nv = util::make_unique<const char*[]>(nheader * 2 + 6 + 1);
......
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