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.
This commit is contained in:
Tatsuhiro Tsujikawa 2014-08-10 12:39:27 +09:00
parent d499803221
commit 24cfb52b5a
6 changed files with 27 additions and 3 deletions

View File

@ -569,6 +569,7 @@ void fill_default_config()
mod_config()->tls_proto_mask = 0; mod_config()->tls_proto_mask = 0;
mod_config()->cached_time = generate_time(); mod_config()->cached_time = generate_time();
mod_config()->no_location_rewrite = false;
} }
} // namespace } // namespace
@ -873,6 +874,12 @@ Misc:
downstream request. downstream request.
--no-via Don't append to Via header field. If Via header --no-via Don't append to Via header field. If Via header
field is received, it is left unaltered. 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=<PROTOID,PORT[,HOST,[ORIGIN]]> --altsvc=<PROTOID,PORT[,HOST,[ORIGIN]]>
Specify protocol ID, port, host and origin of Specify protocol ID, port, host and origin of
alternative service. <HOST> and <ORIGIN> are alternative service. <HOST> and <ORIGIN> are
@ -995,6 +1002,7 @@ int main(int argc, char **argv)
{"errorlog-syslog", no_argument, &flag, 59}, {"errorlog-syslog", no_argument, &flag, 59},
{"stream-read-timeout", required_argument, &flag, 60}, {"stream-read-timeout", required_argument, &flag, 60},
{"stream-write-timeout", required_argument, &flag, 61}, {"stream-write-timeout", required_argument, &flag, 61},
{"no-location-rewrite", no_argument, &flag, 62},
{nullptr, 0, nullptr, 0 } {nullptr, 0, nullptr, 0 }
}; };
@ -1263,6 +1271,10 @@ int main(int argc, char **argv)
// --stream-write-timeout // --stream-write-timeout
cmdcfgs.emplace_back(SHRPX_OPT_STREAM_WRITE_TIMEOUT, optarg); cmdcfgs.emplace_back(SHRPX_OPT_STREAM_WRITE_TIMEOUT, optarg);
break; break;
case 62:
// --no-location-rewrite
cmdcfgs.emplace_back(SHRPX_OPT_NO_LOCATION_REWRITE, "yes");
break;
default: default:
break; break;
} }

View File

@ -124,6 +124,7 @@ const char SHRPX_OPT_ALTSVC[] = "altsvc";
const char SHRPX_OPT_ADD_RESPONSE_HEADER[] = "add-response-header"; const char SHRPX_OPT_ADD_RESPONSE_HEADER[] = "add-response-header";
const char SHRPX_OPT_WORKER_FRONTEND_CONNECTIONS[] = const char SHRPX_OPT_WORKER_FRONTEND_CONNECTIONS[] =
"worker-frontend-connections"; "worker-frontend-connections";
const char SHRPX_OPT_NO_LOCATION_REWRITE[] = "no-location-rewrite";
namespace { namespace {
Config *config = nullptr; Config *config = nullptr;
@ -840,6 +841,12 @@ int parse_config(const char *opt, const char *optarg)
return 0; 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")) { if(util::strieq(opt, "conf")) {
LOG(WARNING) << "conf is ignored"; LOG(WARNING) << "conf is ignored";

View File

@ -114,6 +114,7 @@ extern const char SHRPX_OPT_PADDING[];
extern const char SHRPX_OPT_ALTSVC[]; extern const char SHRPX_OPT_ALTSVC[];
extern const char SHRPX_OPT_ADD_RESPONSE_HEADER[]; extern const char SHRPX_OPT_ADD_RESPONSE_HEADER[];
extern const char SHRPX_OPT_WORKER_FRONTEND_CONNECTIONS[]; extern const char SHRPX_OPT_WORKER_FRONTEND_CONNECTIONS[];
extern const char SHRPX_OPT_NO_LOCATION_REWRITE[];
union sockaddr_union { union sockaddr_union {
sockaddr sa; sockaddr sa;
@ -259,6 +260,7 @@ struct Config {
bool backend_ipv6; bool backend_ipv6;
bool http2_no_cookie_crumbling; bool http2_no_cookie_crumbling;
bool upstream_frame_debug; bool upstream_frame_debug;
bool no_location_rewrite;
}; };
const Config* get_config(); const Config* get_config();

View File

@ -1174,7 +1174,8 @@ int Http2Upstream::on_downstream_header_complete(Downstream *downstream)
} }
downstream->normalize_response_headers(); 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 downstream->rewrite_norm_location_response_header
(get_client_handler()->get_upstream_scheme(), get_config()->port); (get_client_handler()->get_upstream_scheme(), get_config()->port);
} }

View File

@ -765,7 +765,8 @@ int HttpsUpstream::on_downstream_header_complete(Downstream *downstream)
hdrs += http2::get_status_string(downstream->get_response_http_status()); hdrs += http2::get_status_string(downstream->get_response_http_status());
hdrs += "\r\n"; hdrs += "\r\n";
downstream->normalize_response_headers(); 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 downstream->rewrite_norm_location_response_header
(get_client_handler()->get_upstream_scheme(), get_config()->port); (get_client_handler()->get_upstream_scheme(), get_config()->port);
} }

View File

@ -911,7 +911,8 @@ int SpdyUpstream::on_downstream_header_complete(Downstream *downstream)
DLOG(INFO, downstream) << "HTTP response header completed"; DLOG(INFO, downstream) << "HTTP response header completed";
} }
downstream->normalize_response_headers(); 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 downstream->rewrite_norm_location_response_header
(get_client_handler()->get_upstream_scheme(), get_config()->port); (get_client_handler()->get_upstream_scheme(), get_config()->port);
} }