reimplement client_max_body_size handlers
[rainbows.git] / t / t0024-pipelined-sendfile-response.sh
blob9111ce914177167ddd31f8f952b472ea3e9a9136
1 #!/bin/sh
2 . ./test-lib.sh
4 t_plan 6 "pipelined sendfile response for $model"
6 t_begin "setup and startup" && {
7 rtmpfiles err out dd_fifo
8 rainbows_setup $model
9 echo 'require "sendfile"' >> $unicorn_config
10 echo 'def (::IO).copy_stream(*x); abort "NO"; end' >> $unicorn_config
12 # can't load Rack::Lint here since it clobbers body#to_path
13 rainbows -E none -D large-file-response.ru -c $unicorn_config
14 rainbows_wait_start
17 t_begin "read random blob sha1" && {
18 random_blob_sha1=$(rsha1 < random_blob)
21 script='
22 require "digest/sha1"
23 require "kcar"
24 $stdin.binmode
25 expect = ENV["random_blob_sha1"]
26 kcar = Kcar::Response.new($stdin, {})
27 3.times do
28 nr = 0
29 status, headers, body = kcar.rack
30 dig = Digest::SHA1.new
31 body.each { |buf| dig << buf ; nr += buf.size }
32 sha1 = dig.hexdigest
33 sha1 == expect or abort "mismatch: sha1=#{sha1} != expect=#{expect}"
34 body.close
35 end
36 $stdout.syswrite("ok\n")
39 t_begin "staggered pipeline of 3 HTTP requests" && {
40 req='GET /random_blob HTTP/1.1\r\nHost: example.com\r\n'
41 rm -f $ok
43 export random_blob_sha1
44 $RUBY -e "$script" < $fifo >> $ok &
45 printf "$req"'X-Req:0\r\n\r\n'
46 exec 6>&1
48 dd bs=16384 count=1
49 printf "$req" >&6
50 dd bs=16384 count=1
51 printf 'X-Req:1\r\n\r\n' >&6
52 dd bs=16384 count=1
53 printf "$req" >&6
54 dd bs=16384 count=1
55 printf 'X-Req:2\r\n' >&6
56 dd bs=16384 count=1
57 printf 'Connection: close\r\n\r' >&6
58 dd bs=16384 count=1
59 printf '\n' >&6
60 cat
61 ) < $dd_fifo > $fifo &
62 wait
63 echo ok >> $ok
64 ) | socat - TCP:$listen > $dd_fifo
65 test 2 -eq $(grep '^ok$' $ok |wc -l)
68 t_begin "pipeline 3 HTTP requests" && {
69 rm -f $ok
70 req='GET /random_blob HTTP/1.1\r\nHost: example.com\r\n'
71 req="$req"'\r\n'"$req"'\r\n'"$req"
72 req="$req"'Connection: close\r\n\r\n'
74 export random_blob_sha1
75 $RUBY -e "$script" < $fifo >> $ok &
76 printf "$req"
77 wait
78 echo ok >> $ok
79 ) | socat - TCP:$listen > $fifo
80 test 2 -eq $(grep '^ok$' $ok |wc -l)
83 t_begin "shutdown server" && {
84 kill -QUIT $rainbows_pid
87 t_begin "check stderr" && check_stderr
89 t_done