changeset 1568:4cc012205ac5

Tests: added js tests for raw headers API.
author Dmitry Volyntsev <xeioex@nginx.com>
date Wed, 06 May 2020 12:52:17 +0000
parents 726877fc4b08
children cd6abbe0f989
files js_headers.t
diffstat 1 files changed, 33 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/js_headers.t
+++ b/js_headers.t
@@ -100,10 +100,18 @@ http {
             js_content hdr_in;
         }
 
+        location /raw_hdr_in {
+            js_content raw_hdr_in;
+        }
+
         location /hdr_out {
             js_content hdr_out;
         }
 
+        location /raw_hdr_out {
+            js_content raw_hdr_out;
+        }
+
         location /hdr_out_array {
             js_content hdr_out_array;
         }
@@ -216,6 +224,12 @@ EOF
         r.return(200, s);
     }
 
+    function raw_hdr_in(r) {
+        var filtered = r.rawHeadersIn
+                       .filter(v=>v[0].toLowerCase() == r.args.filter);
+        r.return(200, 'raw:' + filtered.map(v=>v[1]).join('|'));
+    }
+
     function hdr_sorted_keys(r) {
         var s = '';
         var hdr = r.args.in ? r.headersIn : r.headersOut;
@@ -256,6 +270,15 @@ EOF
         r.finish();
     }
 
+    function raw_hdr_out(r) {
+        r.headersOut.a = ['foo', 'bar'];
+        r.headersOut.b = 'b';
+
+        var filtered = r.rawHeadersOut
+                       .filter(v=>v[0].toLowerCase() == r.args.filter);
+        r.return(200, 'raw:' + filtered.map(v=>v[1]).join('|'));
+    }
+
     function hdr_out_array(r) {
         if (!r.args.hidden) {
             r.headersOut['Foo'] = [r.args.fOO];
@@ -303,7 +326,7 @@ EOF
 
 EOF
 
-$t->try_run('no njs')->plan(37);
+$t->try_run('no njs')->plan(39);
 
 ###############################################################################
 
@@ -414,6 +437,15 @@ like(http(
 	. 'Host: localhost' . CRLF . CRLF
 ), qr/foo: bar1,bar2/, 'r.headersIn duplicate generic');
 
+like(http(
+	'GET /raw_hdr_in?filter=foo HTTP/1.0' . CRLF
+	. 'foo: bar1' . CRLF
+	. 'Foo: bar2' . CRLF
+	. 'Host: localhost' . CRLF . CRLF
+), qr/raw: bar1|bar2/, 'r.rawHeadersIn');
+
+like(http_get('/raw_hdr_out?filter=a'), qr/raw: foo|bar/, 'r.rawHeadersOut');
+
 }
 
 like(http(