nghttpx: Fill request scheme in upstream
We may log before filling scheme in Downstream, so we leave construct_absolute_request_uri as is.
This commit is contained in:
parent
b20abfc11a
commit
9a0b9428da
|
@ -706,7 +706,8 @@ std::string construct_absolute_request_uri(Downstream *downstream) {
|
||||||
}
|
}
|
||||||
std::string uri;
|
std::string uri;
|
||||||
if (downstream->get_request_http2_scheme().empty()) {
|
if (downstream->get_request_http2_scheme().empty()) {
|
||||||
// this comes from HTTP/1 upstream without scheme. Just use http.
|
// We may have to log the request which lacks scheme (e.g.,
|
||||||
|
// http/1.1 with origin form).
|
||||||
uri += "http://";
|
uri += "http://";
|
||||||
} else {
|
} else {
|
||||||
uri += downstream->get_request_http2_scheme();
|
uri += downstream->get_request_http2_scheme();
|
||||||
|
|
|
@ -330,14 +330,9 @@ int Http2DownstreamConnection::push_request_headers() {
|
||||||
http2::make_nv_ls(":authority", downstream_->get_request_path()));
|
http2::make_nv_ls(":authority", downstream_->get_request_path()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!downstream_->get_request_http2_scheme().empty()) {
|
assert(!downstream_->get_request_http2_scheme().empty());
|
||||||
nva.push_back(http2::make_nv_ls(":scheme",
|
nva.push_back(
|
||||||
downstream_->get_request_http2_scheme()));
|
http2::make_nv_ls(":scheme", downstream_->get_request_http2_scheme()));
|
||||||
} else if (client_handler_->get_ssl()) {
|
|
||||||
nva.push_back(http2::make_nv_ll(":scheme", "https"));
|
|
||||||
} else {
|
|
||||||
nva.push_back(http2::make_nv_ll(":scheme", "http"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (authority) {
|
if (authority) {
|
||||||
nva.push_back(http2::make_nv_lc(":authority", authority));
|
nva.push_back(http2::make_nv_lc(":authority", authority));
|
||||||
|
|
|
@ -107,35 +107,6 @@ int on_stream_close_callback(nghttp2_session *session, int32_t stream_id,
|
||||||
int Http2Upstream::upgrade_upstream(HttpsUpstream *http) {
|
int Http2Upstream::upgrade_upstream(HttpsUpstream *http) {
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
// to deduce :scheme and :authority, first we have to parse request
|
|
||||||
// URI.
|
|
||||||
http_parser_url u = {};
|
|
||||||
auto &url = http->get_downstream()->get_request_path();
|
|
||||||
|
|
||||||
std::string scheme, authority;
|
|
||||||
rv = http_parser_parse_url(url.c_str(), url.size(), 0, &u);
|
|
||||||
if (rv == 0) {
|
|
||||||
http2::copy_url_component(scheme, &u, UF_SCHEMA, url.c_str());
|
|
||||||
http2::copy_url_component(authority, &u, UF_HOST, url.c_str());
|
|
||||||
}
|
|
||||||
if (scheme.empty()) {
|
|
||||||
if (handler_->get_ssl()) {
|
|
||||||
scheme = "https";
|
|
||||||
} else {
|
|
||||||
scheme = "http";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!authority.empty()) {
|
|
||||||
if (authority.find(":") != std::string::npos) {
|
|
||||||
authority = "[" + authority;
|
|
||||||
authority += "]";
|
|
||||||
}
|
|
||||||
if (u.field_set & (1 << UF_PORT)) {
|
|
||||||
authority += ":";
|
|
||||||
authority += util::utos(u.port);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto http2_settings = http->get_downstream()->get_http2_settings();
|
auto http2_settings = http->get_downstream()->get_http2_settings();
|
||||||
util::to_base64(http2_settings);
|
util::to_base64(http2_settings);
|
||||||
|
|
||||||
|
@ -159,8 +130,6 @@ int Http2Upstream::upgrade_upstream(HttpsUpstream *http) {
|
||||||
downstream->reset_upstream_rtimer();
|
downstream->reset_upstream_rtimer();
|
||||||
downstream->set_stream_id(1);
|
downstream->set_stream_id(1);
|
||||||
downstream->set_priority(0);
|
downstream->set_priority(0);
|
||||||
downstream->set_request_http2_authority(authority);
|
|
||||||
downstream->set_request_http2_scheme(scheme);
|
|
||||||
|
|
||||||
auto ptr = downstream.get();
|
auto ptr = downstream.get();
|
||||||
|
|
||||||
|
|
|
@ -260,14 +260,10 @@ int HttpDownstreamConnection::push_request_headers() {
|
||||||
} else if (get_config()->http2_proxy || get_config()->client_proxy) {
|
} else if (get_config()->http2_proxy || get_config()->client_proxy) {
|
||||||
// Construct absolute-form request target because we are going to
|
// Construct absolute-form request target because we are going to
|
||||||
// send a request to a HTTP/1 proxy.
|
// send a request to a HTTP/1 proxy.
|
||||||
if (downstream_->get_request_http2_scheme().empty()) {
|
assert(!downstream_->get_request_http2_scheme().empty());
|
||||||
// this comes from HTTP/1 upstream, use http scheme. We don't
|
hdrs += downstream_->get_request_http2_scheme();
|
||||||
// support https forward link yet.
|
hdrs += "://";
|
||||||
hdrs += "http://";
|
|
||||||
} else {
|
|
||||||
hdrs += downstream_->get_request_http2_scheme();
|
|
||||||
hdrs += "://";
|
|
||||||
}
|
|
||||||
if (authority) {
|
if (authority) {
|
||||||
hdrs += authority;
|
hdrs += authority;
|
||||||
} else {
|
} else {
|
||||||
|
@ -332,14 +328,9 @@ int HttpDownstreamConnection::push_request_headers() {
|
||||||
if (!get_config()->http2_proxy && !get_config()->client_proxy &&
|
if (!get_config()->http2_proxy && !get_config()->client_proxy &&
|
||||||
downstream_->get_request_method() != "CONNECT") {
|
downstream_->get_request_method() != "CONNECT") {
|
||||||
hdrs += "X-Forwarded-Proto: ";
|
hdrs += "X-Forwarded-Proto: ";
|
||||||
if (!downstream_->get_request_http2_scheme().empty()) {
|
assert(!downstream_->get_request_http2_scheme().empty());
|
||||||
hdrs += downstream_->get_request_http2_scheme();
|
hdrs += downstream_->get_request_http2_scheme();
|
||||||
hdrs += "\r\n";
|
hdrs += "\r\n";
|
||||||
} else if (client_handler_->get_ssl()) {
|
|
||||||
hdrs += "https\r\n";
|
|
||||||
} else {
|
|
||||||
hdrs += "http\r\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
auto expect = downstream_->get_request_header(http2::HD_EXPECT);
|
auto expect = downstream_->get_request_header(http2::HD_EXPECT);
|
||||||
if (expect && !util::strifind((*expect).value.c_str(), "100-continue")) {
|
if (expect && !util::strifind((*expect).value.c_str(), "100-continue")) {
|
||||||
|
|
|
@ -219,11 +219,10 @@ void rewrite_request_host_path_from_uri(Downstream *downstream, const char *uri,
|
||||||
path.append(uri + fdata.off, fdata.len);
|
path.append(uri + fdata.off, fdata.len);
|
||||||
}
|
}
|
||||||
downstream->set_request_path(std::move(path));
|
downstream->set_request_path(std::move(path));
|
||||||
if (get_config()->http2_proxy || get_config()->client_proxy) {
|
|
||||||
std::string scheme;
|
std::string scheme;
|
||||||
http2::copy_url_component(scheme, &u, UF_SCHEMA, uri);
|
http2::copy_url_component(scheme, &u, UF_SCHEMA, uri);
|
||||||
downstream->set_request_http2_scheme(std::move(scheme));
|
downstream->set_request_http2_scheme(std::move(scheme));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -286,6 +285,12 @@ int htp_hdrs_completecb(http_parser *htp) {
|
||||||
// Request URI should be absolute-form for client proxy mode
|
// Request URI should be absolute-form for client proxy mode
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (upstream->get_client_handler()->get_ssl()) {
|
||||||
|
downstream->set_request_http2_scheme("https");
|
||||||
|
} else {
|
||||||
|
downstream->set_request_http2_scheme("http");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
rewrite_request_host_path_from_uri(downstream, uri.c_str(), u);
|
rewrite_request_host_path_from_uri(downstream, uri.c_str(), u);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue