diff --git a/src/shrpx.cc b/src/shrpx.cc index 17896474..689c9ad8 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -782,6 +782,7 @@ void fill_default_config() { mod_config()->tls_ctx_per_worker = false; mod_config()->downstream_request_buffer_size = 16 * 1024; mod_config()->downstream_response_buffer_size = 16 * 1024; + mod_config()->no_server_push = false; } } // namespace @@ -1087,6 +1088,10 @@ HTTP/2 and SPDY: padding. Specify 0 to disable padding. This option is meant for debugging purpose and not intended to enhance protocol security. + --no-server-push + Disable HTTP/2 server push. Server push is only + supported by default mode and HTTP/2 frontend. SPDY + frontend does not support server push. Mode: (default mode) @@ -1345,6 +1350,7 @@ int main(int argc, char **argv) { {"backend-response-buffer", required_argument, &flag, 71}, {"backend-request-buffer", required_argument, &flag, 72}, {"no-host-rewrite", no_argument, &flag, 73}, + {"no-server-push", no_argument, &flag, 74}, {nullptr, 0, nullptr, 0}}; int option_index = 0; @@ -1678,6 +1684,10 @@ int main(int argc, char **argv) { // --no-host-rewrite cmdcfgs.emplace_back(SHRPX_OPT_NO_HOST_REWRITE, "yes"); break; + case 74: + // --no-server-push + cmdcfgs.emplace_back(SHRPX_OPT_NO_SERVER_PUSH, "yes"); + break; default: break; } diff --git a/src/shrpx_config.cc b/src/shrpx_config.cc index 3c94440c..96775a03 100644 --- a/src/shrpx_config.cc +++ b/src/shrpx_config.cc @@ -145,6 +145,7 @@ const char SHRPX_OPT_RLIMIT_NOFILE[] = "rlimit-nofile"; const char SHRPX_OPT_TLS_CTX_PER_WORKER[] = "tls-ctx-per-worker"; const char SHRPX_OPT_BACKEND_REQUEST_BUFFER[] = "backend-request-buffer"; const char SHRPX_OPT_BACKEND_RESPONSE_BUFFER[] = "backend-response-buffer"; +const char SHRPX_OPT_NO_SERVER_PUSH[] = "no-server-push"; namespace { Config *config = nullptr; @@ -1165,6 +1166,12 @@ int parse_config(const char *opt, const char *optarg) { return 0; } + if (util::strieq(opt, SHRPX_OPT_NO_SERVER_PUSH)) { + mod_config()->no_server_push = util::strieq(optarg, "yes"); + + return 0; + } + if (util::strieq(opt, "conf")) { LOG(WARN) << "conf: ignored"; diff --git a/src/shrpx_config.h b/src/shrpx_config.h index 86eb22b8..ac920b43 100644 --- a/src/shrpx_config.h +++ b/src/shrpx_config.h @@ -132,6 +132,7 @@ extern const char SHRPX_OPT_RLIMIT_NOFILE[]; extern const char SHRPX_OPT_TLS_CTX_PER_WORKER[]; extern const char SHRPX_OPT_BACKEND_REQUEST_BUFFER[]; extern const char SHRPX_OPT_BACKEND_RESPONSE_BUFFER[]; +extern const char SHRPX_OPT_NO_SERVER_PUSH[]; union sockaddr_union { sockaddr_storage storage; @@ -304,6 +305,7 @@ struct Config { bool no_host_rewrite; bool auto_tls_ticket_key; bool tls_ctx_per_worker; + bool no_server_push; }; const Config *get_config(); diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index 55fedf1a..89e9de81 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -1336,7 +1336,8 @@ int Http2Upstream::on_downstream_header_complete(Downstream *downstream) { // * We requires GET or POST for associated resource. Probably we // don't want to push for HEAD request. Not sure other methods // are also eligible for push. - if (get_config()->downstream_proto == PROTO_HTTP && + if (!get_config()->no_server_push && + get_config()->downstream_proto == PROTO_HTTP && !get_config()->http2_proxy && (downstream->get_stream_id() % 2) && downstream->get_response_header(http2::HD_LINK) && downstream->get_response_http_status() == 200 &&