4646 }
4747
4848 location /append {
49+ js_header_filter test.clear_content_length;
4950 js_body_filter test.append;
5051 proxy_pass http://127.0.0.1:8081/source;
5152 }
@@ -67,11 +68,13 @@ http {
6768
6869 location /filter {
6970 proxy_buffering off;
71+ js_header_filter test.clear_content_length;
7072 js_body_filter test.filter;
7173 proxy_pass http://127.0.0.1:8081/source;
7274 }
7375
7476 location /prepend {
77+ js_header_filter test.clear_content_length;
7578 js_body_filter test.prepend;
7679 proxy_pass http://127.0.0.1:8081/source;
7780 }
@@ -108,6 +111,10 @@ $t->write_file('test.js', <<EOF);
108111 }
109112 }
110113
114+ function clear_content_length(r) {
115+ delete r.headersOut['Content-Length'];
116+ }
117+
111118 var collect = Buffer.from([]);
112119 function buffer_type(r, data, flags) {
113120 collect = Buffer.concat([collect, data]);
@@ -134,6 +141,7 @@ $t->write_file('test.js', <<EOF);
134141 chunks.chain = chain;
135142
136143 r.status = 200;
144+ r.headersOut['Content-Length'] = chunks.reduce((a, b) => a + b.length, 0);
137145 r.sendHeader();
138146 chain(chunks, 0);
139147 }
@@ -170,15 +178,16 @@ $t->write_file('test.js', <<EOF);
170178 }
171179
172180 export default {njs: test_njs, append, buffer_type, filter, forward,
173- prepend, source, nonutf8_source};
181+ prepend, source, nonutf8_source, clear_content_length };
174182
175183EOF
176184
177- $t -> try_run(' no njs body filter' )-> plan(7 );
185+ $t -> try_run(' no njs body filter' )-> plan(8 );
178186
179187# ##############################################################################
180188
181189like(http_get(' /append' ), qr / AAABBCDDDDXXX$ / , ' append' );
190+ unlike(http_get(' /append' ), qr / Content-Length/ , ' append no content-length' );
182191like(http_get(' /buffer_type' ), qr / AAABBCDDDD$ / , ' buffer type' );
183192like(http_get(' /buffer_type_nonutf8' ), qr /\xaa\xaa\xbb\xcc\xdd\xdd $ / ,
184193 ' buffer type nonutf8' );
0 commit comments