Added explicit test for keepalive and non-keepalive HTTP/1.0 response

This commit is contained in:
Aliaksandr Valialkin
2016-01-17 00:30:13 +02:00
parent e3369ec00b
commit 224aecb81d
+30 -9
View File
@@ -10,13 +10,34 @@ import (
"testing"
)
func TestRequestSetByteRange(t *testing.T) {
testRequestSetByteRange(t, 0, 10, "bytes=0-10")
testRequestSetByteRange(t, 123, -1, "bytes=123-")
testRequestSetByteRange(t, -234, 58349, "bytes=-234")
func TestResponseHeaderOldVersion(t *testing.T) {
var h ResponseHeader
s := "HTTP/1.0 200 OK\r\nContent-Length: 5\r\nContent-Type: aaa\r\n\r\n12345"
s += "HTTP/1.0 200 OK\r\nContent-Length: 2\r\nContent-Type: ass\r\nConnection: keep-alive\r\n\r\n42"
br := bufio.NewReader(bytes.NewBufferString(s))
if err := h.Read(br); err != nil {
t.Fatalf("unexpected error: %s", err)
}
if !h.ConnectionClose() {
t.Fatalf("expecting 'Connection: close' for the response with old http protocol")
}
if err := h.Read(br); err != nil {
t.Fatalf("unexpected error: %s", err)
}
if h.ConnectionClose() {
t.Fatalf("unexpected 'Connection: close' for keep-alive response with old http protocol")
}
}
func testRequestSetByteRange(t *testing.T, startPos, endPos int, expectedV string) {
func TestRequestHeaderSetByteRange(t *testing.T) {
testRequestHeaderSetByteRange(t, 0, 10, "bytes=0-10")
testRequestHeaderSetByteRange(t, 123, -1, "bytes=123-")
testRequestHeaderSetByteRange(t, -234, 58349, "bytes=-234")
}
func testRequestHeaderSetByteRange(t *testing.T, startPos, endPos int, expectedV string) {
var h RequestHeader
h.SetByteRange(startPos, endPos)
v := h.Peek("Range")
@@ -25,12 +46,12 @@ func testRequestSetByteRange(t *testing.T, startPos, endPos int, expectedV strin
}
}
func TestResponseSetContentRange(t *testing.T) {
testResponseSetContentRange(t, 0, 0, 1, "bytes 0-0/1")
testResponseSetContentRange(t, 123, 456, 789, "bytes 123-456/789")
func TestResponseHeaderSetContentRange(t *testing.T) {
testResponseHeaderSetContentRange(t, 0, 0, 1, "bytes 0-0/1")
testResponseHeaderSetContentRange(t, 123, 456, 789, "bytes 123-456/789")
}
func testResponseSetContentRange(t *testing.T, startPos, endPos, contentLength int, expectedV string) {
func testResponseHeaderSetContentRange(t *testing.T, startPos, endPos, contentLength int, expectedV string) {
var h ResponseHeader
h.SetContentRange(startPos, endPos, contentLength)
v := h.Peek("Content-Range")