vtest "if-range header"

server s1 {
	rxreq
	txresp -hdr {etag: "foo"} -hdr "last-modified: Wed, 21 Oct 2015 07:28:00 GMT" -bodylen 16

	rxreq
	txresp -bodylen 16
} -start

vinyl v1 -vcl+backend {} -start

client c1 {
	txreq
	rxresp
	expect resp.status == 200
	expect resp.bodylen == 16

	# if-range, but no range
	txreq -hdr {if-range: "foo"}
	rxresp
	expect resp.status == 200
	expect resp.bodylen == 16

	# non-matching etag if-range
	txreq -hdr {if-range: "fooled"} -hdr "range: bytes=5-9"
	rxresp
	expect resp.status == 200
	expect resp.bodylen == 16

	# matching etag if-range
	txreq -hdr {if-range: "foo"} -hdr "range: bytes=5-9"
	rxresp
	expect resp.status == 206
	expect resp.bodylen == 5

	# non-matching date if-range (past)
	txreq -hdr "if-range: Wed, 21 Oct 2015 07:18:00 GMT" -hdr "range: bytes=5-9"
	rxresp
	expect resp.status == 200
	expect resp.bodylen == 16

	# non-matching date if-range (future)
	txreq -hdr "if-range: Wed, 21 Oct 2015 07:38:00 GMT" -hdr "range: bytes=5-9"
	rxresp
	expect resp.status == 200
	expect resp.bodylen == 16

	# matching etag if-range
	txreq -hdr "if-range: Wed, 21 Oct 2015 07:28:00 GMT" -hdr "range: bytes=5-9"
	rxresp
	expect resp.status == 206
	expect resp.bodylen == 5
}-run

vinyl v1 -cliok "ban obj.status != x"

# no etag/LM header
client c1 {
	txreq
	rxresp
	expect resp.status == 200
	expect resp.bodylen == 16

	# non-matching etag if-range
	txreq -hdr {if-range: "fooled"} -hdr "range: bytes=5-9"
	rxresp
	expect resp.status == 200
	expect resp.bodylen == 16

	# matching etag if-range
	txreq -hdr {if-range: "foo"} -hdr "range: bytes=5-9"
	rxresp
	expect resp.status == 200
	expect resp.bodylen == 16

	# non-matching date if-range (past)
	txreq -hdr "if-range: Wed, 21 Oct 2015 07:18:00 GMT" -hdr "range: bytes=5-9"
	rxresp
	expect resp.status == 200
	expect resp.bodylen == 16

	# non-matching date if-range (future)
	txreq -hdr "if-range: Wed, 21 Oct 2015 07:38:00 GMT" -hdr "range: bytes=5-9"
	rxresp
	expect resp.status == 200
	expect resp.bodylen == 16
} -run
