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