1 t_begin
"byte-range setup vars" && {
2 random_blob_size
=$
(wc -c < random_blob
)
3 rb_1
=$
(( $random_blob_size - 1 ))
8 range_n2
=-r0-$
(($rb_1 - 1))
10 range_1b_tail
=-r$rb_1-$rb_1
11 range_1b_mid
=-r200-200
12 range_all
=-r0-$random_blob_size
13 url
=http
://$listen/random_blob
16 check_content_range
() {
17 grep '^< HTTP/1\.1 206 Partial Content' $err
19 # Content-Range: bytes #{offset}-#{offset+count-1}/#{clen}
22 eval $
(< $err sed -n -e \
23 "s/^< Content-Range: bytes $d-$d\/$d"'.*$/start=\1 end=\2 size=\3/p')
28 # ensure we didn't screw up the sed invocation
29 expect
="< Content-Range: bytes $start-$end/$size"
30 test x
"$(grep -F "$expect" $err)" = x
"$(grep '^< Content-Range:' $err)"
36 t_begin
"read random blob sha1s" && {
37 sha1_head
=$
(curl
-sSff $range_head file://random_blob | rsha1
)
38 sha1_tail
=$
(curl
-sSff $range_tail file://random_blob | rsha1
)
39 sha1_mid
=$
(curl
-sSff $range_mid file://random_blob | rsha1
)
40 sha1_n1
=$
(curl
-sSff $range_n1 file://random_blob | rsha1
)
41 sha1_n2
=$
(curl
-sSff $range_n2 file://random_blob | rsha1
)
42 sha1_1b_head
=$
(curl
-sSff $range_1b_head file://random_blob | rsha1
)
43 sha1_1b_tail
=$
(curl
-sSff $range_1b_tail file://random_blob | rsha1
)
44 sha1_1b_mid
=$
(curl
-sSff $range_1b_mid file://random_blob | rsha1
)
45 sha1_all
=$
(rsha1
< random_blob
)
46 echo "$sha1_all=$sha1_n1"
49 t_begin
"normal full request matches" && {
50 sha1
="$(curl -v 2>$err -sSf $url | rsha1)"
51 test x
"$sha1_all" = x
"$sha1"
52 grep 'Content-Range:' $err && die
"Content-Range unexpected"
53 grep 'HTTP/1.1 200 OK' $err || die
"200 response expected"
56 t_begin
"crazy offset goes over" && {
57 range_insane
=-r$
(($random_blob_size * 2))-$
(($random_blob_size * 4))
58 curl
-vsS 2>$err $range_insane $url
59 grep '^< HTTP/1\.[01] 416 ' $err || die
"expected 416 error"
60 grep '^< Content-Range: bytes \*/'$random_blob_size $err || \
61 die
"expected Content-Range: bytes */SIZE"
64 t_begin
"keepalive/pipelining is supported on 416 responses" && {
68 printf 'GET /byte-range-common.sh HTTP/1.1\r\n'
69 printf 'Host: %s\r\n' $listen
70 printf 'Range: bytes=9999999999-9999999999\r\n\r\n'
71 printf 'GET /byte-range-common.sh HTTP/1.1\r\n'
72 printf 'Host: %s\r\n' $listen
73 printf 'Connection: close\r\n'
74 printf 'Range: bytes=0-0\r\n\r\n'
76 ) | socat
- TCP
:$listen > $fifo
79 /^HTTP\/1\.1 / && NR == 1 && $2 == 416 { first = $2 }
80 /^HTTP\/1\.1 / && NR != 1 && $2 == 206 { second = $2 }
81 END { exit((first == 416 && second == 206) ? 0 : 1) }
85 t_begin
"full request matches with explicit ranges" && {
86 sha1
="$(curl -v 2>$err $range_all -sSf $url | rsha1)"
88 test x
"$sha1_all" = x
"$sha1"
90 sha1
="$(curl -v 2>$err $range_n1 -sSf $url | rsha1)"
92 test x
"$sha1_all" = x
"$sha1"
94 range_over
=-r0-$
(($random_blob_size * 2))
95 sha1
="$(curl -v 2>$err $range_over -sSf $url | rsha1)"
97 test x
"$sha1_all" = x
"$sha1"
100 t_begin
"no fence post errors" && {
101 sha1
="$(curl -v 2>$err $range_n2 -sSf $url | rsha1)"
103 test x
"$sha1_n2" = x
"$sha1"
105 sha1
="$(curl -v 2>$err $range_1b_head -sSf $url | rsha1)"
107 test x
"$sha1_1b_head" = x
"$sha1"
109 sha1
="$(curl -v 2>$err $range_1b_tail -sSf $url | rsha1)"
111 test x
"$sha1_1b_tail" = x
"$sha1"
113 sha1
="$(curl -v 2>$err $range_1b_mid -sSf $url | rsha1)"
115 test x
"$sha1_1b_mid" = x
"$sha1"
118 t_begin
"head range matches" && {
119 sha1
="$(curl -sSfv 2>$err $range_head $url | rsha1)"
121 test x
"$sha1_head" = x
"$sha1"
124 t_begin
"tail range matches" && {
125 sha1
="$(curl -sSfv 2>$err $range_tail $url | rsha1)"
127 test x
"$sha1_tail" = x
"$sha1"
130 t_begin
"mid range matches" && {
131 sha1
="$(curl -sSfv 2>$err $range_mid $url | rsha1)"
133 test x
"$sha1_mid" = x
"$sha1"
136 t_begin
"shutdown server" && {
137 kill -QUIT $rainbows_pid
140 t_begin
"check stderr" && check_stderr