annotate js.t @ 993:3ee5ca1ec728

Tests: updated js.t to the new http js module syntax.
author Sergey Kandaurov <pluknet@nginx.com>
date Mon, 25 Jul 2016 16:20:37 +0300
parents 882267679006
children 345a655ef643
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
2
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
3 # (C) Roman Arutyunyan
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
4
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
5 # Tests for http JavaScript module.
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
6
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
7 ###############################################################################
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
8
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
9 use warnings;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
10 use strict;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
11
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
12 use Test::More;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
13
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
15
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
16 use lib 'lib';
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
17 use Test::Nginx;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
18
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
19 ###############################################################################
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
20
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
21 select STDERR; $| = 1;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
22 select STDOUT; $| = 1;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
23
864
460a9cadbd2f Tests: do not check for njs presence, just try js.t configuration.
Sergey Kandaurov <pluknet@nginx.com>
parents: 709
diff changeset
24 my $t = Test::Nginx->new()->has(qw/http rewrite/)
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
25 ->write_file_expand('nginx.conf', <<'EOF');
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
26
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
27 %%TEST_GLOBALS%%
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
28
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
29 daemon off;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
30
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
31 events {
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
32 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
33
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
34 http {
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
35 %%TEST_GLOBALS_HTTP%%
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
36
993
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
37 js_set $test_method test_method;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
38 js_set $test_version test_version;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
39 js_set $test_addr test_addr;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
40 js_set $test_uri test_uri;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
41 js_set $test_hdr test_hdr;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
42 js_set $test_ihdr test_ihdr;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
43 js_set $test_arg test_arg;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
44 js_set $test_iarg test_iarg;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
45
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
46 js_include test.js;
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
47
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
48 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
49 listen 127.0.0.1:8080;
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
50 server_name localhost;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
51
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
52 location /req_method {
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
53 return 200 $test_method;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
54 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
55
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
56 location /req_version {
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
57 return 200 $test_version;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
58 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
59
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
60 location /req_addr {
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
61 return 200 $test_addr;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
62 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
63
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
64 location /req_uri {
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
65 return 200 $test_uri;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
66 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
67
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
68 location /req_hdr {
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
69 return 200 $test_hdr;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
70 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
71
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
72 location /req_ihdr {
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
73 return 200 $test_ihdr;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
74 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
75
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
76 location /req_arg {
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
77 return 200 $test_arg;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
78 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
79
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
80 location /req_iarg {
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
81 return 200 $test_iarg;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
82 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
83
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
84 location /res_status {
993
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
85 js_content status;
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
86 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
87
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
88 location /res_ctype {
993
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
89 js_content ctype;
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
90 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
91
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
92 location /res_clen {
993
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
93 js_content clen;
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
94 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
95
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
96 location /res_send {
993
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
97 js_content send;
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
98 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
99
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
100 location /res_hdr {
993
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
101 js_content hdr;
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
102 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
103 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
104 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
105
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
106 EOF
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
107
993
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
108 $t->write_file('test.js', <<EOF);
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
109 function test_method(req, res) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
110 return 'method=' + req.method;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
111 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
112
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
113 function test_version(req, res) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
114 return 'version=' + req.httpVersion;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
115 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
116
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
117 function test_addr(req, res) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
118 return 'addr=' + req.remoteAddress;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
119 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
120
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
121 function test_uri(req, res) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
122 return 'uri=' + req.uri;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
123 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
124
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
125 function test_hdr(req, res) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
126 return 'hdr=' + req.headers.foo;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
127 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
128
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
129 function test_ihdr(req, res) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
130 var s;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
131 s = '';
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
132 for (h in req.headers) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
133 if (h.substr(0, 3) == 'foo') {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
134 s += req.headers[h];
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
135 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
136 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
137 return s;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
138 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
139
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
140 function test_arg(req, res) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
141 return 'arg=' + req.args.foo;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
142 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
143
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
144 function test_iarg(req, res) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
145 var s;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
146 s = '';
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
147 for (a in req.args) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
148 if (a.substr(0, 3) == 'foo') {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
149 s += req.args[a];
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
150 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
151 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
152 return s;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
153 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
154
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
155 function status(req, res) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
156 res.status = 204;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
157 res.sendHeader();
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
158 res.finish();
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
159 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
160
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
161 function ctype(req, res) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
162 res.status = 200;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
163 res.contentType = 'application/foo';
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
164 res.sendHeader();
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
165 res.finish();
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
166 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
167
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
168 function clen(req, res) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
169 res.status = 200;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
170 res.contentLength = 5;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
171 res.sendHeader();
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
172 res.send('foo12');
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
173 res.finish();
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
174 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
175
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
176 function send(req, res) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
177 var a, s;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
178 res.status = 200;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
179 res.sendHeader();
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
180 for (a in req.args) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
181 if (a.substr(0, 3) == 'foo') {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
182 s = req.args[a];
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
183 res.send('n=' + a + ', v=' + s.substr(0, 2) + ' ');
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
184 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
185 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
186 res.finish();
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
187 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
188
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
189 function hdr(req, res) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
190 res.status = 200;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
191 res.headers['Foo'] = req.args.fOO;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
192 res.sendHeader();
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
193 res.finish();
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
194 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
195 EOF
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
196
864
460a9cadbd2f Tests: do not check for njs presence, just try js.t configuration.
Sergey Kandaurov <pluknet@nginx.com>
parents: 709
diff changeset
197 $t->try_run('no njs available')->plan(13);
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
198
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
199 ###############################################################################
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
200
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
201 like(http_get('/req_method'), qr/method=GET/, 'r.method');
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
202 like(http_get('/req_version'), qr/version=1.0/, 'r.httpVersion');
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
203 like(http_get('/req_addr'), qr/addr=127.0.0.1/, 'r.remoteAddress');
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
204 like(http_get('/req_uri'), qr/uri=\/req_uri/, 'r.uri');
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
205 like(http_get_hdr('/req_hdr'), qr/hdr=12345/, 'r.headers');
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
206 like(http_get_ihdr('/req_ihdr'), qr/12345barz/, 'r.headers iteration');
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
207 like(http_get('/req_arg?foO=12345'), qr/arg=12345/, 'r.args');
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
208 like(http_get('/req_iarg?foo=12345&foo2=bar&nn=22&foo-3=z'), qr/12345barz/,
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
209 'r.args iteration');
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
210
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
211 like(http_get('/res_status'), qr/204 No Content/, 'r.response.status');
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
212 like(http_get('/res_ctype'), qr/Content-Type: application\/foo/,
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
213 'r.response.contentType');
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
214 like(http_get('/res_clen'), qr/Content-Length: 5/, 'r.response.contentLength');
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
215 like(http_get('/res_send?foo=12345&n=11&foo-2=bar&ndd=&foo-3=z'),
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
216 qr/n=foo, v=12 n=foo-2, v=ba n=foo-3, v=z/, 'r.response.send');
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
217 like(http_get('/res_hdr?foo=12345'), qr/Foo: 12345/, 'r.response.headers');
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
218
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
219 ###############################################################################
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
220
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
221 sub http_get_hdr {
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
222 my ($url, %extra) = @_;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
223 return http(<<EOF, %extra);
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
224 GET $url HTTP/1.0
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
225 FoO: 12345
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
226
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
227 EOF
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
228 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
229
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
230 sub http_get_ihdr {
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
231 my ($url, %extra) = @_;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
232 return http(<<EOF, %extra);
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
233 GET $url HTTP/1.0
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
234 foo: 12345
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
235 Host: localhost
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
236 foo2: bar
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
237 X-xxx: more
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
238 foo-3: z
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
239
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
240 EOF
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
241 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
242
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
243 ###############################################################################