Skip to content

Commit

Permalink
Restore setting of no-cache header in health HTTP responses; add test (
Browse files Browse the repository at this point in the history
  • Loading branch information
barchetta and tjquinno authored Feb 10, 2025
1 parent d143290 commit af893e4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,6 +22,7 @@

import io.helidon.health.HealthCheck;
import io.helidon.health.HealthCheckResponse;
import io.helidon.http.HeaderValues;
import io.helidon.http.HtmlEncoder;
import io.helidon.http.Status;
import io.helidon.http.media.EntityWriter;
Expand Down Expand Up @@ -84,6 +85,7 @@ public void handle(ServerRequest req, ServerResponse res) {
};

res.status(responseStatus);
res.header(HeaderValues.CACHE_NO_CACHE);

if (details) {
entityWriter.write(JsonpSupport.JSON_OBJECT_TYPE,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2025 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.helidon.webserver.observe.health;

import io.helidon.common.testing.http.junit5.HttpHeaderMatcher;
import io.helidon.http.HeaderNames;
import io.helidon.webclient.http1.Http1Client;
import io.helidon.webclient.http1.Http1ClientResponse;
import io.helidon.webserver.testing.junit5.ServerTest;

import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;

@ServerTest
class TestNoCacheHeaders {

private final Http1Client client;

TestNoCacheHeaders(Http1Client client) {
this.client = client;
}

@Test
void testNoCacheHeaders() {
try (Http1ClientResponse response = client
.get("/observe/health")
.request()) {

assertThat("No-cache headers",
response.headers(),
allOf(HttpHeaderMatcher.hasHeader(HeaderNames.CACHE_CONTROL,
"no-cache",
"no-store",
"must-revalidate",
"no-transform")));
}
}
}

0 comments on commit af893e4

Please sign in to comment.