diff options
author | Dmitry Volyntsev <xeioex@nginx.com> | 2025-04-28 18:34:29 -0700 |
---|---|---|
committer | Dmitry Volyntsev <xeioexception@gmail.com> | 2025-04-29 22:50:04 -0700 |
commit | 7f901b6f87a29ab74d18040c18aebb5b5918b028 (patch) | |
tree | 1fb11a6a7a504ddcaabdf05cdc346ff230a5bcdf /nginx | |
parent | 1496ed3f5820dbaec91fe7fdba2da8ee387bb36b (diff) | |
download | njs-7f901b6f87a29ab74d18040c18aebb5b5918b028.tar.gz njs-7f901b6f87a29ab74d18040c18aebb5b5918b028.zip |
Tests: improved js_body_filter.t tests.
Dropping Content-Length header in locations where response body
length is modified. This is not strictly needed for the test itself,
but can serve as an example for a typical body modification task.
Diffstat (limited to 'nginx')
-rw-r--r-- | nginx/t/js_body_filter.t | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/nginx/t/js_body_filter.t b/nginx/t/js_body_filter.t index d0c74238..5fc8292a 100644 --- a/nginx/t/js_body_filter.t +++ b/nginx/t/js_body_filter.t @@ -46,6 +46,7 @@ http { } location /append { + js_header_filter test.clear_content_length; js_body_filter test.append; proxy_pass http://127.0.0.1:8081/source; } @@ -67,11 +68,13 @@ http { location /filter { proxy_buffering off; + js_header_filter test.clear_content_length; js_body_filter test.filter; proxy_pass http://127.0.0.1:8081/source; } location /prepend { + js_header_filter test.clear_content_length; js_body_filter test.prepend; proxy_pass http://127.0.0.1:8081/source; } @@ -108,6 +111,10 @@ $t->write_file('test.js', <<EOF); } } + function clear_content_length(r) { + delete r.headersOut['Content-Length']; + } + var collect = Buffer.from([]); function buffer_type(r, data, flags) { collect = Buffer.concat([collect, data]); @@ -134,6 +141,7 @@ $t->write_file('test.js', <<EOF); chunks.chain = chain; r.status = 200; + r.headersOut['Content-Length'] = chunks.reduce((a, b) => a + b.length, 0); r.sendHeader(); chain(chunks, 0); } @@ -170,15 +178,16 @@ $t->write_file('test.js', <<EOF); } export default {njs: test_njs, append, buffer_type, filter, forward, - prepend, source, nonutf8_source}; + prepend, source, nonutf8_source, clear_content_length}; EOF -$t->try_run('no njs body filter')->plan(7); +$t->try_run('no njs body filter')->plan(8); ############################################################################### like(http_get('/append'), qr/AAABBCDDDDXXX$/, 'append'); +unlike(http_get('/append'), qr/Content-Length/, 'append no content-length'); like(http_get('/buffer_type'), qr/AAABBCDDDD$/, 'buffer type'); like(http_get('/buffer_type_nonutf8'), qr/\xaa\xaa\xbb\xcc\xdd\xdd$/, 'buffer type nonutf8'); |