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

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

1 Comment

At first, I used this method to obtain, and the result was not obtained.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.