Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In the HTTP CORS spec, what's the difference between Allow-Headers and Expose-Headers?

Tags:

http

cors

In the HTTP CORS spec, what's the difference between 5.6 Access-Control-Allow-Headers and 5.3 Access-Control-Expose-Headers?

[Allow-Headers] header indicates, as part of the response to a preflight request, which header field names can be used during the actual request

UPDATE: I was hoping someone would tell me one of these headers is sent for every request (pre-flight)... However, there is yet another header that is used for that: 5.9 Access-Control-Request-Headers

[Request-Headers] header indicates which headers will be used in the actual request as part of the preflight request

BTW, I love how they (W3C) carefully worded 5.9 so that the request header can have a field called _Something_ Request Header.

I'm completely lost in the spec, is there a diagram where I can understand this process better?

like image 934
BogdanBiv Avatar asked Jan 23 '15 10:01

BogdanBiv


People also ask

What is expose Headers in CORS?

The Access-Control-Expose-Headers response header allows a server to indicate which response headers should be made available to scripts running in the browser, in response to a cross-origin request. Only the CORS-safelisted response headers are exposed by default.

What is an allow header?

The allow-header entry specifies which headers are presented in preflight responses to clients as acceptable to use when making cross-origin requests to resources which this policy is applicable to.


1 Answers

Access-Control-Allow-Headers

Used in response to a preflight request to indicate which HTTP headers can be used when making the actual request.

Access-Control-Expose-Headers

This header lets a server whitelist headers that browsers are allowed to access. For example:

Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

like image 115
Udi Dahan Avatar answered Sep 19 '22 02:09

Udi Dahan