(t *testing.T)
| 180 | } |
| 181 | |
| 182 | func TestResponseHeaderMultiLineValue(t *testing.T) { |
| 183 | t.Parallel() |
| 184 | |
| 185 | s := "HTTP/1.1 200 SuperOK\r\n" + |
| 186 | "EmptyValue1:\r\n" + |
| 187 | "Content-Type: foo/bar;\r\n\tnewline;\r\n another/newline\r\n" + |
| 188 | "Foo: Bar\r\n" + |
| 189 | "Multi-Line: one;\r\n two\r\n" + |
| 190 | "Values: v1;\r\n v2; v3;\r\n v4;\tv5\r\n" + |
| 191 | "\r\n" |
| 192 | header := new(ResponseHeader) |
| 193 | if _, err := header.parse([]byte(s)); err != nil { |
| 194 | t.Fatalf("parse headers with multi-line values failed, %v", err) |
| 195 | } |
| 196 | response, err := http.ReadResponse(bufio.NewReader(strings.NewReader(s)), nil) |
| 197 | if err != nil { |
| 198 | t.Fatalf("parse response using net/http failed, %v", err) |
| 199 | } |
| 200 | defer func() { _ = response.Body.Close() }() |
| 201 | |
| 202 | if !bytes.Equal(header.StatusMessage(), []byte("SuperOK")) { |
| 203 | t.Errorf("parse status line with non-default value failed, got: '%q' want: 'SuperOK'", header.StatusMessage()) |
| 204 | } |
| 205 | |
| 206 | header.SetProtocol([]byte("HTTP/3.3")) |
| 207 | if !bytes.Equal(header.Protocol(), []byte("HTTP/3.3")) { |
| 208 | t.Errorf("parse protocol with non-default value failed, got: '%q' want: 'HTTP/3.3'", header.Protocol()) |
| 209 | } |
| 210 | |
| 211 | if !bytes.Equal(header.appendStatusLine(nil), []byte("HTTP/3.3 200 SuperOK\r\n")) { |
| 212 | t.Errorf("parse status line with non-default value failed, got: '%q' want: 'HTTP/3.3 200 SuperOK'", header.Protocol()) |
| 213 | } |
| 214 | |
| 215 | header.SetStatusMessage(nil) |
| 216 | |
| 217 | if !bytes.Equal(header.appendStatusLine(nil), []byte("HTTP/3.3 200 OK\r\n")) { |
| 218 | t.Errorf("parse status line with default protocol value failed, got: '%q' want: 'HTTP/3.3 200 OK'", header.appendStatusLine(nil)) |
| 219 | } |
| 220 | |
| 221 | header.SetStatusMessage(s2b(StatusMessage(200))) |
| 222 | |
| 223 | if !bytes.Equal(header.appendStatusLine(nil), []byte("HTTP/3.3 200 OK\r\n")) { |
| 224 | t.Errorf("parse status line with default protocol value failed, got: '%q' want: 'HTTP/3.3 200 OK'", header.appendStatusLine(nil)) |
| 225 | } |
| 226 | |
| 227 | for name, vals := range response.Header { |
| 228 | got := string(header.Peek(name)) |
| 229 | want := vals[0] |
| 230 | |
| 231 | if got != want { |
| 232 | t.Errorf("unexpected %q got: %q want: %q", name, got, want) |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | func TestIssue1808(t *testing.T) { |
| 238 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…