From d9139fc286a291ebc71b988a3c7a8124085a79c6 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Mon, 22 Aug 2016 22:30:25 +0900 Subject: [PATCH 01/14] asio: Fix reserved size --- src/asio_client_session_impl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/asio_client_session_impl.cc b/src/asio_client_session_impl.cc index fafb26b1..f5a14be9 100644 --- a/src/asio_client_session_impl.cc +++ b/src/asio_client_session_impl.cc @@ -503,7 +503,7 @@ const request *session_impl::submit(boost::system::error_code &ec, } auto nva = std::vector(); - nva.reserve(3 + h.size()); + nva.reserve(4 + h.size()); nva.push_back(http2::make_nv_ls(":method", method)); nva.push_back(http2::make_nv_ls(":scheme", uref.scheme)); nva.push_back(http2::make_nv_ls(":path", path)); From 8f47b68a9526f4f2be2f31e73112f49b59359d97 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 23 Aug 2016 21:36:43 +0900 Subject: [PATCH 02/14] nghttpx: Set do_signal_write_ when TLS handshake was completed --- src/shrpx_http_downstream_connection.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/shrpx_http_downstream_connection.cc b/src/shrpx_http_downstream_connection.cc index da1c6fd0..ae398122 100644 --- a/src/shrpx_http_downstream_connection.cc +++ b/src/shrpx_http_downstream_connection.cc @@ -994,6 +994,8 @@ int HttpDownstreamConnection::tls_handshake() { auto &connect_blocker = addr_->connect_blocker; + do_signal_write_ = &HttpDownstreamConnection::actual_signal_write; + connect_blocker->on_success(); ev_set_cb(&conn_.rt, timeoutcb); @@ -1160,8 +1162,6 @@ int HttpDownstreamConnection::connected() { ev_set_cb(&conn_.wev, writecb); - do_signal_write_ = &HttpDownstreamConnection::actual_signal_write; - if (conn_.tls.ssl) { do_read_ = &HttpDownstreamConnection::tls_handshake; do_write_ = &HttpDownstreamConnection::tls_handshake; @@ -1169,6 +1169,8 @@ int HttpDownstreamConnection::connected() { return 0; } + do_signal_write_ = &HttpDownstreamConnection::actual_signal_write; + connect_blocker->on_success(); ev_set_cb(&conn_.rt, timeoutcb); From 00c80a15c09c168d44b4d4560f301f8cdd3f77ee Mon Sep 17 00:00:00 2001 From: Wenfeng Liu Date: Tue, 23 Aug 2016 13:40:14 +0000 Subject: [PATCH 03/14] lib: Make emit_header() return void since it always succeed. --- lib/nghttp2_hd.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/nghttp2_hd.c b/lib/nghttp2_hd.c index f8dba5c0..275c966c 100644 --- a/lib/nghttp2_hd.c +++ b/lib/nghttp2_hd.c @@ -768,14 +768,12 @@ static size_t entry_room(size_t namelen, size_t valuelen) { return NGHTTP2_HD_ENTRY_OVERHEAD + namelen + valuelen; } -static int emit_header(nghttp2_hd_nv *nv_out, nghttp2_hd_nv *nv) { +static void emit_header(nghttp2_hd_nv *nv_out, nghttp2_hd_nv *nv) { DEBUGF(fprintf(stderr, "inflatehd: header emission: %s: %s\n", nv->name->base, nv->value->base)); /* ent->ref may be 0. This happens if the encoder emits literal block larger than header table capacity with indexing. */ *nv_out = *nv; - - return 0; } static size_t count_encoded_length(size_t n, size_t prefix) { From cf7f87c2adb9118ad3409b02b9590f2c58cb22d2 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 25 Aug 2016 00:25:03 +0900 Subject: [PATCH 04/14] nghttpx: Log error code from getsockopt(SO_ERROR) on first write event --- src/shrpx_http2_session.cc | 6 ++++-- src/shrpx_http_downstream_connection.cc | 6 ++++-- src/shrpx_live_check.cc | 6 ++++-- src/shrpx_memcached_connection.cc | 11 ++++++----- src/util.cc | 10 ++++++++++ src/util.h | 5 +++++ 6 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/shrpx_http2_session.cc b/src/shrpx_http2_session.cc index 74dd18c5..624289bb 100644 --- a/src/shrpx_http2_session.cc +++ b/src/shrpx_http2_session.cc @@ -1806,9 +1806,11 @@ int Http2Session::read_noop(const uint8_t *data, size_t datalen) { return 0; } int Http2Session::write_noop() { return 0; } int Http2Session::connected() { - if (!util::check_socket_connected(conn_.fd)) { + auto sock_error = util::get_socket_error(conn_.fd); + if (sock_error != 0) { SSLOG(WARN, this) << "Backend connect failed; addr=" - << util::to_numeric_addr(&addr_->addr); + << util::to_numeric_addr(&addr_->addr) + << ": errno=" << sock_error; downstream_failure(addr_); diff --git a/src/shrpx_http_downstream_connection.cc b/src/shrpx_http_downstream_connection.cc index ae398122..feb548f3 100644 --- a/src/shrpx_http_downstream_connection.cc +++ b/src/shrpx_http_downstream_connection.cc @@ -1143,11 +1143,13 @@ int HttpDownstreamConnection::process_input(const uint8_t *data, int HttpDownstreamConnection::connected() { auto &connect_blocker = addr_->connect_blocker; - if (!util::check_socket_connected(conn_.fd)) { + auto sock_error = util::get_socket_error(conn_.fd); + if (sock_error != 0) { conn_.wlimit.stopw(); DCLOG(WARN, this) << "Backend connect failed; addr=" - << util::to_numeric_addr(&addr_->addr); + << util::to_numeric_addr(&addr_->addr) + << ": errno=" << sock_error; downstream_failure(addr_); diff --git a/src/shrpx_live_check.cc b/src/shrpx_live_check.cc index 7f6559c8..05f48447 100644 --- a/src/shrpx_live_check.cc +++ b/src/shrpx_live_check.cc @@ -259,10 +259,12 @@ int LiveCheck::initiate_connection() { } int LiveCheck::connected() { - if (!util::check_socket_connected(conn_.fd)) { + auto sock_error = util::get_socket_error(conn_.fd); + if (sock_error != 0) { if (LOG_ENABLED(INFO)) { LOG(INFO) << "Backend connect failed; addr=" - << util::to_numeric_addr(&addr_->addr); + << util::to_numeric_addr(&addr_->addr) + << ": errno=" << sock_error; } return -1; diff --git a/src/shrpx_memcached_connection.cc b/src/shrpx_memcached_connection.cc index d28b5fab..77e55747 100644 --- a/src/shrpx_memcached_connection.cc +++ b/src/shrpx_memcached_connection.cc @@ -203,15 +203,16 @@ int MemcachedConnection::initiate_connection() { } int MemcachedConnection::connected() { - if (!util::check_socket_connected(conn_.fd)) { + auto sock_error = util::get_socket_error(conn_.fd); + if (sock_error != 0) { + MCLOG(WARN, this) << "memcached connect failed; addr=" + << util::to_numeric_addr(addr_) + << ": errno=" << sock_error; + connect_blocker_.on_failure(); conn_.wlimit.stopw(); - if (LOG_ENABLED(INFO)) { - MCLOG(INFO, this) << "memcached connect failed"; - } - return -1; } diff --git a/src/util.cc b/src/util.cc index af7f187d..7a3646d3 100644 --- a/src/util.cc +++ b/src/util.cc @@ -893,6 +893,16 @@ bool check_socket_connected(int fd) { return error == 0; } +int get_socket_error(int fd) { + int error; + socklen_t len = sizeof(error); + if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) != 0) { + return -1; + } + + return error; +} + bool ipv6_numeric_addr(const char *host) { uint8_t dst[16]; return inet_pton(AF_INET6, host, dst) == 1; diff --git a/src/util.h b/src/util.h index 5ae8cfb5..81aa671c 100644 --- a/src/util.h +++ b/src/util.h @@ -574,6 +574,11 @@ int create_nonblock_socket(int family); bool check_socket_connected(int fd); +// Returns the error code (errno) by inspecting SO_ERROR of given +// |fd|. This function returns the error code if it succeeds, or -1. +// Returning 0 means no error. +int get_socket_error(int fd); + // Returns true if |host| is IPv6 numeric address (e.g., ::1) bool ipv6_numeric_addr(const char *host); From 979c99eaea90631e12045a87d07767cfd203aab2 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 25 Aug 2016 22:36:05 +0900 Subject: [PATCH 05/14] Update AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 7a0b243c..a55dba53 100644 --- a/AUTHORS +++ b/AUTHORS @@ -71,6 +71,7 @@ Tomasz Buchert Vernon Tang Viacheslav Biriukov Viktor Szépe +Wenfeng Liu Xiaoguang Sun Zhuoyun Wei acesso From 7d661889108cbc1c1d9d96452c04ceb452b39e8a Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 25 Aug 2016 22:37:18 +0900 Subject: [PATCH 06/14] Add author.py This script prints out the commit author from `git log` output. Used to update AUTHORS file. --- author.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 author.py diff --git a/author.py b/author.py new file mode 100755 index 00000000..760da009 --- /dev/null +++ b/author.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python + +# script to extract commit author's name from standard input. The +# input should be :, one per line. +# This script expects the input is created by git-log command: +# +# git log --format=%aN:%aE +# +# This script removes duplicates based on email address, breaking a +# tie with longer author name. Among the all author names extract the +# previous step, we remove duplicate by case-insensitive match. +# +# So we can do this in one line: +# +# git log --format=%aN:%aE | sort | uniq | ./author.py > authors + +import sys + +edict = {} + +for line in sys.stdin: + author, email = line.strip().split(':', 1) + if email in edict: + an = edict[email] + if len(an) < len(author) or an > author: + sys.stderr.write( + 'eliminated {} in favor of {}\n'.format(an, author)) + edict[email] = author + else: + sys.stderr.write( + 'eliminated {} in favor of {}\n'.format(author, an)) + else: + edict[email] = author + +names = list(sorted(edict.values())) + +ndict = {} + +for name in names: + lowname = name.lower() + if lowname in ndict: + an = ndict[lowname] + if an > name: + sys.stderr.write('eliminated {} in favor of {}\n'.format(an, name)) + ndict[lowname] = name + else: + sys.stderr.write('eliminated {} in favor of {}\n'.format(name, an)) + else: + ndict[lowname] = name + +for name in sorted(ndict.values()): + print name From 25ea41972a0fa8d04e65115fa8e9f68adbe2da48 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 25 Aug 2016 22:41:17 +0900 Subject: [PATCH 07/14] Bump up version number to 1.14.0, LT revision to 24:0:10 --- CMakeLists.txt | 2 +- configure.ac | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c11989e..cc9e47de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ cmake_minimum_required(VERSION 3.0) # XXX using 1.8.90 instead of 1.9.0-DEV -project(nghttp2 VERSION 1.13.90) +project(nghttp2 VERSION 1.14.0) # See versioning rule: # http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html diff --git a/configure.ac b/configure.ac index ab9bd2ed..930ffb61 100644 --- a/configure.ac +++ b/configure.ac @@ -25,7 +25,7 @@ dnl Do not change user variables! dnl http://www.gnu.org/software/automake/manual/html_node/Flag-Variables-Ordering.html AC_PREREQ(2.61) -AC_INIT([nghttp2], [1.14.0-DEV], [t-tujikawa@users.sourceforge.net]) +AC_INIT([nghttp2], [1.14.0], [t-tujikawa@users.sourceforge.net]) AC_CONFIG_AUX_DIR([.]) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_HEADERS([config.h]) @@ -44,9 +44,9 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) dnl See versioning rule: dnl http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html -AC_SUBST(LT_CURRENT, 23) +AC_SUBST(LT_CURRENT, 24) AC_SUBST(LT_REVISION, 0) -AC_SUBST(LT_AGE, 9) +AC_SUBST(LT_AGE, 10) major=`echo $PACKAGE_VERSION |cut -d. -f1 | sed -e "s/[^0-9]//g"` minor=`echo $PACKAGE_VERSION |cut -d. -f2 | sed -e "s/[^0-9]//g"` From 4749e66c67d66e409238fe6b86953a3d93650593 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 25 Aug 2016 22:55:12 +0900 Subject: [PATCH 08/14] nghttpx: Disallow copying Config --- src/shrpx.cc | 2 -- src/shrpx_config.h | 6 ++++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/shrpx.cc b/src/shrpx.cc index ece98e36..cd36a1cf 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -1272,8 +1272,6 @@ constexpr auto DEFAULT_ACCESSLOG_FORMAT = StringRef::from_lit( namespace { void fill_default_config(Config *config) { - *config = {}; - config->num_worker = 1; config->conf_path = "/etc/nghttpx/nghttpx.conf"; config->pid = getpid(); diff --git a/src/shrpx_config.h b/src/shrpx_config.h index d0645ff3..5ad6585a 100644 --- a/src/shrpx_config.h +++ b/src/shrpx_config.h @@ -706,8 +706,14 @@ struct APIConfig { }; struct Config { + Config() = default; ~Config(); + Config(Config &&) = delete; + Config(const Config &&) = delete; + Config &operator=(Config &&) = delete; + Config &operator=(const Config &&) = delete; + HttpProxy downstream_http_proxy; HttpConfig http; Http2Config http2; From 1c8a672a8d3086ab3ca0664895338e66fdbf3aec Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 25 Aug 2016 22:57:56 +0900 Subject: [PATCH 09/14] Update man pages --- doc/h2load.1 | 2 +- doc/nghttp.1 | 2 +- doc/nghttpd.1 | 2 +- doc/nghttpx.1 | 8 +++++++- doc/nghttpx.1.rst | 4 ++++ 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/doc/h2load.1 b/doc/h2load.1 index dd63c682..634385c9 100644 --- a/doc/h2load.1 +++ b/doc/h2load.1 @@ -1,6 +1,6 @@ .\" Man page generated from reStructuredText. . -.TH "H2LOAD" "1" "Jul 31, 2016" "1.14.0-DEV" "nghttp2" +.TH "H2LOAD" "1" "Aug 25, 2016" "1.14.0" "nghttp2" .SH NAME h2load \- HTTP/2 benchmarking tool . diff --git a/doc/nghttp.1 b/doc/nghttp.1 index 5d3f3eaa..6a711cc6 100644 --- a/doc/nghttp.1 +++ b/doc/nghttp.1 @@ -1,6 +1,6 @@ .\" Man page generated from reStructuredText. . -.TH "NGHTTP" "1" "Jul 31, 2016" "1.14.0-DEV" "nghttp2" +.TH "NGHTTP" "1" "Aug 25, 2016" "1.14.0" "nghttp2" .SH NAME nghttp \- HTTP/2 client . diff --git a/doc/nghttpd.1 b/doc/nghttpd.1 index 43540382..9eb17d73 100644 --- a/doc/nghttpd.1 +++ b/doc/nghttpd.1 @@ -1,6 +1,6 @@ .\" Man page generated from reStructuredText. . -.TH "NGHTTPD" "1" "Jul 31, 2016" "1.14.0-DEV" "nghttp2" +.TH "NGHTTPD" "1" "Aug 25, 2016" "1.14.0" "nghttp2" .SH NAME nghttpd \- HTTP/2 server . diff --git a/doc/nghttpx.1 b/doc/nghttpx.1 index c4548174..a27453ee 100644 --- a/doc/nghttpx.1 +++ b/doc/nghttpx.1 @@ -1,6 +1,6 @@ .\" Man page generated from reStructuredText. . -.TH "NGHTTPX" "1" "Jul 31, 2016" "1.14.0-DEV" "nghttp2" +.TH "NGHTTPX" "1" "Aug 25, 2016" "1.14.0" "nghttp2" .SH NAME nghttpx \- HTTP/2 proxy . @@ -938,6 +938,12 @@ $ssl_session_id: session ID for SSL/TLS connection. .IP \(bu 2 $ssl_session_reused: "r" if SSL/TLS session was reused. Otherwise, "." +.IP \(bu 2 +$backend_host: backend host used to fulfill the +request. "\-" if backend host is not available. +.IP \(bu 2 +$backend_port: backend port used to fulfill the +request. "\-" if backend host is not available. .UNINDENT .sp The variable can be enclosed by "{" and "}" for diff --git a/doc/nghttpx.1.rst b/doc/nghttpx.1.rst index 20236781..a8b292e7 100644 --- a/doc/nghttpx.1.rst +++ b/doc/nghttpx.1.rst @@ -847,6 +847,10 @@ Logging * $ssl_session_id: session ID for SSL/TLS connection. * $ssl_session_reused: "r" if SSL/TLS session was reused. Otherwise, "." + * $backend_host: backend host used to fulfill the + request. "-" if backend host is not available. + * $backend_port: backend port used to fulfill the + request. "-" if backend host is not available. The variable can be enclosed by "{" and "}" for disambiguation (e.g., ${remote_addr}). From 8103f43b650667029e60866cc8e1bfd2a859fa7c Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 25 Aug 2016 23:19:35 +0900 Subject: [PATCH 10/14] doc: Add missing APIDOCS entry --- doc/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/Makefile.am b/doc/Makefile.am index ce9eef5b..9f790892 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -37,6 +37,7 @@ APIDOCS= \ nghttp2_hd_deflate_get_num_table_entries.rst \ nghttp2_hd_deflate_get_table_entry.rst \ nghttp2_hd_deflate_hd.rst \ + nghttp2_hd_deflate_hd_vec.rst \ nghttp2_hd_deflate_new.rst \ nghttp2_hd_deflate_new2.rst \ nghttp2_hd_inflate_change_table_size.rst \ From 833cd962a1d3f45cca054fa29f9fd24171af2166 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 25 Aug 2016 23:25:42 +0900 Subject: [PATCH 11/14] Bump up version number to 1.15.0-DEV --- CMakeLists.txt | 2 +- configure.ac | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cc9e47de..b2f598e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ cmake_minimum_required(VERSION 3.0) # XXX using 1.8.90 instead of 1.9.0-DEV -project(nghttp2 VERSION 1.14.0) +project(nghttp2 VERSION 1.14.90) # See versioning rule: # http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html diff --git a/configure.ac b/configure.ac index 930ffb61..d06f11b0 100644 --- a/configure.ac +++ b/configure.ac @@ -25,7 +25,7 @@ dnl Do not change user variables! dnl http://www.gnu.org/software/automake/manual/html_node/Flag-Variables-Ordering.html AC_PREREQ(2.61) -AC_INIT([nghttp2], [1.14.0], [t-tujikawa@users.sourceforge.net]) +AC_INIT([nghttp2], [1.15.0-DEV], [t-tujikawa@users.sourceforge.net]) AC_CONFIG_AUX_DIR([.]) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_HEADERS([config.h]) From 0d4d1a63d45fb880ada93c78df7aa52779640632 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 26 Aug 2016 22:28:09 +0900 Subject: [PATCH 12/14] nghttpx: Add --server-name option to change server response header field --- gennghttpxfun.py | 1 + src/memchunk.h | 3 +++ src/shrpx.cc | 10 +++++++++- src/shrpx_config.cc | 10 ++++++++++ src/shrpx_config.h | 4 +++- src/shrpx_http.cc | 2 +- src/shrpx_http2_upstream.cc | 10 ++++++---- 7 files changed, 33 insertions(+), 7 deletions(-) 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("