Skip to content

Commit

Permalink
Ensure that HTTP OPTIONS handling involves the proper handler chain
Browse files Browse the repository at this point in the history
This is done in order to be more consistent with how
other cases are handled and how RESTEasy Classic handles things as well

Fixes: quarkusio#26828
  • Loading branch information
geoand committed Jul 27, 2022
1 parent 314c240 commit 9a49b24
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package io.quarkus.resteasy.reactive.server.test.customproviders;

import static io.restassured.RestAssured.*;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;
import java.util.List;
import java.util.function.Supplier;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import org.jboss.resteasy.reactive.server.ServerRequestFilter;
import org.jboss.resteasy.reactive.server.ServerResponseFilter;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

public class OptionsRequestTest {

@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.setArchiveProducer(new Supplier<>() {
@Override
public JavaArchive get() {
return ShrinkWrap.create(JavaArchive.class)
.addClasses(PreMatchingHeadersFilterTest.Resource.class);
}
});

@Test
public void testJsonHeaderAdded() {
when()
.get("/test")
.then()
.statusCode(200)
.header("X-Foo", equalTo("Bar"))
.header("Allow", equalTo("Bar"));
}

@Path("test")
public static class Resource {

@GET
public String hello() {
return "hello";
}
}

public static class Filters {
@ServerResponseFilter
public void preMatchingFilter(ContainerResponseContext context) {
context.getHeaders().putSingle("X-Foo", "Bar");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void handle(ResteasyReactiveRequestContext requestContext) throws Excepti
if (requestMethod.equals(HttpMethod.HEAD)) {
mapper = mappers.get(HttpMethod.GET);
} else if (requestMethod.equals(HttpMethod.OPTIONS)) {
Set<CharSequence> allowedMethods = new HashSet<>();
Set<String> allowedMethods = new HashSet<>();
for (String method : mappers.keySet()) {
if (method == null) {
continue;
Expand All @@ -53,7 +53,7 @@ public void handle(ResteasyReactiveRequestContext requestContext) throws Excepti
}
allowedMethods.add(HttpMethod.OPTIONS);
allowedMethods.add(HttpMethod.HEAD);
requestContext.serverResponse().setResponseHeader(HttpHeaders.ALLOW, allowedMethods).end();
requestContext.abortWith(Response.ok().allow(allowedMethods).build());
return;
}
if (mapper == null) {
Expand Down

0 comments on commit 9a49b24

Please sign in to comment.