@@ -21,14 +21,14 @@ import (
2121func TestInvalidTrailers (t * testing.T ) {
2222 t .Parallel ()
2323
24- if err := (& Response {}).Read (bufio .NewReader (strings .NewReader (" 0 \n Transfer-Encoding:\xff \n \n 0\r \n 0" ))); ! errors .Is (err , io .EOF ) {
25- t .Fatalf ("%#v" , err )
24+ if err := (& Response {}).Read (bufio .NewReader (strings .NewReader ("HTTP/1.1 200 \r \n Transfer-Encoding:\xff \n \n 0\r \n 0" ))); ! errors .Is (err , io .EOF ) {
25+ t .Errorf ("%#v" , err )
2626 }
27- if err := (& Response {}).Read (bufio .NewReader (strings .NewReader ("\xff \ n TRaILeR:,\n \ n " ))); ! errors .Is (err , errEmptyInt ) {
28- t .Fatal (err )
27+ if err := (& Response {}).Read (bufio .NewReader (strings .NewReader ("HTTP/1.1 200 OK \r \ n TRaILeR:,\r \n \r \ n " ))); ! errors .Is (err , ErrBadTrailer ) {
28+ t .Error (err )
2929 }
30- if err := (& Response {}).Read (bufio .NewReader (strings .NewReader ("TRaILeR:,\n \n " ))); ! strings .Contains (err .Error (), "cannot find whitespace in the first line of response" ) {
31- t .Fatal (err )
30+ if err := (& Response {}).Read (bufio .NewReader (strings .NewReader ("TRaILeR:,\r \n \r \n " ))); ! strings .Contains (err .Error (), "cannot find whitespace in the first line of response" ) {
31+ t .Error (err )
3232 }
3333}
3434
@@ -586,7 +586,7 @@ func TestRequestContentTypeWithCharsetIssue100(t *testing.T) {
586586
587587 expectedContentType := "application/x-www-form-urlencoded; charset=UTF-8"
588588 expectedBody := "0123=56789"
589- s := fmt .Sprintf ("POST / HTTP/1.1\r \n Content-Type: %s\r \n Content-Length: %d\r \n \r \n %s" ,
589+ s := fmt .Sprintf ("POST / HTTP/1.1\r \n Host: example.com \r \ n Content-Type: %s\r \n Content-Length: %d\r \n \r \n %s" ,
590590 expectedContentType , len (expectedBody ), expectedBody )
591591
592592 br := bufio .NewReader (bytes .NewBufferString (s ))
@@ -1032,7 +1032,7 @@ func TestRequestReadNoBody(t *testing.T) {
10321032
10331033 var r Request
10341034
1035- br := bufio .NewReader (bytes .NewBufferString ("GET / HTTP/1.1\r \n \r \n " ))
1035+ br := bufio .NewReader (bytes .NewBufferString ("GET / HTTP/1.1\r \n Host: example.com \r \ n\r \n " ))
10361036 err := r .Read (br )
10371037 r .SetHost ("foobar" )
10381038 if err != nil {
@@ -1200,7 +1200,7 @@ func TestRequestReadGzippedBody(t *testing.T) {
12001200
12011201 bodyOriginal := "foo bar baz compress me better!"
12021202 body := AppendGzipBytes (nil , []byte (bodyOriginal ))
1203- s := fmt .Sprintf ("POST /foobar HTTP/1.1\r \n Content-Type: foo/bar\r \n Content-Encoding: gzip\r \n Content-Length: %d\r \n \r \n %s" ,
1203+ s := fmt .Sprintf ("POST /foobar HTTP/1.1\r \n Host: example.com \r \ n Content-Type: foo/bar\r \n Content-Encoding: gzip\r \n Content-Length: %d\r \n \r \n %s" ,
12041204 len (body ), body )
12051205 br := bufio .NewReader (bytes .NewBufferString (s ))
12061206 if err := r .Read (br ); err != nil {
@@ -1231,7 +1231,7 @@ func TestRequestReadPostNoBody(t *testing.T) {
12311231
12321232 var r Request
12331233
1234- s := "POST /foo/bar HTTP/1.1\r \n Content-Type: aaa/bbb\r \n \r \n aaaa"
1234+ s := "POST /foo/bar HTTP/1.1\r \n Host: example.com \r \ n Content-Type: aaa/bbb\r \n \r \n aaaa"
12351235 br := bufio .NewReader (bytes .NewBufferString (s ))
12361236 if err := r .Read (br ); err != nil {
12371237 t .Fatalf ("unexpected error: %v" , err )
@@ -1262,7 +1262,7 @@ func TestRequestReadPostNoBody(t *testing.T) {
12621262func TestRequestContinueReadBody (t * testing.T ) {
12631263 t .Parallel ()
12641264
1265- s := "PUT /foo/bar HTTP/1.1\r \n Expect: 100-continue\r \n Content-Length: 5\r \n Content-Type: foo/bar\r \n \r \n abcdef4343"
1265+ s := "PUT /foo/bar HTTP/1.1\r \n Host: example.org \r \ n Expect: 100-continue\r \n Content-Length: 5\r \n Content-Type: foo/bar\r \n \r \n abcdef4343"
12661266 br := bufio .NewReader (bytes .NewBufferString (s ))
12671267
12681268 var r Request
@@ -2034,7 +2034,7 @@ func TestResponseReadWithoutBody(t *testing.T) {
20342034 testResponseReadWithoutBody (t , & resp , "HTTP/1.1 123 AAA\r \n Content-Type: xxx\r \n Content-Length: 3434\r \n \r \n " , false ,
20352035 123 , 3434 , "xxx" )
20362036
2037- testResponseReadWithoutBody (t , & resp , "HTTP 200 OK\r \n Content-Type: text/xml\r \n Content-Length: 123\r \n \r \n foobar\r \n " , true ,
2037+ testResponseReadWithoutBody (t , & resp , "HTTP/1.1 200 OK\r \n Content-Type: text/xml\r \n Content-Length: 123\r \n \r \n foobar\r \n " , true ,
20382038 200 , 123 , "text/xml" )
20392039
20402040 // '100 Continue' must be skipped.
@@ -3120,6 +3120,12 @@ func TestRequestMultipartFormPipeEmptyFormField(t *testing.T) {
31203120 if err != nil {
31213121 t .Fatalf ("unexpected error: %v" , err )
31223122 }
3123+ if _ , err = bw .Write (strCRLF ); err != nil {
3124+ t .Fatalf ("unexpected error: %v" , err )
3125+ }
3126+ if err = bw .Flush (); err != nil {
3127+ t .Fatalf ("unexpected error: %v" , err )
3128+ }
31233129
31243130 for e := range errs {
31253131 t .Fatalf ("unexpected error in goroutine multiwriter: %v" , e )
0 commit comments