vtest "Don't test gunzip for partial responses"

# The use of ETags is only here to ensure they aren't accidentally weakened.

server s1 {
	# pass'ed range request
	rxreq
	expect req.url == "/pass"
	expect req.http.Accept-Encoding == gzip
	expect req.http.Range == bytes=0-1
	txresp -status 206 -nolen \
		-hdr {ETag: "abc123"} \
		-hdr "Accept-Ranges: bytes" \
		-hdr "Content-Encoding: gzip" \
		-hdr "Content-Length: 2" \
		-hdr "Content-Range: bytes 0-1/*"
	sendhex 1f8b

	# unattended partial response
	rxreq
	expect req.url == "/miss"
	expect req.http.Accept-Encoding == gzip
	expect req.http.Range == <undef>
	txresp -status 206 -nolen \
		-hdr {ETag: "123abc"} \
		-hdr "Accept-Ranges: bytes" \
		-hdr "Content-Encoding: gzip" \
		-hdr "Content-Length: 2" \
		-hdr "Content-Range: bytes 0-1/*"
	sendhex 1f8b
} -start

vinyl v1 -cliok "param.set http_range_support off"

vinyl v1 -vcl+backend {
	sub vcl_recv {
		if (req.url == "/pass") {
			return (pass);
		}
	}
} -start

client c1 {
	txreq -url "/pass" -hdr "Accept-Encoding: gzip" -hdr "Range: bytes=0-1"
	rxresp
	expect resp.status == 206
	expect resp.http.Etag == {"abc123"}
	expect resp.http.Accept-Ranges == bytes
	expect resp.http.Content-Range ~ "^bytes 0-1/"
	expect resp.http.Content-Length == 2
	expect resp.bodylen == 2
} -run

vinyl v1 -expect n_gzip == 0
vinyl v1 -expect n_gunzip == 0
vinyl v1 -expect n_test_gunzip == 0
vinyl v1 -expect SM?.s0.c_req == 0
vinyl v1 -expect SM?.Transient.c_req == 2

# Invalid partial response, also in Transient
client c1 {
	txreq -url "/miss" -hdr "Accept-Encoding: gzip" -hdr "Range: bytes=0-1"
	rxresp
	expect resp.status == 206
	expect resp.http.Etag == {"123abc"}
	expect resp.http.Accept-Ranges == bytes
	expect resp.http.Content-Range ~ "^bytes 0-1/"
	expect resp.http.Content-Length == 2
	expect resp.bodylen == 2
} -run

vinyl v1 -expect n_gzip == 0
vinyl v1 -expect n_gunzip == 0
vinyl v1 -expect n_test_gunzip == 0
vinyl v1 -expect SM?.s0.c_req == 0
vinyl v1 -expect SM?.Transient.c_req == 4
