Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

response.headers.get('') bug? #13

Closed
coldestheart opened this issue Mar 11, 2020 · 2 comments
Closed

response.headers.get('') bug? #13

coldestheart opened this issue Mar 11, 2020 · 2 comments

Comments

@coldestheart
Copy link

coldestheart commented Mar 11, 2020

Hello, ive tried to migrate from axios (using nuxt), and start using '@nuxt/http' but when i was tryed to get header from the post response

import http from 'ky-universal'
const actions = {
  // Get Token
  async login(context, payload) {
    let data = null
    try {
      data = await http.post(
        process.env.apiUrl + '/api/content/create?type=User',
        {
          body: payload
        }
      )
    } catch (err) {}
    console.log(data.headers.get('Authorization'))
  },
}

console.log(data.headers.get('Authorization')) shows null, there is anyway to make it work?

in firefox network tab response header looks like:

HTTP/1.1 200 OK
Access-Control-Allow-Headers: Accept, Authorization, Content-Type
Access-Control-Allow-Origin: *
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhY2Nlc3MiOiJjb2xkQGNvbGQuY29sZCIsImF1ZCI6bnVsbCwiZXhwIjoxNTg0NTQyMzMwLCJpYXQiOm51bGwsImlzcyI6bnVsbCwianRpIjpudWxsLCJuYmYiOm51bGwsInN1YiI6bnVsbH0.SYAwu0h5xA6xNQQGqja9uItHq0Wbq-52I4CrT78N7U0
Cache-Control: max-age=2592000, public
Etag: MTU4MzkzNjUzMw==
Date: Wed, 11 Mar 2020 14:38:50 GMT
Content-Length: 0
@sholladay
Copy link
Collaborator

I don't know why it's not working, but Authorization is a request header, not a response header. This usage is invalid as far as the HTTP spec is concerned.

https://tools.ietf.org/html/rfc7235#section-4.2

@coldestheart
Copy link
Author

Thx for an answer, sorry about this stupid question cause im newbie, i've just tried to use https://github.com/bosssauce/access/ and there was cfg.ResponseWriter.Header().Add("Authorization", "Bearer "+token), i thought that was right way to send token in header of response, sorry and thx again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants