diff --git a/src/shrpx.cc b/src/shrpx.cc index 959c15bf..f6847bd3 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -1109,8 +1109,8 @@ void fill_default_config() { // For API endpoint, we enable automatic window update. This is // because we are a sink. - nghttp2_option_new(&upstreamconf.api_option); - nghttp2_option_set_no_recv_client_magic(upstreamconf.api_option, 1); + nghttp2_option_new(&upstreamconf.alt_mode_option); + nghttp2_option_set_no_recv_client_magic(upstreamconf.alt_mode_option, 1); } { diff --git a/src/shrpx_client_handler.cc b/src/shrpx_client_handler.cc index d1e4c25d..9ba99b9b 100644 --- a/src/shrpx_client_handler.cc +++ b/src/shrpx_client_handler.cc @@ -896,7 +896,8 @@ ClientHandler::get_downstream_connection(Downstream *downstream) { const auto &req = downstream->request(); - if (faddr_->api) { + switch (faddr_->alt_mode) { + case ALTMODE_API: return make_unique(worker_); } diff --git a/src/shrpx_config.cc b/src/shrpx_config.cc index 6a9e5271..21f81232 100644 --- a/src/shrpx_config.cc +++ b/src/shrpx_config.cc @@ -610,8 +610,8 @@ int parse_memcached_connection_params(MemcachedConnectionParams &out, } // namespace struct UpstreamParams { + int alt_mode; bool tls; - bool api; }; namespace { @@ -629,7 +629,7 @@ int parse_upstream_params(UpstreamParams &out, const StringRef &src_params) { } else if (util::strieq_l("no-tls", param)) { out.tls = false; } else if (util::strieq_l("api", param)) { - out.api = true; + out.alt_mode = ALTMODE_API; } else if (!param.empty()) { LOG(ERROR) << "frontend: " << param << ": unknown keyword"; return -1; @@ -1736,9 +1736,9 @@ int parse_config(Config *config, int optid, const StringRef &opt, UpstreamAddr addr{}; addr.fd = -1; addr.tls = params.tls; - addr.api = params.api; + addr.alt_mode = params.alt_mode; - if (addr.api) { + if (addr.alt_mode == ALTMODE_API) { listenerconf.api = true; } diff --git a/src/shrpx_config.h b/src/shrpx_config.h index aa9522ac..347aa0b1 100644 --- a/src/shrpx_config.h +++ b/src/shrpx_config.h @@ -316,6 +316,13 @@ struct AltSvc { uint16_t port; }; +enum UpstreamAltMode { + // No alternative mode + ALTMODE_NONE, + // API processing mode + ALTMODE_API, +}; + struct UpstreamAddr { // The frontend address (e.g., FQDN, hostname, IP address). If // |host_unix| is true, this is UNIX domain socket path. @@ -329,12 +336,12 @@ struct UpstreamAddr { // For TCP socket, this is either AF_INET or AF_INET6. For UNIX // domain socket, this is 0. int family; + // Alternate mode + int alt_mode; // true if |host| contains UNIX domain socket path. bool host_unix; // true if TLS is enabled. bool tls; - // true if this is an API endpoint. - bool api; int fd; }; @@ -554,7 +561,7 @@ struct Http2Config { ev_tstamp settings; } timeout; nghttp2_option *option; - nghttp2_option *api_option; + nghttp2_option *alt_mode_option; nghttp2_session_callbacks *callbacks; size_t window_bits; size_t connection_window_bits; diff --git a/src/shrpx_connection_handler.cc b/src/shrpx_connection_handler.cc index bc76ad47..87f03221 100644 --- a/src/shrpx_connection_handler.cc +++ b/src/shrpx_connection_handler.cc @@ -393,7 +393,7 @@ int ConnectionHandler::handle_connection(int fd, sockaddr *addr, int addrlen, Worker *worker; - if (faddr->api) { + if (faddr->alt_mode == ALTMODE_API) { worker = workers_[0].get(); if (LOG_ENABLED(INFO)) { diff --git a/src/shrpx_downstream.cc b/src/shrpx_downstream.cc index 60ac686d..8afd7fc4 100644 --- a/src/shrpx_downstream.cc +++ b/src/shrpx_downstream.cc @@ -505,7 +505,7 @@ bool Downstream::request_buf_full() { auto worker = handler->get_worker(); // We don't check buffer size here for API endpoint. - if (faddr->api) { + if (faddr->alt_mode == ALTMODE_API) { return false; } diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index 28647631..518335bb 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -879,7 +879,8 @@ Http2Upstream::Http2Upstream(ClientHandler *handler) rv = nghttp2_session_server_new2( &session_, http2conf.upstream.callbacks, this, - faddr->api ? http2conf.upstream.api_option : http2conf.upstream.option); + faddr->alt_mode ? http2conf.upstream.alt_mode_option + : http2conf.upstream.option); assert(rv == 0); @@ -891,7 +892,7 @@ Http2Upstream::Http2Upstream(ClientHandler *handler) entry[0].value = http2conf.upstream.max_concurrent_streams; entry[1].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE; - if (faddr->api) { + if (faddr->alt_mode) { entry[1].value = (1u << 31) - 1; } else { entry[1].value = (1 << http2conf.upstream.window_bits) - 1; @@ -905,7 +906,7 @@ Http2Upstream::Http2Upstream(ClientHandler *handler) } int32_t window_bits = - faddr->api ? 31 : http2conf.upstream.connection_window_bits; + faddr->alt_mode ? 31 : http2conf.upstream.connection_window_bits; if (window_bits != 16) { int32_t window_size = (1u << window_bits) - 1; @@ -1701,7 +1702,7 @@ int Http2Upstream::consume(int32_t stream_id, size_t len) { auto faddr = handler_->get_upstream_addr(); - if (faddr->api) { + if (faddr->alt_mode) { return 0; } diff --git a/src/shrpx_https_upstream.cc b/src/shrpx_https_upstream.cc index 24c80c7d..1f5e4640 100644 --- a/src/shrpx_https_upstream.cc +++ b/src/shrpx_https_upstream.cc @@ -413,11 +413,11 @@ int htp_hdrs_completecb(http_parser *htp) { auto faddr = handler->get_upstream_addr(); - if (faddr->api) { + if (faddr->alt_mode) { // Normally, we forward expect: 100-continue to backend server, // and let them decide whether responds with 100 Continue or not. - // For API endpoint, we have no backend, so just send 100 Continue - // here to make the client happy. + // For alternative mode, we have no backend, so just send 100 + // Continue here to make the client happy. auto expect = req.fs.header(http2::HD_EXPECT); if (expect && util::strieq(expect->value, StringRef::from_lit("100-continue"))) { diff --git a/src/shrpx_spdy_upstream.cc b/src/shrpx_spdy_upstream.cc index df78b9c0..0d09fccc 100644 --- a/src/shrpx_spdy_upstream.cc +++ b/src/shrpx_spdy_upstream.cc @@ -565,7 +565,7 @@ SpdyUpstream::SpdyUpstream(uint16_t version, ClientHandler *handler) // going to be deprecated in the future, and the default stream // window is large enough for API request body (64KiB), we don't // expand window size depending on the options. - if (version >= SPDYLAY_PROTO_SPDY3 && !faddr->api) { + if (version >= SPDYLAY_PROTO_SPDY3 && !faddr->alt_mode) { int val = 1; flow_control_ = true; initial_window_size_ = 1 << http2conf.upstream.window_bits;