1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
| | #!/bin/sh
. ./test-lib.sh
echo "simple HTTP connection keepalive/pipelining tests for $model"
tbase=$(expr "$T" : '^\(t....\)-').ru
test -f "$tbase" || die "$tbase missing for $T"
eval $(unused_listen)
rtmpfiles unicorn_config pid r_err r_out tmp fifo ok
cat > $unicorn_config <<EOF
listen "$listen"
pid "$pid"
stderr_path "$r_err"
stdout_path "$r_out"
EOF
if test x$model != xany
then
echo "Rainbows! { use :$model }" >> $unicorn_config
fi
rainbows -D $tbase -c $unicorn_config
wait_for_pid $pid
echo "single request"
curl -sSfv http://$listen/
dbgcat r_err
echo "two requests with keepalive"
curl -sSfv http://$listen/a http://$listen/b > $tmp 2>&1
dbgcat r_err
dbgcat tmp
grep 'Re-using existing connection' < $tmp
echo "pipelining partial requests"
req='GET / HTTP/1.1\r\nHost: example.com\r\n'
(
printf "$req"'\r\n'"$req"
cat $fifo > $tmp &
sleep 1
printf 'Connection: close\r\n\r\n'
wait
echo ok > $ok
) | socat - TCP:$listen > $fifo
dbgcat tmp
test 2 -eq $(grep '^HTTP/1.1' $tmp | wc -l)
test 2 -eq $(grep '^HTTP/1.1 200 OK' $tmp | wc -l)
test 1 -eq $(grep '^Connection: keep-alive' $tmp | wc -l)
test 1 -eq $(grep '^Connection: close' $tmp | wc -l)
test x"$(cat $ok)" = xok
check_stderr
echo "burst pipelining"
req='GET / HTTP/1.1\r\nHost: example.com\r\n'
(
printf "$req"'\r\n'"$req"'Connection: close\r\n\r\n'
cat $fifo > $tmp &
wait
echo ok > $ok
) | socat - TCP:$listen > $fifo
dbgcat tmp
dbgcat r_err
test 2 -eq $(grep '^HTTP/1.1' $tmp | wc -l)
test 2 -eq $(grep '^HTTP/1.1 200 OK' $tmp | wc -l)
test 1 -eq $(grep '^Connection: keep-alive' $tmp | wc -l)
test 1 -eq $(grep '^Connection: close' $tmp | wc -l)
test x"$(cat $ok)" = xok
check_stderr
echo "HTTP/0.9 request should not return headers"
(
printf 'GET /\r\n\r\n'
cat $fifo > $tmp &
wait
echo ok > $ok
) | socat - TCP:$listen > $fifo
dbgcat tmp
dbgcat r_err
echo "env.inspect should've put everything on one line"
test 1 -eq $(wc -l < $tmp)
! grep ^Connection: $tmp
! grep ^HTTP/ $tmp
kill $(cat $pid)
|