Skip to content

Commit db70f43

Browse files
authored
Merge pull request #1475 from tkan145/THREESCALE-8410-proxy-buffers
[THREESCALE-8410] Add support to set proxy buffer size
2 parents 34a4b0a + 5b984c6 commit db70f43

File tree

4 files changed

+100
-0
lines changed

4 files changed

+100
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2727

2828
- Token Introspection Policy - Support `private_key_jwt` and `client_secret_jwt` authentication mode [PR #1464](https://github.com/3scale/APIcast/pull/1464) [THREESCALE-11015](https://issues.redhat.com/browse/THREESCALE-11015)
2929

30+
- Added the `APICAST_PROXY_BUFFER_SIZE` variable to allow configuration of the buffer size for handling response from the proxied servers. [PR #1473](https://github.com/3scale/APIcast/pull/1473), [THREESCALE-8410](https://issues.redhat.com/browse/THREESCALE-8410)
31+
3032
## [3.15.0] 2024-04-04
3133

3234
### Fixed

doc/parameters.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,13 @@ directive](https://nginx.org/en/docs/http/ngx_http_core_module.html#large_client
524524

525525
Sets the maximum size of shared memory used by batcher policy. The accepted [size units](https://github.com/openresty/lua-nginx-module?tab=readme-ov-file#lua_shared_dict) are k and m.
526526

527+
### `APICAST_PROXY_BUFFER_SIZE`
528+
529+
**Default:** 4k|8k;
530+
**Value:** string
531+
532+
Sets the size of the buffer used for handling the response received from the proxied server. This variable sets both [`proxy_buffer` NGINX directive](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffers) and [`proxy_buffer_size` NGINX directive](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffer_size). By default, the buffer size is equal to one memory page. This is either 4 KiB or 8 KiB, depending on a platform.
533+
527534
### `OPENTELEMETRY`
528535

529536
This environment variable enables NGINX instrumentation using OpenTelemetry tracing library.

gateway/apicast.d/buffers.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{%- assign proxy_buffer_size = env.APICAST_PROXY_BUFFER_SIZE %}
2+
{% if proxy_buffer_size -%}
3+
proxy_buffers 8 {{ proxy_buffer_size }};
4+
proxy_buffer_size {{ proxy_buffer_size }};
5+
{%- endif %}

t/proxy-buffers.t

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
use lib 't';
2+
use Test::APIcast::Blackbox 'no_plan';
3+
4+
run_tests();
5+
6+
__DATA__
7+
8+
=== TEST 1: reject with 502 when upstream return large header (the header exceed the size
9+
of proxy_buffer_size)
10+
--- configuration env
11+
{
12+
"services": [
13+
{
14+
"id": 42,
15+
"backend_version": 1,
16+
"backend_authentication_type": "service_token",
17+
"backend_authentication_value": "token-value",
18+
"proxy": {
19+
"api_backend": "http://test:$TEST_NGINX_SERVER_PORT/",
20+
"proxy_rules": [
21+
{ "pattern": "/", "http_method": "GET", "metric_system_name": "hits", "delta": 2 }
22+
]
23+
}
24+
}
25+
]
26+
}
27+
--- backend
28+
location /transactions/authrep.xml {
29+
content_by_lua_block {
30+
ngx.exit(ngx.OK)
31+
}
32+
}
33+
--- upstream
34+
location / {
35+
content_by_lua_block {
36+
ngx.header["X-Large-Header"] = string.rep("a", 2^12)
37+
}
38+
}
39+
--- request
40+
GET /?user_key=value
41+
--- error_code: 502
42+
--- error_log eval
43+
qr/upstream sent too big header while reading response header from upstream/
44+
45+
46+
=== TEST 2: large utream header with APICAST_PROXY_BUFFER_SIZE set to 8k
47+
--- env eval
48+
(
49+
'APICAST_PROXY_BUFFER_SIZE' => '8k',
50+
)
51+
--- configuration env
52+
{
53+
"services": [
54+
{
55+
"id": 42,
56+
"backend_version": 1,
57+
"backend_authentication_type": "service_token",
58+
"backend_authentication_value": "token-value",
59+
"proxy": {
60+
"api_backend": "http://test:$TEST_NGINX_SERVER_PORT/",
61+
"proxy_rules": [
62+
{ "pattern": "/", "http_method": "GET", "metric_system_name": "hits", "delta": 2 }
63+
]
64+
}
65+
}
66+
]
67+
}
68+
--- backend
69+
location /transactions/authrep.xml {
70+
content_by_lua_block {
71+
ngx.exit(ngx.OK)
72+
}
73+
}
74+
--- upstream
75+
location / {
76+
content_by_lua_block {
77+
ngx.header["X-Large-Header"] = string.rep("a", 2^12)
78+
}
79+
}
80+
--- request
81+
GET /?user_key=value
82+
--- response_headers eval
83+
"X-Large-Header: " . ("a" x 4096) . "\r\n\r\n"
84+
--- error_code: 200
85+
--- no_error_log
86+
[error]

0 commit comments

Comments
 (0)