MCPcopy Index your code
hub / github.com/valyala/fasthttp / TestServerDisableHeaderNamesNormalizing

Function TestServerDisableHeaderNamesNormalizing

server_test.go:1600–1645  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1598}
1599
1600func TestServerDisableHeaderNamesNormalizing(t *testing.T) {
1601 t.Parallel()
1602
1603 headerName := "CASE-senSITive-HEAder-NAME"
1604 headerNameLower := strings.ToLower(headerName)
1605 headerValue := "foobar baz"
1606 s := &Server{
1607 Handler: func(ctx *RequestCtx) {
1608 hv := ctx.Request.Header.Peek(headerName)
1609 if string(hv) != headerValue {
1610 t.Errorf("unexpected header value for %q: %q. Expecting %q", headerName, hv, headerValue)
1611 }
1612 hv = ctx.Request.Header.Peek(headerNameLower)
1613 if len(hv) > 0 {
1614 t.Errorf("unexpected header value for %q: %q. Expecting empty value", headerNameLower, hv)
1615 }
1616 ctx.Response.Header.Set(headerName, headerValue)
1617 ctx.WriteString("ok") //nolint:errcheck
1618 ctx.SetContentType("aaa")
1619 },
1620 DisableHeaderNamesNormalizing: true,
1621 }
1622
1623 rw := &readWriter{}
1624 fmt.Fprintf(&rw.r, "GET / HTTP/1.1\r\n%s: %s\r\nHost: google.com\r\n\r\n", headerName, headerValue)
1625
1626 if err := s.ServeConn(rw); err != nil {
1627 t.Fatalf("Unexpected error from serveConn: %v", err)
1628 }
1629
1630 br := bufio.NewReader(&rw.w)
1631 var resp Response
1632 resp.Header.DisableNormalizing()
1633 if err := resp.Read(br); err != nil {
1634 t.Fatalf("unexpected error: %v", err)
1635 }
1636
1637 hv := resp.Header.Peek(headerName)
1638 if string(hv) != headerValue {
1639 t.Fatalf("unexpected header value for %q: %q. Expecting %q", headerName, hv, headerValue)
1640 }
1641 hv = resp.Header.Peek(headerNameLower)
1642 if len(hv) > 0 {
1643 t.Fatalf("unexpected header value for %q: %q. Expecting empty value", headerNameLower, hv)
1644 }
1645}
1646
1647func TestServerReduceMemoryUsageSerial(t *testing.T) {
1648 t.Parallel()

Callers

nothing calls this directly

Calls 8

ServeConnMethod · 0.95
ReadMethod · 0.95
NewReaderMethod · 0.80
DisableNormalizingMethod · 0.80
PeekMethod · 0.65
SetMethod · 0.45
WriteStringMethod · 0.45
SetContentTypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…