Reputation: 3579
enable-cors.org nginx config suggests using the below values for Access-Control-Allow-Headers
and Access-Control-Expose-Headers
. But there isn't much explanation of why these are recommended except Custom headers and headers various browsers *should* be OK with but aren't
. I'd rather not inflate the payload for every API request if some of these are not needed for my application.
I know I could remove them and wait for something to break but I'm hoping for some background on why/how they were selected so I can make a more educated decision on whether they are necessary for my application. i.e. were they recommended to support a browser that my application doesn't need to support?
Access-Control-Allow-Headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range
Access-Control-Expose-Headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range
For the Allow-Headers
, I can understand for most of them why a client would want to send them. X-CustomHeader
stands out as an oddball though. Also, I tested on Chrome that even if User-Agent
isn't explicitly allowed, chrome still sends it. This implies that these options were added for browser compatibility that my app might not need.
For the Expose-Headers
, it seems like it would be very application specific on which headers a client needs to read. Why would a client need to read User-Agent
, DNT
, or X-Requested-With
? They contain info meant for the server to consume, not the client. Additionally, Cache-Control
and Content-Range
are already enabled by default so they seem redundant here.
Upvotes: 3
Views: 3710
Reputation: 3579
I ended up going through each header and determining if it was necessary. I compiled a list of changes:
Allow
and Expose
X-CustomHeader
Allow
:
Content-Range
Content-Type
Expose
:
Cache-Control
Content-Type
DNT
User-Agent
X-Requested-With
If-Modified-Since
Range
Content-Length
This leaves me with the following:
Access-Control-Allow-Headers: DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range
Access-Control-Expose-Headers: Content-Length,Content-Range
Any comments or corrections would be greatly appreciated.
Upvotes: 5