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

Fix bug with CORS headers #57

Merged
merged 2 commits into from
Nov 3, 2023
Merged

Fix bug with CORS headers #57

merged 2 commits into from
Nov 3, 2023

Conversation

evgeniy-scherbina
Copy link
Contributor

No description provided.

@evgeniy-scherbina evgeniy-scherbina force-pushed the yevhenii/cache-fix branch 3 times, most recently from 5961b65 to b48a181 Compare November 3, 2023 15:55
@evgeniy-scherbina evgeniy-scherbina changed the title Temporary Commit Fix bug with CORS headers Nov 3, 2023
@evgeniy-scherbina evgeniy-scherbina force-pushed the yevhenii/cache-fix branch 2 times, most recently from 07edcdd to f060113 Compare November 3, 2023 16:09
@evgeniy-scherbina evgeniy-scherbina marked this pull request as ready for review November 3, 2023 16:20
DEFAULT_ACCESS_CONTROL_ALLOW_ORIGIN_VALUE="*"
# Map contains mapping between hostname (for ex. evm.kava.io) and corresponding value for Access-Control-Allow-Origin header.
# If hostname for specific request is missing we fallback to DEFAULT_ACCESS_CONTROL_ALLOW_ORIGIN_VALUE.
# NOTE: it will be used only in Cache Hit scenario.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update caching docs with details on how the cachng middleware affects headers and logic for deciding when to modify cors headers

@@ -254,6 +254,11 @@ func createProxyRequestMiddleware(next http.Handler, config config.Config, servi
for headerName, headerValue := range typedCachedResponse.HeaderMap {
w.Header().Add(headerName, headerValue)
}
// add CORS headers
accessControlAllowOriginValue := config.GetAccessControlAllowOriginValue(r.Host)
if accessControlAllowOriginValue != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

important to add to the spec in the caching doc that we won't override any value of this header if present from the backend response

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually in current implementation we override

I can add smth like this:

// add CORS headers
accessControlAllowOriginValue := config.GetAccessControlAllowOriginValue(r.Host)
if w.Header().Get("Access-Control-Allow-Origin") == "" && accessControlAllowOriginValue != "" {
    w.Header().Add("Access-Control-Allow-Origin", accessControlAllowOriginValue)
}

@galxy25 ?

@evgeniy-scherbina evgeniy-scherbina merged commit abdad16 into main Nov 3, 2023
4 checks passed
@evgeniy-scherbina evgeniy-scherbina deleted the yevhenii/cache-fix branch November 3, 2023 17:45
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 this pull request may close these issues.

2 participants