From 24cfb52b5a77c696a345daca7e0dba0a4ba48b9b Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 10 Aug 2014 12:39:27 +0900 Subject: [PATCH] nghttpx: Add --no-location-rewrite option --no-location-rewrite option disallows location header rewrite on --http2-bridge, --client and default mode. This option is useful when connecting nghttpx proxy with --http2-bridge to backend nghttpx with http2-proxy mode. --- src/shrpx.cc | 12 ++++++++++++ src/shrpx_config.cc | 7 +++++++ src/shrpx_config.h | 2 ++ src/shrpx_http2_upstream.cc | 3 ++- src/shrpx_https_upstream.cc | 3 ++- src/shrpx_spdy_upstream.cc | 3 ++- 6 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/shrpx.cc b/src/shrpx.cc index a1fcfae1..1967158a 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -569,6 +569,7 @@ void fill_default_config() mod_config()->tls_proto_mask = 0; mod_config()->cached_time = generate_time(); + mod_config()->no_location_rewrite = false; } } // namespace @@ -873,6 +874,12 @@ Misc: downstream request. --no-via Don't append to Via header field. If Via header field is received, it is left unaltered. + --no-location-rewrite + Don't rewrite location header field on + --http2-bridge, --client and default mode. For + --http2-proxy and --client-proxy mode, location + header field will not be altered regardless of + this option. --altsvc= Specify protocol ID, port, host and origin of alternative service. and are @@ -995,6 +1002,7 @@ int main(int argc, char **argv) {"errorlog-syslog", no_argument, &flag, 59}, {"stream-read-timeout", required_argument, &flag, 60}, {"stream-write-timeout", required_argument, &flag, 61}, + {"no-location-rewrite", no_argument, &flag, 62}, {nullptr, 0, nullptr, 0 } }; @@ -1263,6 +1271,10 @@ int main(int argc, char **argv) // --stream-write-timeout cmdcfgs.emplace_back(SHRPX_OPT_STREAM_WRITE_TIMEOUT, optarg); break; + case 62: + // --no-location-rewrite + cmdcfgs.emplace_back(SHRPX_OPT_NO_LOCATION_REWRITE, "yes"); + break; default: break; } diff --git a/src/shrpx_config.cc b/src/shrpx_config.cc index 9c2b3cec..a8166fb1 100644 --- a/src/shrpx_config.cc +++ b/src/shrpx_config.cc @@ -124,6 +124,7 @@ const char SHRPX_OPT_ALTSVC[] = "altsvc"; const char SHRPX_OPT_ADD_RESPONSE_HEADER[] = "add-response-header"; const char SHRPX_OPT_WORKER_FRONTEND_CONNECTIONS[] = "worker-frontend-connections"; +const char SHRPX_OPT_NO_LOCATION_REWRITE[] = "no-location-rewrite"; namespace { Config *config = nullptr; @@ -840,6 +841,12 @@ int parse_config(const char *opt, const char *optarg) return 0; } + if(util::strieq(opt, SHRPX_OPT_NO_LOCATION_REWRITE)) { + mod_config()->no_location_rewrite = util::strieq(optarg, "yes"); + + return 0; + } + if(util::strieq(opt, "conf")) { LOG(WARNING) << "conf is ignored"; diff --git a/src/shrpx_config.h b/src/shrpx_config.h index 2ebeff83..59b907f1 100644 --- a/src/shrpx_config.h +++ b/src/shrpx_config.h @@ -114,6 +114,7 @@ extern const char SHRPX_OPT_PADDING[]; extern const char SHRPX_OPT_ALTSVC[]; extern const char SHRPX_OPT_ADD_RESPONSE_HEADER[]; extern const char SHRPX_OPT_WORKER_FRONTEND_CONNECTIONS[]; +extern const char SHRPX_OPT_NO_LOCATION_REWRITE[]; union sockaddr_union { sockaddr sa; @@ -259,6 +260,7 @@ struct Config { bool backend_ipv6; bool http2_no_cookie_crumbling; bool upstream_frame_debug; + bool no_location_rewrite; }; const Config* get_config(); diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index 8706a050..c0e0ff1c 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -1174,7 +1174,8 @@ int Http2Upstream::on_downstream_header_complete(Downstream *downstream) } downstream->normalize_response_headers(); - if(!get_config()->http2_proxy && !get_config()->client_proxy) { + if(!get_config()->http2_proxy && !get_config()->client_proxy && + !get_config()->no_location_rewrite) { downstream->rewrite_norm_location_response_header (get_client_handler()->get_upstream_scheme(), get_config()->port); } diff --git a/src/shrpx_https_upstream.cc b/src/shrpx_https_upstream.cc index 80b6981f..8a5d2423 100644 --- a/src/shrpx_https_upstream.cc +++ b/src/shrpx_https_upstream.cc @@ -765,7 +765,8 @@ int HttpsUpstream::on_downstream_header_complete(Downstream *downstream) hdrs += http2::get_status_string(downstream->get_response_http_status()); hdrs += "\r\n"; downstream->normalize_response_headers(); - if(!get_config()->http2_proxy && !get_config()->client_proxy) { + if(!get_config()->http2_proxy && !get_config()->client_proxy && + !get_config()->no_location_rewrite) { downstream->rewrite_norm_location_response_header (get_client_handler()->get_upstream_scheme(), get_config()->port); } diff --git a/src/shrpx_spdy_upstream.cc b/src/shrpx_spdy_upstream.cc index 5b8cbfa4..690a79c6 100644 --- a/src/shrpx_spdy_upstream.cc +++ b/src/shrpx_spdy_upstream.cc @@ -911,7 +911,8 @@ int SpdyUpstream::on_downstream_header_complete(Downstream *downstream) DLOG(INFO, downstream) << "HTTP response header completed"; } downstream->normalize_response_headers(); - if(!get_config()->http2_proxy && !get_config()->client_proxy) { + if(!get_config()->http2_proxy && !get_config()->client_proxy && + !get_config()->no_location_rewrite) { downstream->rewrite_norm_location_response_header (get_client_handler()->get_upstream_scheme(), get_config()->port); }