nghttpx: Don't rewrite path if http2 proxy or client proxy is enabled

There are many requests which changes its meaning when we rewrite
path.  This is due to bad percent-encoding in URI; reserved characters
are just used without percent encoding.  It seems this is common in ad
services, but I suspect more to come.  For reverse proxying situation,
sane service most likely encodes URI properly, so probably this is not
an issue.
This commit is contained in:
Tatsuhiro Tsujikawa 2015-07-11 17:50:58 +09:00
parent 1a63cd94aa
commit fa7069a273
3 changed files with 19 additions and 7 deletions

View File

@ -301,9 +301,13 @@ int Http2Upstream::on_request_headers(Downstream *downstream,
downstream->set_request_http2_scheme(http2::value_to_str(scheme)); downstream->set_request_http2_scheme(http2::value_to_str(scheme));
downstream->set_request_http2_authority(http2::value_to_str(authority)); downstream->set_request_http2_authority(http2::value_to_str(authority));
if (path) { if (path) {
auto &value = path->value; if (get_config()->http2_proxy || get_config()->client_proxy) {
downstream->set_request_path( downstream->set_request_path(http2::value_to_str(path));
http2::rewrite_clean_path(std::begin(value), std::end(value))); } else {
auto &value = path->value;
downstream->set_request_path(
http2::rewrite_clean_path(std::begin(value), std::end(value)));
}
} }
if (!(frame->hd.flags & NGHTTP2_FLAG_END_STREAM)) { if (!(frame->hd.flags & NGHTTP2_FLAG_END_STREAM)) {

View File

@ -218,8 +218,12 @@ void rewrite_request_host_path_from_uri(Downstream *downstream, const char *uri,
path += '?'; path += '?';
path.append(uri + fdata.off, fdata.len); path.append(uri + fdata.off, fdata.len);
} }
downstream->set_request_path( if (get_config()->http2_proxy || get_config()->client_proxy) {
http2::rewrite_clean_path(std::begin(path), std::end(path))); downstream->set_request_path(std::move(path));
} else {
downstream->set_request_path(
http2::rewrite_clean_path(std::begin(path), std::end(path)));
}
std::string scheme; std::string scheme;
http2::copy_url_component(scheme, &u, UF_SCHEMA, uri); http2::copy_url_component(scheme, &u, UF_SCHEMA, uri);

View File

@ -229,8 +229,12 @@ void on_ctrl_recv_callback(spdylay_session *session, spdylay_frame_type type,
} else { } else {
downstream->set_request_http2_scheme(scheme->value); downstream->set_request_http2_scheme(scheme->value);
downstream->set_request_http2_authority(host->value); downstream->set_request_http2_authority(host->value);
downstream->set_request_path(http2::rewrite_clean_path( if (get_config()->http2_proxy || get_config()->client_proxy) {
std::begin(path->value), std::end(path->value))); downstream->set_request_path(path->value);
} else {
downstream->set_request_path(http2::rewrite_clean_path(
std::begin(path->value), std::end(path->value)));
}
} }
if (!(frame->syn_stream.hd.flags & SPDYLAY_CTRL_FLAG_FIN)) { if (!(frame->syn_stream.hd.flags & SPDYLAY_CTRL_FLAG_FIN)) {