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

Fixed handling of CORS within Vert.x #4232

Merged
merged 5 commits into from
Jan 9, 2025
Merged

Conversation

sergiuszkierat
Copy link
Member

@sergiuszkierat sergiuszkierat commented Jan 2, 2025

Technical changes related to this issue:

  • registered options handler explicitly

Technical changes NOT related to this issue:

  • added CORSInterceptor example for Vert.x server

Closes #3651

@sergiuszkierat sergiuszkierat self-assigned this Jan 2, 2025
@sergiuszkierat sergiuszkierat force-pushed the fix/interceptor_with_vertex branch 2 times, most recently from 7a41568 to e06cec8 Compare January 7, 2025 18:50
@sergiuszkierat sergiuszkierat marked this pull request as ready for review January 7, 2025 19:07
@@ -25,6 +26,14 @@ object PathMapping {
case (None, path) => router.route(path)
}

private[vertx] def createOptionsRoute(router: Router, route: RouteDefinition): Option[Route] =
Copy link
Member

Choose a reason for hiding this comment

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

I don't think I understand the purpose of this method. Is it "Options" as in the OPTIONS HTTP method? If so, why are we creating an options-route if the method is get/head/post/etc.?

Copy link
Member Author

Choose a reason for hiding this comment

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

Based on this Vert.x will signal a 405 error if a route matches the path, but doesn’t match the HTTP Method. As I understand this is our case, so I've artificially added its counterpart OPTIONS route for the same path in order to get a chance to pass through. Do you see a better approach?

@@ -26,7 +26,9 @@ trait VertxFutureServerInterpreter extends CommonServerInterpreter with VertxErr
* A function, that given a router, will attach this endpoint to it
*/
def route[A, U, I, E, O](e: ServerEndpoint[VertxStreams with WebSockets, Future]): Router => Route = { router =>
mountWithDefaultHandlers(e)(router, extractRouteDefinition(e.endpoint), vertxFutureServerOptions)
val routeDef = extractRouteDefinition(e.endpoint)
optionsRoute(e)(router, routeDef).foreach(_.handler(endpointHandler(e)))
Copy link
Member

Choose a reason for hiding this comment

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

I think this would need some more explanation, as to why it's needed here and what's the purpose. Won't we run the routes twice?

Copy link
Member Author

Choose a reason for hiding this comment

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

Having only i.e. GET /path is not sufficient 🫨 , so by adding its counterpart OPTIONS /path I am explaining to Vert.x : please accept my preflight request instead of rejecting it quickly

*Technical changes related to this issue:*
- registered options handler explicitly

*Technical changes NOT related to this issue:*
- added CORSInterceptor example for Vert.x server

Closes #3651
@sergiuszkierat
Copy link
Member Author

We have CORS tests which pass smoothly here 😭 I've added the draft PR which needs to be continued. As fixed tests might raise the issues within other servers.

@sergiuszkierat sergiuszkierat force-pushed the fix/interceptor_with_vertex branch from e06cec8 to d9205e0 Compare January 8, 2025 13:15
@adamw adamw merged commit 9ee00fe into master Jan 9, 2025
33 checks passed
@adamw adamw deleted the fix/interceptor_with_vertex branch January 9, 2025 08: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.

[BUG] CORSInterceptor doesn't work with Vert.x server
2 participants