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

Unexpected Access-Control-Expose-Headers header behavior #159

Closed
chrismeyers opened this issue Sep 28, 2023 · 2 comments · Fixed by #160
Closed

Unexpected Access-Control-Expose-Headers header behavior #159

chrismeyers opened this issue Sep 28, 2023 · 2 comments · Fixed by #160

Comments

@chrismeyers
Copy link
Contributor

I noticed that responses always include the Access-Control-Expose-Headers header even if Options.ExposedHeaders is not set. Running one of the examples, such as examples/gorilla/server.go, produces the following response:

$ curl -i -X GET 'http://localhost:8080' --header 'Origin: http://localhost:3000'
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers:
Content-Type: application/json
Vary: Origin
Date: Thu, 28 Sep 2023 00:33:47 GMT
Content-Length: 18

{"hello": "world"}

Is this the correct behavior? I would expect Access-Control-Expose-Headers to be omitted if no Options.ExposedHeaders value is set. If this is indeed a bug, I have a solution and can submit a PR to fix this.

@rs
Copy link
Owner

rs commented Sep 28, 2023

I'm not sure how this could happen. Which version of the lib are you using?

@chrismeyers
Copy link
Contributor Author

I'm using the latest version of this library (v1.10.0) and the latest version of Go (go version go1.21.1 darwin/arm64).

Looking into the code, this line is returning []string{""} instead of []string{} when Options.ExposedHeaders is omitted:

cors/cors.go

Line 218 in 20a76bd

c.exposedHeaders = []string{strings.Join(convert(options.ExposedHeaders, http.CanonicalHeaderKey), ", ")}

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

Successfully merging a pull request may close this issue.

2 participants