File tree Expand file tree Collapse file tree 1 file changed +93
-0
lines changed Expand file tree Collapse file tree 1 file changed +93
-0
lines changed Original file line number Diff line number Diff line change
1
+ # !/usr/bin/perl
2
+
3
+ # (C) Dmitry Volyntsev
4
+ # (C) Nginx, Inc.
5
+
6
+ # Tests for http njs module, header filter.
7
+
8
+ # ##############################################################################
9
+
10
+ use warnings;
11
+ use strict;
12
+
13
+ use Test::More;
14
+
15
+ BEGIN { use FindBin; chdir ($FindBin::Bin ); }
16
+
17
+ use lib ' lib' ;
18
+ use Test::Nginx;
19
+
20
+ # ##############################################################################
21
+
22
+ select STDERR ; $| = 1;
23
+ select STDOUT ; $| = 1;
24
+
25
+ my $t = Test::Nginx-> new()-> has(qw/ http proxy rewrite/ )
26
+ -> write_file_expand(' nginx.conf' , <<'EOF' );
27
+
28
+ %%TEST_GLOBALS%%
29
+
30
+ daemon off;
31
+
32
+ events {
33
+ }
34
+
35
+ http {
36
+ %%TEST_GLOBALS_HTTP%%
37
+
38
+ js_import test.js;
39
+
40
+ server {
41
+ listen 127.0.0.1:8080;
42
+ server_name localhost;
43
+
44
+ location /njs {
45
+ js_content test.njs;
46
+ }
47
+
48
+ location /filter/ {
49
+ js_header_filter test.filter;
50
+ proxy_pass http://127.0.0.1:8081/;
51
+ }
52
+ }
53
+
54
+ server {
55
+ listen 127.0.0.1:8081;
56
+ server_name localhost;
57
+
58
+ location / {
59
+ add_header Set-Cookie "BB";
60
+ add_header Set-Cookie "CCCC";
61
+
62
+ return 200;
63
+ }
64
+ }
65
+ }
66
+
67
+ EOF
68
+
69
+ $t -> write_file(' test.js' , <<EOF );
70
+ function test_njs(r) {
71
+ r.return(200, njs.version);
72
+ }
73
+
74
+ function filter(r) {
75
+ var cookies = r.headersOut['Set-Cookie'];
76
+ var len = r.args.len ? Number(r.args.len) : 0;
77
+ r.headersOut['Set-Cookie'] = cookies.filter(v=>v.length > len);
78
+ }
79
+
80
+ export default {njs: test_njs, filter};
81
+
82
+ EOF
83
+
84
+ $t -> try_run(' no njs header filter' )-> plan(2);
85
+
86
+ # ##############################################################################
87
+
88
+ like(http_get(' /filter/?len=1' ), qr / Set-Cookie: BB.*Set-Cookie: CCCC.*/ ms ,
89
+ ' all' );;
90
+ unlike(http_get(' /filter/?len=3' ), qr / Set-Cookie: BB/ ,
91
+ ' filter' );
92
+
93
+ # ##############################################################################
You can’t perform that action at this time.
0 commit comments