Mercurial > hg > nginx-tests
comparison h2_request_body_js.t @ 1592:efd082b4aa9c
Tests: HTTP/2 tests for posted requests after reading body.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 18 Sep 2020 20:26:30 +0100 |
parents | |
children | 5ac6efbe5552 |
comparison
equal
deleted
inserted
replaced
1591:a7902e5adeab | 1592:efd082b4aa9c |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for HTTP/2 request body with njs subrequest in the body handler. | |
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 use Test::Nginx::HTTP2; | |
20 | |
21 ############################################################################### | |
22 | |
23 select STDERR; $| = 1; | |
24 select STDOUT; $| = 1; | |
25 | |
26 my $t = Test::Nginx->new()->has(qw/http http_v2/) | |
27 ->write_file_expand('nginx.conf', <<'EOF'); | |
28 | |
29 %%TEST_GLOBALS%% | |
30 | |
31 daemon off; | |
32 | |
33 events { | |
34 } | |
35 | |
36 http { | |
37 %%TEST_GLOBALS_HTTP%% | |
38 | |
39 js_include test.js; | |
40 | |
41 server { | |
42 listen 127.0.0.1:8080 http2; | |
43 server_name localhost; | |
44 | |
45 lingering_close off; | |
46 | |
47 location / { | |
48 js_content sr_body; | |
49 add_header X-Body $request_body; | |
50 } | |
51 | |
52 location /sr { } | |
53 } | |
54 } | |
55 | |
56 EOF | |
57 | |
58 $t->write_file('test.js', <<EOF); | |
59 function body_fwd_cb(r) { | |
60 r.parent.return(r.status, r.responseBody); | |
61 } | |
62 | |
63 function sr_body(r) { | |
64 r.subrequest('/sr', body_fwd_cb); | |
65 } | |
66 | |
67 EOF | |
68 | |
69 $t->write_file('sr', 'SEE-THIS'); | |
70 $t->try_run('no njs available')->plan(3); | |
71 | |
72 ############################################################################### | |
73 | |
74 local $TODO = 'not yet' unless $t->has_version('1.19.3'); | |
75 $t->todo_alerts() unless $t->has_version('1.19.3'); | |
76 | |
77 my $s = Test::Nginx::HTTP2->new(); | |
78 my $sid = $s->new_stream({ body => 'TEST' }); | |
79 my $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | |
80 | |
81 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
82 is($frame->{headers}->{':status'}, 200, 'status'); | |
83 is($frame->{headers}->{'x-body'}, 'TEST', 'request body'); | |
84 | |
85 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
86 is($frame->{data}, 'SEE-THIS', 'response body'); | |
87 | |
88 $t->stop(); | |
89 | |
90 ############################################################################### |