I have created and deployed an AWS API Gateway resource with the following structure including a custom HTTP Request Header 'X-header'
dev (stage)
/echo (resource)
POST (method)
Method Request - Headers: X-header
OPTIONS (method)
Method Request - Headers: X-header
When I POST to the endpoint from Chrome, I get the following error.
XMLHttpRequest cannot load https://fxxxx.execute-api.us-west-2.amazonaws.com/dev/echo. Request header field X-header is not allowed by Access-Control-Allow-Headers in preflight response.
Chrome is doing a preflight check against the OPTIONS method. I can see the Request Headers:
Access-Control-Request-Headers:accept, content-type, x-header
Access-Control-Request-Method:POST
But the Response Headers only have:
Access-Control-Allow-Headers:Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token
Access-Control-Allow-Methods:POST,OPTIONS
Access-Control-Allow-Origin:*
Chrome expects the Response Access-Control-Request-Headers to include my custom x-header, which seems logical. Is this an API Gateway bug?
The only workaround I see is to remove the custom header and pass the data in the POST body.