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
() {
18 # Content-Range: bytes #{offset}-#{offset+count-1}/#{clen}
21 eval $
(< $err sed -n -e \
22 "s/^< Content-Range: bytes $d-$d\/$d"'.*$/start=\1 end=\2 size=\3/p')
27 # ensure we didn't screw up the sed invocation
28 expect
="< Content-Range: bytes $start-$end/$size"
29 test x
"$(grep -F "$expect" $err)" = x
"$(grep '^< Content-Range:' $err)"
35 t_begin
"read random blob sha1s" && {
36 sha1_head
=$
(curl
-sSff $range_head file://random_blob | rsha1
)
37 sha1_tail
=$
(curl
-sSff $range_tail file://random_blob | rsha1
)
38 sha1_mid
=$
(curl
-sSff $range_mid file://random_blob | rsha1
)
39 sha1_n1
=$
(curl
-sSff $range_n1 file://random_blob | rsha1
)
40 sha1_n2
=$
(curl
-sSff $range_n2 file://random_blob | rsha1
)
41 sha1_1b_head
=$
(curl
-sSff $range_1b_head file://random_blob | rsha1
)
42 sha1_1b_tail
=$
(curl
-sSff $range_1b_tail file://random_blob | rsha1
)
43 sha1_1b_mid
=$
(curl
-sSff $range_1b_mid file://random_blob | rsha1
)
44 sha1_all
=$
(rsha1
< random_blob
)
45 echo "$sha1_all=$sha1_n1"
48 t_begin
"normal full request matches" && {
49 sha1
="$(curl -v 2>$err -sSf $url | rsha1)"
50 test x
"$sha1_all" = x
"$sha1"
51 grep 'Content-Range:' $err && die
"Content-Range unexpected"
52 grep 'HTTP/1.1 200 OK' $err || die
"200 response expected"
55 t_begin
"crazy offset goes over" && {
56 range_insane
=-r$
(($random_blob_size * 2))-$
(($random_blob_size * 4))
57 curl
-vsS 2>$err $range_insane $url
58 grep 'HTTP/1\.[01] 416 ' $err || die
"expected 416 error"
61 t_begin
"full request matches with explicit ranges" && {
62 sha1
="$(curl -v 2>$err $range_all -sSf $url | rsha1)"
64 test x
"$sha1_all" = x
"$sha1"
66 sha1
="$(curl -v 2>$err $range_n1 -sSf $url | rsha1)"
68 test x
"$sha1_all" = x
"$sha1"
70 range_over
=-r0-$
(($random_blob_size * 2))
71 sha1
="$(curl -v 2>$err $range_over -sSf $url | rsha1)"
73 test x
"$sha1_all" = x
"$sha1"
76 t_begin
"no fence post errors" && {
77 sha1
="$(curl -v 2>$err $range_n2 -sSf $url | rsha1)"
79 test x
"$sha1_n2" = x
"$sha1"
81 sha1
="$(curl -v 2>$err $range_1b_head -sSf $url | rsha1)"
83 test x
"$sha1_1b_head" = x
"$sha1"
85 sha1
="$(curl -v 2>$err $range_1b_tail -sSf $url | rsha1)"
87 test x
"$sha1_1b_tail" = x
"$sha1"
89 sha1
="$(curl -v 2>$err $range_1b_mid -sSf $url | rsha1)"
91 test x
"$sha1_1b_mid" = x
"$sha1"
94 t_begin
"head range matches" && {
95 sha1
="$(curl -sSfv 2>$err $range_head $url | rsha1)"
97 test x
"$sha1_head" = x
"$sha1"
100 t_begin
"tail range matches" && {
101 sha1
="$(curl -sSfv 2>$err $range_tail $url | rsha1)"
103 test x
"$sha1_tail" = x
"$sha1"
106 t_begin
"mid range matches" && {
107 sha1
="$(curl -sSfv 2>$err $range_mid $url | rsha1)"
109 test x
"$sha1_mid" = x
"$sha1"
112 t_begin
"shutdown server" && {
113 kill -QUIT $rainbows_pid
116 t_begin
"check stderr" && check_stderr