)
type respTest struct {
- Raw string
- Resp Response
- Body string
+ Raw string
+ RawOut string
+ Resp Response
+ Body string
}
func dummyReq(method string) *Request {
"\r\n" +
"Body here\n",
+ "HTTP/1.0 200 OK\r\n" +
+ "Connection: close\r\n" +
+ "\r\n" +
+ "Body here\n",
+
Response{
Status: "200 OK",
StatusCode: 200,
"\r\n" +
"Body here\n",
+ "HTTP/1.1 200 OK\r\n" +
+ "Connection: close\r\n" +
+ "\r\n" +
+ "Body here\n",
+
Response{
Status: "200 OK",
StatusCode: 200,
"\r\n" +
"Body should not be read!\n",
+ "HTTP/1.1 204 No Content\r\n" +
+ "\r\n",
+
Response{
Status: "204 No Content",
StatusCode: 204,
"\r\n" +
"Body here\n",
+ "HTTP/1.0 200 OK\r\n" +
+ "Content-Length: 10\r\n" +
+ "Connection: close\r\n" +
+ "\r\n" +
+ "Body here\n",
+
Response{
Status: "200 OK",
StatusCode: 200,
"0\r\n" +
"\r\n",
+ "HTTP/1.1 200 OK\r\n" +
+ "Transfer-Encoding: chunked\r\n" +
+ "\r\n" +
+ "13\r\n" +
+ "Body here\ncontinued\r\n" +
+ "0\r\n" +
+ "\r\n",
+
Response{
Status: "200 OK",
StatusCode: 200,
"\r\n" +
"Body here\n",
+ "HTTP/1.0 200 OK\r\n" +
+ "Content-Length: 10\r\n" +
+ "Connection: close\r\n" +
+ "\r\n" +
+ "Body here\n",
+
Response{
Status: "200 OK",
StatusCode: 200,
"0\r\n" +
"\r\n",
+ "HTTP/1.1 200 OK\r\n" +
+ "Transfer-Encoding: chunked\r\n" +
+ "\r\n" +
+ "a\r\n" +
+ "Body here\n\r\n" +
+ "0\r\n" +
+ "\r\n",
+
Response{
Status: "200 OK",
StatusCode: 200,
"Transfer-Encoding: chunked\r\n" +
"\r\n",
+ "HTTP/1.1 200 OK\r\n" +
+ "Transfer-Encoding: chunked\r\n" +
+ "\r\n",
+
Response{
Status: "200 OK",
StatusCode: 200,
"Content-Length: 256\r\n" +
"\r\n",
+ "HTTP/1.0 200 OK\r\n" +
+ "Connection: close\r\n" +
+ "Content-Length: 256\r\n" +
+ "\r\n",
+
Response{
Status: "200 OK",
StatusCode: 200,
"Content-Length: 256\r\n" +
"\r\n",
+ "HTTP/1.1 200 OK\r\n" +
+ "Content-Length: 256\r\n" +
+ "\r\n",
+
Response{
Status: "200 OK",
StatusCode: 200,
"HTTP/1.0 200 OK\r\n" +
"\r\n",
+ "HTTP/1.0 200 OK\r\n" +
+ "Connection: close\r\n" +
+ "\r\n",
+
Response{
Status: "200 OK",
StatusCode: 200,
"Content-Length: 0\r\n" +
"\r\n",
+ "HTTP/1.1 200 OK\r\n" +
+ "Content-Length: 0\r\n" +
+ "\r\n",
+
Response{
Status: "200 OK",
StatusCode: 200,
// (permitted by RFC 7230, section 3.1.2)
{
"HTTP/1.0 303 \r\n\r\n",
+
+ "HTTP/1.0 303 \r\n" +
+ "Connection: close\r\n" +
+ "\r\n",
+
Response{
Status: "303 ",
StatusCode: 303,
// (not permitted by RFC 7230, but we'll accept it anyway)
{
"HTTP/1.0 303\r\n\r\n",
+
+ "HTTP/1.0 303 303\r\n" +
+ "Connection: close\r\n" +
+ "\r\n",
+
Response{
Status: "303",
StatusCode: 303,
Content-Type: multipart/byteranges; boundary=18a75608c8f47cef
some body`,
+
+ "HTTP/1.1 206 Partial Content\r\n" +
+ "Connection: close\r\n" +
+ "Content-Type: multipart/byteranges; boundary=18a75608c8f47cef\r\n" +
+ "\r\n" +
+ "some body",
+
Response{
Status: "206 Partial Content",
StatusCode: 206,
"\r\n" +
"Body here\n",
+ "HTTP/1.0 200 OK\r\n" +
+ "Connection: close\r\n" +
+ "\r\n" +
+ "Body here\n",
+
Response{
Status: "200 OK",
StatusCode: 200,
"Content-Length: 6\r\n\r\n" +
"foobar",
+ "HTTP/1.1 206 Partial Content\r\n" +
+ "Content-Length: 6\r\n" +
+ "Accept-Ranges: bytes\r\n" +
+ "Content-Range: bytes 0-5/1862\r\n" +
+ "Content-Type: text/plain; charset=utf-8\r\n" +
+ "\r\n" +
+ "foobar",
+
Response{
Status: "206 Partial Content",
StatusCode: 206,
"Connection: keep-alive, close\r\n" +
"\r\n",
+ "HTTP/1.1 200 OK\r\n" +
+ "Connection: close\r\n" +
+ "Content-Length: 256\r\n" +
+ "\r\n",
+
Response{
Status: "200 OK",
StatusCode: 200,
"Connection: close\r\n" +
"\r\n",
+ "HTTP/1.1 200 OK\r\n" +
+ "Connection: close\r\n" +
+ "Content-Length: 256\r\n" +
+ "\r\n",
+
Response{
Status: "200 OK",
StatusCode: 200,
"\r\n" +
"Body here\n",
+ "HTTP/1.0 200 OK\r\n" +
+ "Connection: close\r\n" +
+ "\r\n" +
+ "Body here\n",
+
Response{
Status: "200 OK",
StatusCode: 200,
"\r\n" +
"Body here\n",
+ "HTTP/1.0 200 OK\r\n" +
+ "Connection: close\r\n" +
+ "Content-Length: 10\r\n" +
+ "\r\n" +
+ "Body here\n",
+
Response{
Status: "200 OK",
StatusCode: 200,
"Connection: keep-alive\r\n" +
"Keep-Alive: timeout=7200\r\n\r\n" +
"\x1f\x8b\b\x00\x00\x00\x00\x00\x00\x00s\xf3\xf7\a\x00\xab'\xd4\x1a\x03\x00\x00\x00",
+
+ "HTTP/1.1 200 OK\r\n" +
+ "Content-Length: 23\r\n" +
+ "Connection: keep-alive\r\n" +
+ "Content-Encoding: gzip\r\n" +
+ "Keep-Alive: timeout=7200\r\n\r\n" +
+ "\x1f\x8b\b\x00\x00\x00\x00\x00\x00\x00s\xf3\xf7\a\x00\xab'\xd4\x1a\x03\x00\x00\x00",
+
Response{
Status: "200 OK",
StatusCode: 200,
"Content-type: text/html\r\n" +
"WWW-Authenticate: Basic realm=\"\"\r\n\r\n" +
"Your Authentication failed.\r\n",
+
+ "HTTP/1.0 401 Unauthorized\r\n" +
+ "Connection: close\r\n" +
+ "Content-Type: text/html\r\n" +
+ "Www-Authenticate: Basic realm=\"\"\r\n" +
+ "\r\n" +
+ "Your Authentication failed.\r\n",
+
Response{
Status: "401 Unauthorized",
StatusCode: 401,
t.Errorf("#%d: %v", i, err)
continue
}
- err = resp.Write(io.Discard)
+ var buf bytes.Buffer
+ err = resp.Write(&buf)
if err != nil {
t.Errorf("#%d: %v", i, err)
continue
}
+ if got, want := buf.String(), tt.RawOut; got != want {
+ t.Errorf("#%d: response differs; got:\n----\n%v\n----\nwant:\n----\n%v\n----\n",
+ i,
+ strings.ReplaceAll(got, "\r", "\\r"),
+ strings.ReplaceAll(want, "\r", "\\r"))
+ }
}
}