[PATCH] Add ability to remove Connection header completely
Tim Birkett
tim.birkett at devopsmakers.com
Wed Feb 1 18:56:57 UTC 2017
# HG changeset patch
# User Tim Birkett <tim.birkett at devopsmakers.com>
# Date 1485972846 -28800
# Thu Feb 02 02:14:06 2017 +0800
# Node ID 25129d5509b83f9c45a92c7508ebc1cd65592118
# Parent d2b2ff157da53260b2b1c414792100ff0cd1377d
Add ability to remove Connection header completely
In some cases it's desirable to strip response sizes down as much as possible.
Consider an API that serves a huge number of small responses.
You'd probably use ngx_headers_more to strip all headers except the "Connection: Close"
header that's about 17 bytes can;t currently be stripped.
If you're returning say, a phone number or IP address then that header accounts for
about a 3rd of the traffic you serve.
This patch allows you to remove the header completely by setting "keepalive_timeout 0 0;"
it seemed to be the most straight forward and sane approach without adding another
config directive.
I realise that this would cause responses to not adhere strictly to HTTP/1.1 but I also feel
it's a valuable edgecase for those in the ad-serving, tel. number replacement and other
high volume "small data" API products out there where every byte counts (and costs).
Any feedback appreciated.
diff -r d2b2ff157da5 -r 25129d5509b8 src/http/ngx_http_header_filter_module.c
--- a/src/http/ngx_http_header_filter_module.c Tue Jan 31 21:19:58 2017 +0300
+++ b/src/http/ngx_http_header_filter_module.c Thu Feb 02 02:14:06 2017 +0800
@@ -389,7 +389,9 @@
}
} else {
- len += sizeof("Connection: close" CRLF) - 1;
+ if (clcf->keepalive_header != 0) {
+ len += sizeof("Connection: close" CRLF) - 1;
+ }
}
#if (NGX_HTTP_GZIP)
@@ -560,8 +562,10 @@
}
} else {
- b->last = ngx_cpymem(b->last, "Connection: close" CRLF,
- sizeof("Connection: close" CRLF) - 1);
+ if (clcf->keepalive_header != 0){
+ b->last = ngx_cpymem(b->last, "Connection: close" CRLF,
+ sizeof("Connection: close" CRLF) - 1);
+ }
}
#if (NGX_HTTP_GZIP)
More information about the nginx-devel
mailing list