Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
6066a2f3
Commit
6066a2f3
authored
Dec 08, 2014
by
Federico G. Schwindt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve Range handling
Add support for 416 and fix some corner cases.
parent
165b4caf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
45 deletions
+57
-45
cache_range.c
bin/varnishd/cache/cache_range.c
+16
-12
c00034.vtc
bin/varnishtest/tests/c00034.vtc
+41
-33
No files found.
bin/varnishd/cache/cache_range.c
View file @
6066a2f3
...
...
@@ -98,14 +98,12 @@ VRG_dorange(struct req *req, struct busyobj *bo, const char *r)
else
len
=
ObjGetLen
(
req
->
wrk
,
req
->
objcore
);
if
(
strncmp
(
r
,
"bytes="
,
6
))
if
(
strnc
asec
mp
(
r
,
"bytes="
,
6
))
return
;
r
+=
6
;
/* The low end of range */
has_low
=
low
=
0
;
if
(
!
vct_isdigit
(
*
r
)
&&
*
r
!=
'-'
)
return
;
while
(
vct_isdigit
(
*
r
))
{
has_low
=
1
;
low
*=
10
;
...
...
@@ -113,9 +111,6 @@ VRG_dorange(struct req *req, struct busyobj *bo, const char *r)
r
++
;
}
if
(
low
>=
len
)
return
;
if
(
*
r
!=
'-'
)
return
;
r
++
;
...
...
@@ -128,22 +123,31 @@ VRG_dorange(struct req *req, struct busyobj *bo, const char *r)
high
+=
*
r
-
'0'
;
r
++
;
}
if
(
high
<
low
)
return
;
if
(
!
has_low
)
{
low
=
len
-
high
;
if
(
low
<
0
)
low
=
0
;
high
=
len
-
1
;
}
}
else
}
else
if
(
high
>=
len
)
high
=
len
-
1
;
}
else
if
(
has_low
)
high
=
len
-
1
;
if
(
*
r
!=
'\0'
)
else
return
;
if
(
high
>=
len
)
high
=
len
-
1
;
if
(
*
r
!=
'\0'
)
return
;
if
(
low
>
high
)
if
(
low
>=
len
)
{
http_PrintfHeader
(
req
->
resp
,
"Content-Range: bytes */%jd"
,
(
intmax_t
)
len
);
http_Unset
(
req
->
resp
,
H_Content_Length
);
http_PutResponse
(
req
->
resp
,
"HTTP/1.1"
,
416
,
NULL
);
req
->
wantbody
=
0
;
return
;
}
http_PrintfHeader
(
req
->
resp
,
"Content-Range: bytes %jd-%jd/%jd"
,
(
intmax_t
)
low
,
(
intmax_t
)
high
,
(
intmax_t
)
len
);
...
...
bin/varnishtest/tests/c00034.vtc
View file @
6066a2f3
...
...
@@ -5,13 +5,11 @@ server s1 {
txresp -bodylen 100
} -start
varnish v1 -vcl+backend {
varnish v1 -arg "-p http_range_support=off" -vcl+backend {
sub vcl_backend_response {
set beresp.do_stream = false;
}
} -start
varnish v1 -cliok "param.set http_range_support off"
client c1 {
txreq -hdr "Range: bytes=0-9"
...
...
@@ -45,61 +43,71 @@ client c1 {
expect resp.status == 200
expect resp.bodylen == 100
txreq -hdr "Range: bytes=-"
rxresp
expect resp.status == 200
expect resp.bodylen == 100
txreq -hdr "Range: bytes=5-2"
rxresp
expect resp.status == 200
expect resp.bodylen == 100
} -run
varnish v1 -expect s_resp_bodybytes ==
5
00
varnish v1 -expect s_resp_bodybytes ==
7
00
client c1 {
txreq -hdr "Range: bytes=0-9"
txreq -hdr "Range: bytes=-0"
rxresp
expect resp.status == 206
expect resp.bodylen == 10
expect resp.status == 416
expect resp.bodylen == 0
expect resp.http.content-range == "bytes */100"
txreq -hdr "Range: bytes=10
-19
"
txreq -hdr "Range: bytes=10
0-
"
rxresp
expect resp.status == 206
expect resp.bodylen == 10
expect resp.status == 416
expect resp.bodylen == 0
expect resp.http.content-range == "bytes */100"
} -run
txreq -hdr "Range: bytes=90-"
rxresp
expect resp.status == 206
expect resp.bodylen == 10
varnish v1 -expect s_resp_bodybytes == 700
txreq -hdr "Range: bytes=-9"
client c1 {
txreq -hdr "Range: bytes=0-49"
rxresp
expect resp.status == 206
expect resp.bodylen == 9
expect resp.bodylen == 50
expect resp.http.content-range == "bytes 0-49/100"
txreq -hdr "Range: bytes=
-
"
txreq -hdr "Range: bytes=
50-99
"
rxresp
expect resp.status == 206
expect resp.bodylen == 100
txreq -hdr "Range: bytes=102-102"
rxresp
expect resp.status == 200
expect resp.bodylen == 100
expect resp.bodylen == 50
expect resp.http.content-range == "bytes 50-99/100"
txreq -hdr "Range: bytes=
99-
"
txreq -hdr "Range: bytes=
-50
"
rxresp
expect resp.status == 206
expect resp.bodylen == 1
expect resp.bodylen == 50
expect resp.http.content-range == "bytes 50-99/100"
txreq -hdr "Range: bytes=
99-70
"
txreq -hdr "Range: bytes=
50-
"
rxresp
expect resp.status == 200
expect resp.bodylen == 100
expect resp.status == 206
expect resp.bodylen == 50
expect resp.http.content-range == "bytes 50-99/100"
txreq -hdr "Range: bytes=
-
"
txreq -hdr "Range: bytes=
0-0
"
rxresp
expect resp.status == 206
expect resp.bodylen == 100
expect resp.bodylen == 1
expect resp.http.content-range == "bytes 0-0/100"
txreq -hdr "Range: bytes=-
101
"
txreq -hdr "Range: bytes=-
2000
"
rxresp
expect resp.status == 206
expect resp.bodylen == 100
expect resp.http.content-range == "bytes 0-99/100"
} -run
varnish v1 -expect s_resp_bodybytes == 10
40
varnish v1 -expect s_resp_bodybytes == 10
01
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment