Custom header not being sent during OPTIONS request.
See original GitHub issueDescribe the issue
Axios not sending custom header during OPTIONS request.
I use axios 0.18.0
in my Vue.js application that is running in e.g. cms.abc.com. and the server is running on APIGee with url server.abc.com.
When I check the logs from APIGee I’m not receiving the value of x-api-key
on OPTIONS request.
Example Code
const headers = {
'X-API-Key': '123123x123123'
}
return axios({
method: 'get',
url: 'https://server.abc.com/content/v1/deals',
headers: headers
}).then(response => {
console.log(response.data)
return response.data;
})
Expected behavior, if applicable
I’m expecting that axios is also sending the x-api-key
during OPTIONS request. It only sends during GET request. Not sure if browsers really not sending custom headers during pre-flight request.
Environment
- Axios Version 0.18.0
- Adapter HTTP
- Browser Chrome
- Browser Version: Version 87.0.4280.88
- Node.js Version: 12.7.0
- OS: OSX 11.0.1
- Additional Library Versions Nuxt 2.13.3
Additional context/Screenshots
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
How do you send a custom header in a CORS preflight ...
This is by design; the purpose of the preflight request is to determine what information the useragent (browser) is permitted to send beyond...
Read more >Access-Control-Allow-Headers - HTTP - MDN Web Docs
It indicates that a custom header named X-Custom-Header is supported by CORS requests to the server (in addition to the CORS-safelisted ...
Read more >How do I add custom header to pre-flight OPTIONS request?
I am making a GET request to API that requires authorization header with key. Since it is cross-domain request there is pre-flight request...
Read more >Chapter 4. Handling preflight requests - CORS in Action
It contains information like which HTTP method is used, as well as if any custom HTTP headers are present. The preflight gives the...
Read more >Techniques for bypassing CORS Preflight Requests to ...
This Preflight request is dispatched transparently by the browser -- JavaScript code does not explicitly enact the Preflight OPTIONS request ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Unfortunately this isn’t something axios can fix —at least not in this case.
In browser environments, CORS-preflight requests are initiated and entirely managed by the user agent; the preflight operations are completely opaque to our userland code and axios has no ability to add additional headers to the outgoing
OPTIONS
request (because it isn’t making it).If you’re fortunate enough to control the backend (APIGee server at server.abc.com in this case), the solution is to update the server code to correctly handle CORS-preflight requests; I recommend this great explainer from MDN as a starting point.
I have the same problem, any solutions?