nghttpx: Add --no-server-rewrite option not to rewrite server header field

This commit is contained in:
Tatsuhiro Tsujikawa 2016-08-31 23:47:15 +09:00
parent a60c3f8939
commit 136aae725f
7 changed files with 25 additions and 3 deletions

View File

@ -135,6 +135,7 @@ OPTIONS = [
"api-max-request-body",
"backend-max-backoff",
"server-name",
"no-server-rewrite",
]
LOGVARS = [

View File

@ -2208,6 +2208,10 @@ HTTP:
--server-name=<NAME>
Change server response header field value to <NAME>.
Default: )" << get_config()->http.server_name << R"(
--no-server-rewrite
Don't rewrite server header field in default mode. When
--http2-proxy is used, these headers will not be altered
regardless of this option.
API:
--api-max-request-body=<SIZE>
@ -2837,6 +2841,7 @@ int main(int argc, char **argv) {
{SHRPX_OPT_API_MAX_REQUEST_BODY.c_str(), required_argument, &flag, 126},
{SHRPX_OPT_BACKEND_MAX_BACKOFF.c_str(), required_argument, &flag, 127},
{SHRPX_OPT_SERVER_NAME.c_str(), required_argument, &flag, 128},
{SHRPX_OPT_NO_SERVER_REWRITE.c_str(), no_argument, &flag, 129},
{nullptr, 0, nullptr, 0}};
int option_index = 0;
@ -3438,6 +3443,11 @@ int main(int argc, char **argv) {
// --server-name
cmdcfgs.emplace_back(SHRPX_OPT_SERVER_NAME, StringRef{optarg});
break;
case 129:
// --no-server-rewrite
cmdcfgs.emplace_back(SHRPX_OPT_NO_SERVER_REWRITE,
StringRef::from_lit("yes"));
break;
default:
break;
}

View File

@ -1288,6 +1288,9 @@ int option_lookup_token(const char *name, size_t namelen) {
case 17:
switch (name[16]) {
case 'e':
if (util::strieq_l("no-server-rewrit", name, 16)) {
return SHRPX_OPTID_NO_SERVER_REWRITE;
}
if (util::strieq_l("worker-write-rat", name, 16)) {
return SHRPX_OPTID_WORKER_WRITE_RATE;
}
@ -2682,6 +2685,10 @@ int parse_config(Config *config, int optid, const StringRef &opt,
config->http.server_name =
ImmutableString{std::begin(optarg), std::end(optarg)};
return 0;
case SHRPX_OPTID_NO_SERVER_REWRITE:
config->http.no_server_rewrite = util::strieq_l("yes", optarg);
return 0;
case SHRPX_OPTID_CONF:
LOG(WARN) << "conf: ignored";

View File

@ -285,6 +285,8 @@ constexpr auto SHRPX_OPT_API_MAX_REQUEST_BODY =
constexpr auto SHRPX_OPT_BACKEND_MAX_BACKOFF =
StringRef::from_lit("backend-max-backoff");
constexpr auto SHRPX_OPT_SERVER_NAME = StringRef::from_lit("server-name");
constexpr auto SHRPX_OPT_NO_SERVER_REWRITE =
StringRef::from_lit("no-server-rewrite");
constexpr size_t SHRPX_OBFUSCATED_NODE_LENGTH = 8;
@ -561,6 +563,7 @@ struct HttpConfig {
bool no_via;
bool no_location_rewrite;
bool no_host_rewrite;
bool no_server_rewrite;
};
struct Http2Config {
@ -832,6 +835,7 @@ enum {
SHRPX_OPTID_NO_LOCATION_REWRITE,
SHRPX_OPTID_NO_OCSP,
SHRPX_OPTID_NO_SERVER_PUSH,
SHRPX_OPTID_NO_SERVER_REWRITE,
SHRPX_OPTID_NO_VIA,
SHRPX_OPTID_NPN_LIST,
SHRPX_OPTID_OCSP_UPDATE_INTERVAL,

View File

@ -1537,7 +1537,7 @@ int Http2Upstream::on_downstream_header_complete(Downstream *downstream) {
http2::copy_headers_to_nva_nocopy(nva, resp.fs.headers());
if (!get_config()->http2_proxy) {
if (!get_config()->http2_proxy && !httpconf.no_server_rewrite) {
nva.push_back(
http2::make_nv_ls_nocopy("server", StringRef{httpconf.server_name}));
} else {

View File

@ -1078,7 +1078,7 @@ int HttpsUpstream::on_downstream_header_complete(Downstream *downstream) {
}
}
if (!get_config()->http2_proxy) {
if (!get_config()->http2_proxy && !httpconf.no_server_rewrite) {
buf->append("Server: ");
buf->append(httpconf.server_name);
buf->append("\r\n");

View File

@ -1100,7 +1100,7 @@ int SpdyUpstream::on_downstream_header_complete(Downstream *downstream) {
nv[hdidx++] = hd.value.c_str();
}
if (!get_config()->http2_proxy) {
if (!get_config()->http2_proxy && !httpconf.no_server_rewrite) {
nv[hdidx++] = "server";
nv[hdidx++] = httpconf.server_name.c_str();
} else {