Skip to content

Allow for more CORS configuration #1594

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

Merged
merged 3 commits into from
May 9, 2023
Merged

Allow for more CORS configuration #1594

merged 3 commits into from
May 9, 2023

Conversation

glbrntt
Copy link
Collaborator

@glbrntt glbrntt commented May 2, 2023

Motivation:

We added some level of CORS configuration support in #1583. This change adds further flexibility.

Modifications:

  • Add an 'originBased' mode where the value of the origin header is returned in the response head.
  • Add a custom fallback where the user can specify a callback which is passed the value of the origin header and returns the value to return in the 'access-control-allow-origin' response header (or nil, if the origin is not allowed).

Result:

More flexibility for CORS.

@glbrntt glbrntt added the 🆕 semver/minor Adds new public API. label May 2, 2023
Motivation:

We added some level of CORS configuration support in grpc#1583. This change adds
further flexibility.

Modifications:

- Add an 'originBased' mode where the value of the origin header is
  returned in the response head.
- Add a custom fallback where the user can specify a callback which
  is passed the value of the origin header and returns the value to
  return in the 'access-control-allow-origin' response header (or nil,
  if the origin is not allowed).

Result:

More flexibility for CORS.
private var checkOrigin: @Sendable (String) -> String?
private let hashInto: @Sendable (inout Hasher) -> Void
#if swift(>=5.7)
private let isEqualTo: @Sendable (any GRPCCustomCORSAllowedOrigin) -> Bool
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we get warnings if we don't use any with new swift compilers?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No; from what I can tell we get an error if the protocol has Self or associatedtype. We have that here via Equatable.

@glbrntt glbrntt requested a review from Lukasa May 4, 2023 06:54
@glbrntt glbrntt enabled auto-merge (squash) May 9, 2023 12:32
@glbrntt glbrntt merged commit ef8ffb9 into grpc:main May 9, 2023
@glbrntt glbrntt deleted the gb-more-cors branch May 9, 2023 12:43
WendellXY pushed a commit to sundayfun/grpc-swift that referenced this pull request Aug 24, 2023
Motivation:

We added some level of CORS configuration support in grpc#1583. This change adds
further flexibility.

Modifications:

- Add an 'originBased' mode where the value of the origin header is
  returned in the response head.
- Add a custom fallback where the user can specify a callback which
  is passed the value of the origin header and returns the value to
  return in the 'access-control-allow-origin' response header (or nil,
  if the origin is not allowed).

Result:

More flexibility for CORS.
pinlin168 pushed a commit to sundayfun/grpc-swift that referenced this pull request Aug 24, 2023
Motivation:

We added some level of CORS configuration support in grpc#1583. This change adds
further flexibility.

Modifications:

- Add an 'originBased' mode where the value of the origin header is
  returned in the response head.
- Add a custom fallback where the user can specify a callback which
  is passed the value of the origin header and returns the value to
  return in the 'access-control-allow-origin' response header (or nil,
  if the origin is not allowed).

Result:

More flexibility for CORS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants