Skip to content

Commit 50942ca

Browse files
tjquinnobarchetta
authored andcommitted
Restore setting of no-cache header in health HTTP responses; add test (helidon-io#9671)
1 parent d143290 commit 50942ca

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

webserver/observe/health/src/main/java/io/helidon/webserver/observe/health/HealthHandler.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
2222

2323
import io.helidon.health.HealthCheck;
2424
import io.helidon.health.HealthCheckResponse;
25+
import io.helidon.http.HeaderValues;
2526
import io.helidon.http.HtmlEncoder;
2627
import io.helidon.http.Status;
2728
import io.helidon.http.media.EntityWriter;
@@ -84,6 +85,7 @@ public void handle(ServerRequest req, ServerResponse res) {
8485
};
8586

8687
res.status(responseStatus);
88+
res.header(HeaderValues.CACHE_NO_CACHE);
8789

8890
if (details) {
8991
entityWriter.write(JsonpSupport.JSON_OBJECT_TYPE,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2025 Oracle and/or its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.helidon.webserver.observe.health;
17+
18+
import io.helidon.common.testing.http.junit5.HttpHeaderMatcher;
19+
import io.helidon.http.HeaderNames;
20+
import io.helidon.webclient.http1.Http1Client;
21+
import io.helidon.webclient.http1.Http1ClientResponse;
22+
import io.helidon.webserver.testing.junit5.ServerTest;
23+
24+
import org.junit.jupiter.api.Test;
25+
26+
import static org.hamcrest.MatcherAssert.assertThat;
27+
import static org.hamcrest.Matchers.allOf;
28+
29+
@ServerTest
30+
class TestNoCacheHeaders {
31+
32+
private final Http1Client client;
33+
34+
TestNoCacheHeaders(Http1Client client) {
35+
this.client = client;
36+
}
37+
38+
@Test
39+
void testNoCacheHeaders() {
40+
try (Http1ClientResponse response = client
41+
.get("/observe/health")
42+
.request()) {
43+
44+
assertThat("No-cache headers",
45+
response.headers(),
46+
allOf(HttpHeaderMatcher.hasHeader(HeaderNames.CACHE_CONTROL,
47+
"no-cache",
48+
"no-store",
49+
"must-revalidate",
50+
"no-transform")));
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)