-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21102 from gastaldi/http
Introduce `quarkus.http.header`
- Loading branch information
Showing
7 changed files
with
184 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/HeaderConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.quarkus.vertx.http.runtime; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
import io.quarkus.runtime.annotations.ConfigItem; | ||
|
||
/** | ||
* Configuration that allows for setting an HTTP header | ||
*/ | ||
@ConfigGroup | ||
public class HeaderConfig { | ||
|
||
/** | ||
* The path this header should be applied | ||
*/ | ||
@ConfigItem(defaultValue = "/*") | ||
public String path; | ||
|
||
/** | ||
* The value for this header configuration | ||
*/ | ||
@ConfigItem | ||
public String value; | ||
|
||
/** | ||
* The HTTP methods for this header configuration | ||
*/ | ||
@ConfigItem | ||
public Optional<List<String>> methods; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
integration-tests/vertx-http/src/main/java/io/quarkus/it/vertx/HeaderResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.quarkus.it.vertx; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.core.Response; | ||
|
||
@Path("/headers") | ||
public class HeaderResource { | ||
|
||
@GET | ||
@Path("/any") | ||
public String headers() { | ||
return "ok"; | ||
} | ||
|
||
@GET | ||
@Path("/pragma") | ||
public String pragmaHeaderMustBeSet() { | ||
return "ok"; | ||
} | ||
|
||
@GET | ||
@Path("/override") | ||
public Response headersOverride() { | ||
return Response.ok("ok").header("foo", "abc").build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
integration-tests/vertx-http/src/test/java/io/quarkus/it/vertx/HeadersTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.quarkus.it.vertx; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.Matchers.emptyOrNullString; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
public class HeadersTestCase { | ||
|
||
@Test | ||
void testAdditionalHeaders() { | ||
given() | ||
.get("/headers/any") | ||
.then() | ||
.header("foo", is("bar")) | ||
.header("Pragma", emptyOrNullString()) | ||
.body(is("ok")); | ||
|
||
} | ||
|
||
@Test | ||
void testAdditionalHeadersOverride() { | ||
given() | ||
.get("/headers/override") | ||
.then() | ||
.header("foo", is("abc")) | ||
.header("Pragma", emptyOrNullString()) | ||
.body(is("ok")); | ||
} | ||
|
||
@Test | ||
void testPragmaIsSent() { | ||
given() | ||
.get("/headers/pragma") | ||
.then() | ||
.header("foo", is("bar")) | ||
.header("Pragma", is("no-cache")) | ||
.body(is("ok")); | ||
|
||
} | ||
|
||
} |