diff --git a/gennghttpxfun.py b/gennghttpxfun.py index ca40cabb..f76abcde 100755 --- a/gennghttpxfun.py +++ b/gennghttpxfun.py @@ -134,6 +134,7 @@ OPTIONS = [ "backend-http2-settings-timeout", "api-max-request-body", "backend-max-backoff", + "server-name", ] LOGVARS = [ diff --git a/src/memchunk.h b/src/memchunk.h index 4cfd3b12..d1753ceb 100644 --- a/src/memchunk.h +++ b/src/memchunk.h @@ -178,6 +178,9 @@ template struct Memchunks { } size_t append(const std::string &s) { return append(s.c_str(), s.size()); } size_t append(const StringRef &s) { return append(s.c_str(), s.size()); } + size_t append(const ImmutableString &s) { + return append(s.c_str(), s.size()); + } size_t remove(void *dest, size_t count) { if (!tail || count == 0) { return 0; diff --git a/src/shrpx.cc b/src/shrpx.cc index cd36a1cf..3c7dd888 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -1317,7 +1317,7 @@ void fill_default_config(Config *config) { auto &httpconf = config->http; httpconf.server_name = - StringRef::from_lit("nghttpx nghttp2/" NGHTTP2_VERSION); + ImmutableString::from_lit("nghttpx nghttp2/" NGHTTP2_VERSION); httpconf.no_host_rewrite = true; httpconf.request_header_field_buffer = 64_k; httpconf.max_request_header_fields = 100; @@ -2203,6 +2203,9 @@ HTTP: 599. If "*" is used instead of , it matches all HTTP status code. If error status code comes from backend server, the custom error pages are not used. + --server-name= + Change server response header field value to . + Default: )" << get_config()->http.server_name << R"( API: --api-max-request-body= @@ -2831,6 +2834,7 @@ int main(int argc, char **argv) { &flag, 125}, {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}, {nullptr, 0, nullptr, 0}}; int option_index = 0; @@ -3428,6 +3432,10 @@ int main(int argc, char **argv) { // --backend-max-backoff cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_MAX_BACKOFF, StringRef{optarg}); break; + case 128: + // --server-name + cmdcfgs.emplace_back(SHRPX_OPT_SERVER_NAME, StringRef{optarg}); + break; default: break; } diff --git a/src/shrpx_config.cc b/src/shrpx_config.cc index 2eb208a3..08c9fa8a 100644 --- a/src/shrpx_config.cc +++ b/src/shrpx_config.cc @@ -1127,6 +1127,11 @@ int option_lookup_token(const char *name, size_t namelen) { break; case 11: switch (name[10]) { + case 'e': + if (util::strieq_l("server-nam", name, 10)) { + return SHRPX_OPTID_SERVER_NAME; + } + break; case 's': if (util::strieq_l("backend-tl", name, 10)) { return SHRPX_OPTID_BACKEND_TLS; @@ -2673,6 +2678,11 @@ int parse_config(Config *config, int optid, const StringRef &opt, case SHRPX_OPTID_BACKEND_MAX_BACKOFF: return parse_duration(&config->conn.downstream->timeout.max_backoff, opt, optarg); + case SHRPX_OPTID_SERVER_NAME: + config->http.server_name = + ImmutableString{std::begin(optarg), std::end(optarg)}; + + return 0; case SHRPX_OPTID_CONF: LOG(WARN) << "conf: ignored"; diff --git a/src/shrpx_config.h b/src/shrpx_config.h index 5ad6585a..0a1b86bb 100644 --- a/src/shrpx_config.h +++ b/src/shrpx_config.h @@ -284,6 +284,7 @@ constexpr auto SHRPX_OPT_API_MAX_REQUEST_BODY = StringRef::from_lit("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 size_t SHRPX_OBFUSCATED_NODE_LENGTH = 8; @@ -552,7 +553,7 @@ struct HttpConfig { std::vector error_pages; Headers add_request_headers; Headers add_response_headers; - StringRef server_name; + ImmutableString server_name; size_t request_header_field_buffer; size_t max_request_header_fields; size_t response_header_field_buffer; @@ -843,6 +844,7 @@ enum { SHRPX_OPTID_REQUEST_HEADER_FIELD_BUFFER, SHRPX_OPTID_RESPONSE_HEADER_FIELD_BUFFER, SHRPX_OPTID_RLIMIT_NOFILE, + SHRPX_OPTID_SERVER_NAME, SHRPX_OPTID_STREAM_READ_TIMEOUT, SHRPX_OPTID_STREAM_WRITE_TIMEOUT, SHRPX_OPTID_STRIP_INCOMING_FORWARDED, diff --git a/src/shrpx_http.cc b/src/shrpx_http.cc index c2939c7e..e54040bf 100644 --- a/src/shrpx_http.cc +++ b/src/shrpx_http.cc @@ -51,7 +51,7 @@ StringRef create_error_html(BlockAllocator &balloc, unsigned int http_status) { return concat_string_ref( balloc, StringRef::from_lit(R"()"), status_string, StringRef::from_lit("

"), status_string, - StringRef::from_lit("