Skip to content

Commit

Permalink
Use cache-control header to make sure health checks aren't cached
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Apr 4, 2024
1 parent 87a15e5 commit 6f53e36
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ void testHealth() {
try {
RestAssured.defaultParser = Parser.JSON;
when().get("/q/health/ready").then()
.header("cache-control", "no-store")
.body("status", is("UP"),
"checks.status", hasItems("UP", "UP"),
"checks.name", hasItems("alpha1", "bravo1"));
when().get("/q/health/ready").then()
.header("cache-control", "no-store")
.body("status", is("UP"),
"checks.status", hasItems("UP", "UP"),
"checks.name", hasItems("alpha1", "bravo2"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ private void doHandle(RoutingContext ctx, ManagedContext requestContext) {
if (health.isDown()) {
resp.setStatusCode(503);
}
resp.headers().set(HttpHeaders.CONTENT_TYPE, "application/json; charset=UTF-8");
resp.headers()
.set(HttpHeaders.CONTENT_TYPE, "application/json; charset=UTF-8")
.set(HttpHeaders.CACHE_CONTROL, "no-store");
Buffer buffer = Buffer.buffer(256); // this size seems to cover the basic health checks
try (BufferOutputStream outputStream = new BufferOutputStream(buffer);) {
reporter.reportHealth(outputStream, health);
Expand Down

0 comments on commit 6f53e36

Please sign in to comment.