Skip to content

Commit

Permalink
Disable proxy (request) buffering for /files location (#439)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrei Krasnitski <[email protected]>

Co-authored-by: Andrei Krasnitski <[email protected]>
  • Loading branch information
2 people authored and svanderburg committed Jun 10, 2021
1 parent 8e10a1b commit 6238759
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 8 additions & 2 deletions buildpack/nginx.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ class Location:
def __init__(self):
self.path = None
self.index = None
self.proxy_intercept_errors = "off"
self.proxy_buffering_enabled = True
self.proxy_intercept_errors_enabled = False
self.satisfy = "any"
self.ipfilter_ips = None
self.basic_auth_enabled = False
Expand All @@ -239,6 +240,8 @@ def get_access_restriction_locations():
# Default for satisfy is any

restrictions = json.loads(os.environ.get("ACCESS_RESTRICTIONS", "{}"))
if "/file" not in restrictions:
restrictions["/file"] = {}
if "/" not in restrictions:
restrictions["/"] = {}

Expand All @@ -254,6 +257,9 @@ def get_access_restriction_locations():
raise Exception(
"Can not override access restrictions on system path %s" % path
)
if path in ["/file"]:
location.proxy_buffering_enabled = False
location.proxy_intercept_errors_enabled = True
if path in [
"/",
"/p/",
Expand All @@ -264,7 +270,7 @@ def get_access_restriction_locations():
"/ws-doc/",
"/rest-doc",
]:
location.proxy_intercept_errors = "on"
location.proxy_intercept_errors_enabled = True

if "satisfy" in config:
if config["satisfy"] in ["any", "all"]:
Expand Down
8 changes: 7 additions & 1 deletion etc/nginx/conf/nginx.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ http {
error_page 503 @503-custom;

{% macro location_body(location) -%}
proxy_intercept_errors {{ location.proxy_intercept_errors }};
{% if not location.proxy_buffering_enabled %}
proxy_buffering off;
proxy_request_buffering off;
{% endif %}
{% if location.proxy_intercept_errors_enabled %}
proxy_intercept_errors on;
{% endif %}
satisfy {{ location.satisfy }};
{% if location.ipfilter_ips is not none %}
{% for ip in location.ipfilter_ips %}
Expand Down

0 comments on commit 6238759

Please sign in to comment.