Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only add Content-Type header when respnose body is present #82

Merged
merged 3 commits into from
Jun 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions jobs/secureproxy/templates/config/nginx.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ http {
add_header Strict-Transport-Security $sts always;
add_header X-Content-Type-Options $content_type_options always;
add_header X-XSS-Protection $xss_protection always;
add_header Content-Type $default_content_type always;

# Clear X-Frame-Options before setting so that ALLOWALL is cleared if set
more_clear_headers X-Frame-Options;
Expand All @@ -195,6 +194,14 @@ http {
##

access_by_lua_block {
# Don't add a `Content-Type` header if the response length is 0,
# e.g. 204/304 status codes
if ngx.var.upstream_response_length > 0 then
ngx.req.set_header("Content-Type", ngx.var.default_content_type)
else
ngx.log(ngx.NOTICE, "Content-Type header not added for host ", ngx.var.host, "and request URI ", ngx.var.request_uri , "with a response body length of 0")
end

-- bail fast if we don't have a whitelist
if ip_whitelist_size == 0 then
return
Expand Down Expand Up @@ -279,8 +286,7 @@ server {
add_header Strict-Transport-Security $sts always;
add_header X-Content-Type-Options $content_type_options always;
add_header X-XSS-Protection $xss_protection always;
add_header Content-Type $default_content_type always;


# Clear X-Frame-Options before setting so that ALLOWALL is cleared if set
more_clear_headers X-Frame-Options;
more_set_headers "X-Frame-Options: $frame_options";
Expand All @@ -295,6 +301,14 @@ server {
##

access_by_lua_block {
# Don't add a `Content-Type` header if the response length is 0,
# e.g. 204/304 status codes
if ngx.var.upstream_response_length > 0 then
ngx.req.set_header("Content-Type", ngx.var.default_content_type)
else
ngx.log(ngx.NOTICE, "Content-Type header not added for host ", ngx.var.host, "and request URI ", ngx.var.request_uri , "with a response body length of 0")
end

-- bail fast if we don't have a whitelist
if ip_whitelist_size == 0 then
return
Expand Down