-
Notifications
You must be signed in to change notification settings - Fork 31
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
Allow custom headers to be returned as part of pre-flight requests #423
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ | |
|
||
cors { | ||
accessControlMaxAge = 60 minutes | ||
allowedCorsHeaders = ["X-Example"] | ||
} | ||
|
||
streams { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import org.apache.commons.codec.binary.Base64 | |
import scala.concurrent.duration._ | ||
import scala.jdk.CollectionConverters._ | ||
|
||
import cats.data.NonEmptyList | ||
import cats.effect.{Clock, Sync} | ||
import cats.implicits._ | ||
|
||
|
@@ -139,11 +140,13 @@ class Service[F[_]: Sync]( | |
} | ||
|
||
override def preflightResponse(req: Request[F]): F[Response[F]] = Sync[F].pure { | ||
val allowedHeaders = (List("Content-Type", "SP-Anonymous") ++ config.cors.allowedCorsHeaders).map(CIString(_)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about just making There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean as part of the config? My only concern would be if people remove this from a default config. |
||
val corsHeaders = NonEmptyList.fromListUnsafe(allowedHeaders) | ||
Comment on lines
+143
to
+144
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think we can remove the "unsafe" method. Which is harmless in this case, but stands out as worrisome when you see it in collector code. val corsHeaders = NonEmptyList("Content-Type", "SP-Anonymous" :: config.cors.allowedCorsHeaders).map(CIString(_)) |
||
Response[F]( | ||
headers = Headers( | ||
accessControlAllowOriginHeader(req), | ||
`Access-Control-Allow-Credentials`(), | ||
`Access-Control-Allow-Headers`(ci"Content-Type", ci"SP-Anonymous"), | ||
`Access-Control-Allow-Headers`(corsHeaders), | ||
`Access-Control-Max-Age`.Cache(config.cors.accessControlMaxAge.toSeconds).asInstanceOf[`Access-Control-Max-Age`] | ||
) | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file provides defaults for the app. So by adding "X-Example" here, it means all pipelines everywhere will respond with "X-Example" in the list of allowed headers.
Guessing that's probably not what you want?