简体   繁体   中英

How to get the header content from *fasthttp.Request of Golang?

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM