Skip to content

Commit

Permalink
Merge pull request #33923 from rhuan080/fix-33922
Browse files Browse the repository at this point in the history
Return Access-Control-Expose-Headers in normal CORS requests
  • Loading branch information
sberyozkin authored Jun 15, 2023
2 parents 0b6c225 + 0fcfc8b commit c7c7370
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ public void corsFullConfigTestServlet() {
.header("Access-Control-Allow-Headers", "X-Custom")
.header("Access-Control-Max-Age", "86400");

given().header("Origin", "http://custom.origin.quarkus")
.when()
.get("/test").then()
.statusCode(200)
.header("Access-Control-Allow-Origin", "http://custom.origin.quarkus")
.header("Access-Control-Allow-Methods", "GET,PUT,POST")
.header("Access-Control-Expose-Headers", "Content-Disposition")
.header("Access-Control-Allow-Headers", "X-Custom");

given().header("Origin", "http://www.quarkus.io")
.header("Access-Control-Request-Method", "PUT")
.when()
Expand All @@ -40,6 +49,7 @@ public void corsFullConfigTestServlet() {
.header("Access-Control-Allow-Origin", "http://www.quarkus.io")
.header("Access-Control-Allow-Methods", "GET,PUT,POST")
.header("Access-Control-Expose-Headers", "Content-Disposition");

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ public void handle(RoutingContext event) {
if (allowedMethods != null) {
response.headers().add(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, allowedMethods);
}

//always set expose headers if present
if (exposedHeaders != null) {
response.headers().add(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, exposedHeaders);
}

//we check that the actual request matches the allowed methods and headers
if (!isMethodAllowed(request.method())) {
LOG.debug("Method is not allowed");
Expand Down Expand Up @@ -216,10 +222,6 @@ private void handlePreflightRequest(RoutingContext event, String requestedHeader
response.headers().add(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, exposedHeaders);
}

if (!isConfiguredWithWildcard(corsConfig.exposedHeaders)) {
response.headers().set(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, this.exposedHeaders);
}

}

static boolean isSameOrigin(HttpServerRequest request, String origin) {
Expand Down

0 comments on commit c7c7370

Please sign in to comment.