How can I read a header from an http request in golang?

前端 未结 3 1392
闹比i
闹比i 2021-02-02 05:53

If I receive a request of type http.Request, how can I read the value of a specific header? In this case I want to pull the value of a jwt token out of the request

3条回答
  •  耶瑟儿~
    2021-02-02 06:10

    You can use the r.Header.Get:

    func yourHandler(w http.ResponseWriter, r *http.Request) {
        ua := r.Header.Get("User-Agent")
        ...
    }
    

提交回复
热议问题