Rainbows! 0.96.0 - range support
[rainbows.git] / t / t0021-sendfile-wrap-to_path.sh
blob7f3acaa194a0344b1a066d736536589ff544152f
1 #!/bin/sh
2 . ./test-lib.sh
3 test -r random_blob || die "random_blob required, run with 'make $0'"
4 case $RUBY_ENGINE in
5 ruby) ;;
6 *)
7 t_info "skipping $T since it can't load the sendfile gem, yet"
8 exit 0
9 ;;
10 esac
12 t_plan 16 "sendfile wrap body response for $model"
14 t_begin "setup and startup" && {
15 rtmpfiles out err http_fifo sub_ok
16 rainbows_setup $model
17 echo 'require "sendfile"' >> $unicorn_config
18 echo 'def (::IO).copy_stream(*x); abort "NO"; end' >> $unicorn_config
20 # can't load Rack::Lint here since it clobbers body#to_path
21 export fifo
22 rainbows -E none -D file-wrap-to_path.ru -c $unicorn_config
23 rainbows_wait_start
26 t_begin "read random blob sha1" && {
27 random_blob_sha1=$(rsha1 < random_blob)
30 t_begin "start FIFO reader" && {
31 cat $fifo > $out &
34 t_begin "single request matches" && {
35 sha1=$(curl -sSfv 2> $err http://$listen/random_blob | rsha1)
36 test -n "$sha1"
37 test x"$sha1" = x"$random_blob_sha1"
40 t_begin "body.close called" && {
41 wait # for cat $fifo
42 grep CLOSING $out || die "body.close not logged"
45 t_begin "start FIFO reader for abortive HTTP/1.1 request" && {
46 cat $fifo > $out &
49 t_begin "send abortive HTTP/1.1 request" && {
50 rm -f $ok
52 printf 'GET /random_blob HTTP/1.1\r\nHost: example.com\r\n\r\n'
53 dd bs=4096 count=1 < $http_fifo >/dev/null
54 echo ok > $ok
55 ) | socat - TCP:$listen > $http_fifo || :
56 test xok = x$(cat $ok)
59 t_begin "body.close called for aborted HTTP/1.1 request" && {
60 wait # for cat $fifo
61 grep CLOSING $out || die "body.close not logged"
64 t_begin "start FIFO reader for abortive HTTP/1.0 request" && {
65 cat $fifo > $out &
68 t_begin "send abortive HTTP/1.0 request" && {
69 rm -f $ok
71 printf 'GET /random_blob HTTP/1.0\r\n\r\n'
72 dd bs=4096 count=1 < $http_fifo >/dev/null
73 echo ok > $ok
74 ) | socat - TCP:$listen > $http_fifo || :
75 test xok = x$(cat $ok)
78 t_begin "body.close called for aborted HTTP/1.0 request" && {
79 wait # for cat $fifo
80 grep CLOSING $out || die "body.close not logged"
83 t_begin "start FIFO reader for abortive HTTP/0.9 request" && {
84 cat $fifo > $out &
87 t_begin "send abortive HTTP/0.9 request" && {
88 rm -f $ok
90 printf 'GET /random_blob\r\n'
91 dd bs=4096 count=1 < $http_fifo >/dev/null
92 echo ok > $ok
93 ) | socat - TCP:$listen > $http_fifo || :
94 test xok = x$(cat $ok)
97 t_begin "body.close called for aborted HTTP/0.9 request" && {
98 wait # for cat $fifo
99 grep CLOSING $out || die "body.close not logged"
102 t_begin "shutdown server" && {
103 kill -QUIT $rainbows_pid
106 t_begin "check stderr" && check_stderr
108 t_done