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

API Gateway removes Access-Control-Allow-Headers header #307

Open
akrabat opened this issue Jun 1, 2018 · 6 comments
Open

API Gateway removes Access-Control-Allow-Headers header #307

akrabat opened this issue Jun 1, 2018 · 6 comments

Comments

@akrabat
Copy link
Member

akrabat commented Jun 1, 2018

Given an action that looks like this:

<?php
function main(array $args) : array
{
    return [
        'statusCode' => 301,
        'headers' => [
            'Location' => '/books',
            'Access-Control-Allow-Headers' => 'Content-Type'
        ],
    ];
}

that's wired up to the API Gateway, I expect to see the Access-Control-Allow-Headers header in the response. Instead it is gone!

Headers in Web Action response:

$ curl -i -H "X-Require-Whisk-Auth: $REQUIRE_WHISK_AUTH" https://openwhisk.eu-gb.bluemix.net/api/v1/web/19FT_dev/default/ow-php-bookshelf-backend-dev-root
HTTP/1.1 301 Moved Permanently
X-Backside-Transport: OK OK
Connection: Keep-Alive
Transfer-Encoding: chunked
Server: nginx
Date: Fri, 01 Jun 2018 15:49:32 GMT
X-Request-ID: 908fab442952df93704c73c8a9e9abb3,908fab442952df93704c73c8a9e9abb3
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: OPTIONS, GET, DELETE, POST, PUT, HEAD, PATCH
Access-Control-Allow-Headers: Authorization, Content-Type,Content-Type
Location: /books
IBM_Cloud_Functions: OpenWhisk
X-Global-Transaction-ID: 34285313
Set-Cookie: DPJSESSIONID=PBC5YS:1342728446; Path=/; Domain=.openwhisk.eu-gb.bluemix.net

Headers in the API Gateway response:

$ curl -i https://service.eu.apiconnect.ibmcloud.com/gws/apigateway/api/2fbc … 8be1/ow-bookshelf-todo-backend/
HTTP/2 301
access-control-allow-credentials: true
access-control-allow-methods: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS
access-control-allow-origin: *
content-type: text/plain
date: Fri, 01 Jun 2018 15:50:58 GMT
ibm_cloud_functions: OpenWhisk
location: /books
server: openresty
set-cookie: DPJSESSIONID=PBC5YS:1342728446; Path=/; Domain=.openwhisk.eu-gb.bluemix.net
x-backside-transport: OK OK
x-gateway-host: 10.164.193.60:31353
x-global-transaction-id: 139638815
x-request-id: 9e54ef0ebeafdcfd2ea43d6806820587,9e54ef0ebeafdcfd2ea43d6806820587
x-request-id: nluhqvi9P9YoSXB8gjPTCuatZpU55eUH
content-length: 0

As you can see, the Access-Control-Allow-Headers header that's in the web action response is missing from the API Gateway response.

@rabbah
Copy link
Member

rabbah commented Jun 1, 2018

side note but why are there two x-request-id fields with values 9e54ef0ebeafdcfd2ea43d6806820587 and nluhqvi9P9YoSXB8gjPTCuatZpU55eUH?

@akrabat
Copy link
Member Author

akrabat commented Jun 1, 2018

A little bit more investigation shows that if I do a pre-flight OPTIONS call, then API Gateway will respond with a reflection of what I send:

$ curl -i -X OPTIONS -H "Access-Control-Request-Headers: Content-Type, X-Pingback" https://service.eu.ap…

HTTP/2 200
access-control-allow-credentials: true
access-control-allow-headers: Content-Type, X-Pingback
access-control-allow-methods: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS
access-control-allow-origin: *

Maybe the test suite I'm writing against is wrong to expect Access-Control-Allow-Headers in a "simple" request.

@mhamann
Copy link
Member

mhamann commented Aug 9, 2019

@akrabat i know this is an old issue, but do you happen to have the api config (swagger) you passed in here?

@akrabat
Copy link
Member Author

akrabat commented Aug 9, 2019

I've never used the swagger config, so I would have connected it via wsk api

@rabbah
Copy link
Member

rabbah commented Oct 2, 2019

@mhamann what's the status on this?

@mhamann
Copy link
Member

mhamann commented Oct 2, 2019

There should be three states:

  • ON: Gateway injects CORS headers
  • OFF: Gateway explicitly removes all CORS headers if present
  • Passthru: Gateway doesn't inject CORS headers, but allows them to pass through from the backend if present.

I believe this is working correctly, but I'd have to look at the test cases to confirm that.

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

4 participants
@akrabat @mhamann @rabbah and others