(t *testing.T)
| 402 | } |
| 403 | |
| 404 | func TestFastBinder_Chunked(t *testing.T) { |
| 405 | handler := func(ctx *fasthttp.RequestCtx) { |
| 406 | assert.Equal(t, "POST", string(ctx.Request.Header.Method())) |
| 407 | assert.Equal(t, "http://example.com/path", string(ctx.Request.Header.RequestURI())) |
| 408 | |
| 409 | assert.Equal(t, "application/x-www-form-urlencoded", |
| 410 | string(ctx.Request.Header.ContentType())) |
| 411 | |
| 412 | headers := map[string][]string{} |
| 413 | |
| 414 | ctx.Request.Header.VisitAll(func(k, v []byte) { |
| 415 | headers[string(k)] = append(headers[string(k)], string(v)) |
| 416 | }) |
| 417 | |
| 418 | expected := map[string][]string{ |
| 419 | "Host": {"example.com"}, |
| 420 | "Content-Type": {"application/x-www-form-urlencoded"}, |
| 421 | "Transfer-Encoding": {"chunked"}, |
| 422 | } |
| 423 | |
| 424 | assert.Equal(t, expected, headers) |
| 425 | |
| 426 | assert.Equal(t, "bar", string(ctx.FormValue("foo"))) |
| 427 | assert.Equal(t, "foo=bar", string(ctx.Request.Body())) |
| 428 | |
| 429 | ctx.Response.Header.Set("Content-Type", "application/json") |
| 430 | ctx.Response.SetBodyStreamWriter(func(w *bufio.Writer) { |
| 431 | _, _ = w.WriteString(`[1, `) |
| 432 | _ = w.Flush() |
| 433 | _, _ = w.WriteString(`2]`) |
| 434 | }) |
| 435 | } |
| 436 | |
| 437 | client := &http.Client{ |
| 438 | Transport: NewFastBinder(handler), |
| 439 | } |
| 440 | |
| 441 | req, err := http.NewRequest( |
| 442 | "POST", "http://example.com/path", strings.NewReader("foo=bar")) |
| 443 | |
| 444 | if err != nil { |
| 445 | t.Fatal(err) |
| 446 | } |
| 447 | |
| 448 | req.Header.Set("Content-Type", "application/x-www-form-urlencoded") |
| 449 | |
| 450 | req.ContentLength = -1 |
| 451 | |
| 452 | resp, err := client.Do(req) |
| 453 | if err != nil { |
| 454 | t.Fatal(err) |
| 455 | } |
| 456 | |
| 457 | assert.Equal(t, []string{"chunked"}, resp.TransferEncoding) |
| 458 | } |
| 459 | |
| 460 | func TestFastBinder_EmptyResponse(t *testing.T) { |
| 461 | handler := func(*fasthttp.RequestCtx) {} |
nothing calls this directly
no test coverage detected
searching dependent graphs…