2

As the title says , is there an api for that?

*fasthttp.Request.Header.key 

When I call the method with POSTMAN , I can't get the header content key as the above code . Why

Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
Mike
  • 419
  • 1
  • 6
  • 16

1 Answers1

4

It may surprise you to learn that fasthttp doesn't store request header values as an exported map[string]string, but as an unexported []byte which it stores indexes into. This apparently is one of its performance optimizations.

You can get a request header value with Peek().

v := ctx.Request.Header.Peek("User-Agent")

Note that this function returns a byte slice, so you'll probably have to convert it to a string.

sv := string(v)
Michael Hampton
  • 9,737
  • 4
  • 55
  • 96