Migrate to new HttpHeaders API

See gh-45487

Co-authored-by: Phillip Webb <phil.webb@broadcom.com>
This commit is contained in:
Stéphane Nicoll 2025-05-07 13:09:53 -07:00 committed by Phillip Webb
parent 6fceab2c90
commit 5ea0674bad
17 changed files with 73 additions and 64 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2024 the original author or authors. * Copyright 2012-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,7 +19,9 @@ package org.springframework.boot.actuate.autoconfigure.tracing.zipkin;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
import zipkin2.reporter.BaseHttpSender; import zipkin2.reporter.BaseHttpSender;
@ -27,8 +29,6 @@ import zipkin2.reporter.BytesMessageSender;
import zipkin2.reporter.Encoding; import zipkin2.reporter.Encoding;
import zipkin2.reporter.HttpEndpointSupplier.Factory; import zipkin2.reporter.HttpEndpointSupplier.Factory;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.unit.DataSize; import org.springframework.util.unit.DataSize;
/** /**
@ -61,20 +61,20 @@ abstract class HttpSender extends BaseHttpSender<URI, byte[]> {
@Override @Override
protected void postSpans(URI endpoint, byte[] body) throws IOException { protected void postSpans(URI endpoint, byte[] body) throws IOException {
MultiValueMap<String, String> headers = getDefaultHeaders(); Map<String, String> headers = getDefaultHeaders();
if (needsCompression(body)) { if (needsCompression(body)) {
body = compress(body); body = compress(body);
headers.add("Content-Encoding", "gzip"); headers.put("Content-Encoding", "gzip");
} }
postSpans(endpoint, headers, body); postSpans(endpoint, headers, body);
} }
abstract void postSpans(URI endpoint, MultiValueMap<String, String> headers, byte[] body) throws IOException; abstract void postSpans(URI endpoint, Map<String, String> headers, byte[] body) throws IOException;
MultiValueMap<String, String> getDefaultHeaders() { Map<String, String> getDefaultHeaders() {
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); Map<String, String> headers = new LinkedHashMap<>();
headers.add("b3", "0"); headers.put("b3", "0");
headers.add("Content-Type", this.encoding.mediaType()); headers.put("Content-Type", this.encoding.mediaType());
return headers; return headers;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2024 the original author or authors. * Copyright 2012-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,12 +25,11 @@ import java.net.http.HttpRequest.Builder;
import java.net.http.HttpResponse; import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers; import java.net.http.HttpResponse.BodyHandlers;
import java.time.Duration; import java.time.Duration;
import java.util.Map;
import zipkin2.reporter.Encoding; import zipkin2.reporter.Encoding;
import zipkin2.reporter.HttpEndpointSupplier.Factory; import zipkin2.reporter.HttpEndpointSupplier.Factory;
import org.springframework.util.MultiValueMap;
/** /**
* A {@link HttpSender} which uses the JDK {@link HttpClient} for HTTP communication. * A {@link HttpSender} which uses the JDK {@link HttpClient} for HTTP communication.
* *
@ -50,12 +49,12 @@ class ZipkinHttpClientSender extends HttpSender {
} }
@Override @Override
void postSpans(URI endpoint, MultiValueMap<String, String> headers, byte[] body) throws IOException { void postSpans(URI endpoint, Map<String, String> headers, byte[] body) throws IOException {
Builder request = HttpRequest.newBuilder() Builder request = HttpRequest.newBuilder()
.POST(BodyPublishers.ofByteArray(body)) .POST(BodyPublishers.ofByteArray(body))
.uri(endpoint) .uri(endpoint)
.timeout(this.readTimeout); .timeout(this.readTimeout);
headers.forEach((name, values) -> values.forEach((value) -> request.header(name, value))); headers.forEach((name, value) -> request.header(name, value));
try { try {
HttpResponse<Void> response = this.httpClient.send(request.build(), BodyHandlers.discarding()); HttpResponse<Void> response = this.httpClient.send(request.build(), BodyHandlers.discarding());
if (response.statusCode() / 100 != 2) { if (response.statusCode() / 100 != 2) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2022 the original author or authors. * Copyright 2012-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,11 +19,13 @@ package org.springframework.boot.actuate.web.exchanges.reactive;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.URI; import java.net.URI;
import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.springframework.boot.actuate.web.exchanges.RecordableHttpRequest; import org.springframework.boot.actuate.web.exchanges.RecordableHttpRequest;
import org.springframework.http.HttpHeaders;
import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpRequest;
/** /**
@ -35,7 +37,7 @@ class RecordableServerHttpRequest implements RecordableHttpRequest {
private final String method; private final String method;
private final Map<String, List<String>> headers; private final HttpHeaders headers;
private final URI uri; private final URI uri;
@ -66,7 +68,9 @@ class RecordableServerHttpRequest implements RecordableHttpRequest {
@Override @Override
public Map<String, List<String>> getHeaders() { public Map<String, List<String>> getHeaders() {
return new LinkedHashMap<>(this.headers); Map<String, List<String>> headers = new LinkedHashMap<>();
this.headers.forEach(headers::put);
return Collections.unmodifiableMap(headers);
} }
@Override @Override

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2022 the original author or authors. * Copyright 2012-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,6 +16,7 @@
package org.springframework.boot.actuate.web.exchanges.reactive; package org.springframework.boot.actuate.web.exchanges.reactive;
import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -38,7 +39,9 @@ class RecordableServerHttpResponse implements RecordableHttpResponse {
RecordableServerHttpResponse(ServerHttpResponse response) { RecordableServerHttpResponse(ServerHttpResponse response) {
this.status = (response.getStatusCode() != null) ? response.getStatusCode().value() : HttpStatus.OK.value(); this.status = (response.getStatusCode() != null) ? response.getStatusCode().value() : HttpStatus.OK.value();
this.headers = new LinkedHashMap<>(response.getHeaders()); Map<String, List<String>> headers = new LinkedHashMap<>();
response.getHeaders().forEach(headers::put);
this.headers = Collections.unmodifiableMap(headers);
} }
@Override @Override

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,11 +23,8 @@ import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -47,14 +44,11 @@ import static org.mockito.Mockito.mock;
*/ */
class HttpExchangeTests { class HttpExchangeTests {
private static final Map<String, List<String>> AUTHORIZATION_HEADER = Map.of(HttpHeaders.AUTHORIZATION, private static final HttpHeaders AUTHORIZATION_HEADER = ofSingleHttpHeader(HttpHeaders.AUTHORIZATION, "secret");
Arrays.asList("secret"));
private static final Map<String, List<String>> COOKIE_HEADER = Map.of(HttpHeaders.COOKIE, private static final HttpHeaders COOKIE_HEADER = ofSingleHttpHeader(HttpHeaders.COOKIE, "test=test");
Arrays.asList("test=test"));
private static final Map<String, List<String>> SET_COOKIE_HEADER = Map.of(HttpHeaders.SET_COOKIE, private static final HttpHeaders SET_COOKIE_HEADER = ofSingleHttpHeader(HttpHeaders.SET_COOKIE, "test=test");
Arrays.asList("test=test"));
private static final Supplier<Principal> NO_PRINCIPAL = () -> null; private static final Supplier<Principal> NO_PRINCIPAL = () -> null;
@ -298,31 +292,33 @@ class HttpExchangeTests {
} }
private RecordableHttpRequest createRequest() { private RecordableHttpRequest createRequest() {
return createRequest(Collections.singletonMap(HttpHeaders.ACCEPT, Arrays.asList("application/json"))); return createRequest(ofSingleHttpHeader(HttpHeaders.ACCEPT, "application/json"));
} }
private RecordableHttpRequest createRequest(Map<String, List<String>> headers) { @SuppressWarnings("removal")
private RecordableHttpRequest createRequest(HttpHeaders headers) {
RecordableHttpRequest request = mock(RecordableHttpRequest.class); RecordableHttpRequest request = mock(RecordableHttpRequest.class);
given(request.getMethod()).willReturn("GET"); given(request.getMethod()).willReturn("GET");
given(request.getUri()).willReturn(URI.create("https://api.example.com")); given(request.getUri()).willReturn(URI.create("https://api.example.com"));
given(request.getHeaders()).willReturn(new HashMap<>(headers)); given(request.getHeaders()).willReturn(new HashMap<>(headers.asMultiValueMap()));
given(request.getRemoteAddress()).willReturn("127.0.0.1"); given(request.getRemoteAddress()).willReturn("127.0.0.1");
return request; return request;
} }
private RecordableHttpResponse createResponse() { private RecordableHttpResponse createResponse() {
return createResponse(Collections.singletonMap(HttpHeaders.CONTENT_TYPE, Arrays.asList("application/json"))); return createResponse(ofSingleHttpHeader(HttpHeaders.CONTENT_TYPE, "application/json"));
} }
private RecordableHttpResponse createResponse(Map<String, List<String>> headers) { @SuppressWarnings("removal")
private RecordableHttpResponse createResponse(HttpHeaders headers) {
RecordableHttpResponse response = mock(RecordableHttpResponse.class); RecordableHttpResponse response = mock(RecordableHttpResponse.class);
given(response.getStatus()).willReturn(204); given(response.getStatus()).willReturn(204);
given(response.getHeaders()).willReturn(new HashMap<>(headers)); given(response.getHeaders()).willReturn(new HashMap<>(headers.asMultiValueMap()));
return response; return response;
} }
private Map<String, List<String>> mixedCase(Map<String, List<String>> headers) { private HttpHeaders mixedCase(HttpHeaders headers) {
Map<String, List<String>> result = new LinkedHashMap<>(); HttpHeaders result = new HttpHeaders();
headers.forEach((key, value) -> result.put(mixedCase(key), value)); headers.forEach((key, value) -> result.put(mixedCase(key), value));
return result; return result;
} }
@ -336,4 +332,10 @@ class HttpExchangeTests {
return output.toString(); return output.toString();
} }
private static HttpHeaders ofSingleHttpHeader(String header, String... values) {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.put(header, List.of(values));
return httpHeaders;
}
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2024 the original author or authors. * Copyright 2012-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -45,6 +45,7 @@ import org.springframework.mock.http.client.MockClientHttpResponse;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then; import static org.mockito.BDDMockito.then;
@ -168,7 +169,7 @@ class RestTemplateAutoConfigurationTests {
given(requestFactory.createRequest(any(), any())).willReturn(request); given(requestFactory.createRequest(any(), any())).willReturn(request);
RestTemplate restTemplate = builder.requestFactory(() -> requestFactory).build(); RestTemplate restTemplate = builder.requestFactory(() -> requestFactory).build();
restTemplate.getForEntity("http://localhost:8080/test", String.class); restTemplate.getForEntity("http://localhost:8080/test", String.class);
assertThat(request.getHeaders()).containsEntry("spring", Collections.singletonList("boot")); assertThat(request.getHeaders().headerSet()).contains(entry("spring", Collections.singletonList("boot")));
}); });
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2024 the original author or authors. * Copyright 2012-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -342,7 +342,7 @@ class LiveReloadServerTests {
requestHeaders.forEach((key, value) -> uppercaseRequestHeaders.put(key.toUpperCase(Locale.ROOT), value)); requestHeaders.forEach((key, value) -> uppercaseRequestHeaders.put(key.toUpperCase(Locale.ROOT), value));
requestHeaders.clear(); requestHeaders.clear();
requestHeaders.putAll(uppercaseRequestHeaders); requestHeaders.putAll(uppercaseRequestHeaders);
requestHeaders.putAll(this.headers); this.headers.forEach(requestHeaders::put);
} }
@Override @Override

View File

@ -481,10 +481,10 @@ class TestRestTemplateTests {
ClientHttpRequest request = ReflectionTestUtils.invokeMethod(testRestTemplate.getRestTemplate(), ClientHttpRequest request = ReflectionTestUtils.invokeMethod(testRestTemplate.getRestTemplate(),
"createRequest", URI.create("http://localhost"), HttpMethod.POST); "createRequest", URI.create("http://localhost"), HttpMethod.POST);
if (username == null) { if (username == null) {
assertThat(request.getHeaders()).doesNotContainKey(HttpHeaders.AUTHORIZATION); assertThat(request.getHeaders().headerNames()).doesNotContain(HttpHeaders.AUTHORIZATION);
} }
else { else {
assertThat(request.getHeaders()).containsKeys(HttpHeaders.AUTHORIZATION); assertThat(request.getHeaders().headerNames()).contains(HttpHeaders.AUTHORIZATION);
assertThat(request.getHeaders().get(HttpHeaders.AUTHORIZATION)).containsExactly("Basic " assertThat(request.getHeaders().get(HttpHeaders.AUTHORIZATION)).containsExactly("Basic "
+ Base64.getEncoder().encodeToString(String.format("%s:%s", username, password).getBytes())); + Base64.getEncoder().encodeToString(String.format("%s:%s", username, password).getBytes()));
} }

View File

@ -44,7 +44,7 @@ class BasicAuthentication {
} }
void applyTo(HttpHeaders headers) { void applyTo(HttpHeaders headers) {
if (!headers.containsKey(HttpHeaders.AUTHORIZATION)) { if (!headers.containsHeader(HttpHeaders.AUTHORIZATION)) {
headers.setBasicAuth(this.username, this.password, this.charset); headers.setBasicAuth(this.username, this.password, this.charset);
} }
} }

View File

@ -319,7 +319,7 @@ class RestTemplateBuilderTests {
void basicAuthenticationShouldApply() { void basicAuthenticationShouldApply() {
RestTemplate template = this.builder.basicAuthentication("spring", "boot", StandardCharsets.UTF_8).build(); RestTemplate template = this.builder.basicAuthentication("spring", "boot", StandardCharsets.UTF_8).build();
ClientHttpRequest request = createRequest(template); ClientHttpRequest request = createRequest(template);
assertThat(request.getHeaders()).containsOnlyKeys(HttpHeaders.AUTHORIZATION); assertThat(request.getHeaders().headerNames()).containsOnly(HttpHeaders.AUTHORIZATION);
assertThat(request.getHeaders().get(HttpHeaders.AUTHORIZATION)).containsExactly("Basic c3ByaW5nOmJvb3Q="); assertThat(request.getHeaders().get(HttpHeaders.AUTHORIZATION)).containsExactly("Basic c3ByaW5nOmJvb3Q=");
} }
@ -327,7 +327,7 @@ class RestTemplateBuilderTests {
void defaultHeaderAddsHeader() { void defaultHeaderAddsHeader() {
RestTemplate template = this.builder.defaultHeader("spring", "boot").build(); RestTemplate template = this.builder.defaultHeader("spring", "boot").build();
ClientHttpRequest request = createRequest(template); ClientHttpRequest request = createRequest(template);
assertThat(request.getHeaders()).contains(entry("spring", Collections.singletonList("boot"))); assertThat(request.getHeaders().headerSet()).contains(entry("spring", Collections.singletonList("boot")));
} }
@Test @Test
@ -336,7 +336,7 @@ class RestTemplateBuilderTests {
String[] values = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE }; String[] values = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE };
RestTemplate template = this.builder.defaultHeader(name, values).build(); RestTemplate template = this.builder.defaultHeader(name, values).build();
ClientHttpRequest request = createRequest(template); ClientHttpRequest request = createRequest(template);
assertThat(request.getHeaders()).contains(entry(name, Arrays.asList(values))); assertThat(request.getHeaders().headerSet()).contains(entry(name, Arrays.asList(values)));
} }
@Test // gh-17885 @Test // gh-17885
@ -344,7 +344,7 @@ class RestTemplateBuilderTests {
RestTemplate template = this.builder.defaultHeader("spring", "boot").build(); RestTemplate template = this.builder.defaultHeader("spring", "boot").build();
MockRestServiceServer.bindTo(template).build(); MockRestServiceServer.bindTo(template).build();
ClientHttpRequest request = createRequest(template); ClientHttpRequest request = createRequest(template);
assertThat(request.getHeaders()).contains(entry("spring", Collections.singletonList("boot"))); assertThat(request.getHeaders().headerSet()).contains(entry("spring", Collections.singletonList("boot")));
} }
@Test @Test
@ -361,7 +361,7 @@ class RestTemplateBuilderTests {
.requestCustomizers((request) -> request.getHeaders().add("spring", "framework")) .requestCustomizers((request) -> request.getHeaders().add("spring", "framework"))
.build(); .build();
ClientHttpRequest request = createRequest(template); ClientHttpRequest request = createRequest(template);
assertThat(request.getHeaders()).contains(entry("spring", Collections.singletonList("framework"))); assertThat(request.getHeaders().headerSet()).contains(entry("spring", Collections.singletonList("framework")));
} }
@Test @Test
@ -371,7 +371,7 @@ class RestTemplateBuilderTests {
.additionalRequestCustomizers((request) -> request.getHeaders().add("for", "java")) .additionalRequestCustomizers((request) -> request.getHeaders().add("for", "java"))
.build(); .build();
ClientHttpRequest request = createRequest(template); ClientHttpRequest request = createRequest(template);
assertThat(request.getHeaders()).contains(entry("spring", Collections.singletonList("framework"))) assertThat(request.getHeaders().headerSet()).contains(entry("spring", Collections.singletonList("framework")))
.contains(entry("for", Collections.singletonList("java"))); .contains(entry("for", Collections.singletonList("java")));
} }

View File

@ -662,7 +662,7 @@ public abstract class AbstractReactiveWebServerFactoryTests {
protected void assertResponseIsNotCompressed(ResponseEntity<Void> response) { protected void assertResponseIsNotCompressed(ResponseEntity<Void> response) {
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getHeaders().keySet()).doesNotContain("X-Test-Compressed"); assertThat(response.getHeaders().headerNames()).doesNotContain("X-Test-Compressed");
} }
protected void assertForwardHeaderIsUsed(AbstractReactiveWebServerFactory factory) { protected void assertForwardHeaderIsUsed(AbstractReactiveWebServerFactory factory) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -46,7 +46,7 @@ abstract class AbstractSampleActuatorCustomSecurityTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = restTemplate().getForEntity(getPath() + "/", Map.class); ResponseEntity<Map> entity = restTemplate().getForEntity(getPath() + "/", Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); assertThat(entity.getHeaders().headerNames()).doesNotContain("Set-Cookie");
} }
@Test @Test

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -53,7 +53,7 @@ class ManagementPathSampleActuatorApplicationTests {
void testHomeIsSecure() { void testHomeIsSecure() {
ResponseEntity<Map<String, Object>> entity = asMapEntity(this.restTemplate.getForEntity("/", Map.class)); ResponseEntity<Map<String, Object>> entity = asMapEntity(this.restTemplate.getForEntity("/", Map.class));
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); assertThat(entity.getHeaders().headerNames()).doesNotContain("Set-Cookie");
} }
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2024 the original author or authors. * Copyright 2012-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -57,7 +57,7 @@ class SampleActuatorApplicationTests {
void testHomeIsSecure() { void testHomeIsSecure() {
ResponseEntity<Map<String, Object>> entity = asMapEntity(this.restTemplate.getForEntity("/", Map.class)); ResponseEntity<Map<String, Object>> entity = asMapEntity(this.restTemplate.getForEntity("/", Map.class));
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); assertThat(entity.getHeaders().headerNames()).doesNotContain("Set-Cookie");
} }
@Test @Test

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -61,7 +61,7 @@ class ServletPathSampleActuatorApplicationTests {
void testHomeIsSecure() { void testHomeIsSecure() {
ResponseEntity<Map<String, Object>> entity = asMapEntity(this.restTemplate.getForEntity("/spring/", Map.class)); ResponseEntity<Map<String, Object>> entity = asMapEntity(this.restTemplate.getForEntity("/spring/", Map.class));
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); assertThat(entity.getHeaders().headerNames()).doesNotContain("Set-Cookie");
} }
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2024 the original author or authors. * Copyright 2012-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -54,7 +54,7 @@ class MessageControllerWebTests {
assertThat(this.mvc.post().uri("/").param("text", "FOO text").param("summary", "FOO")) assertThat(this.mvc.post().uri("/").param("text", "FOO text").param("summary", "FOO"))
.hasStatus(HttpStatus.FOUND) .hasStatus(HttpStatus.FOUND)
.headers() .headers()
.hasEntrySatisfying("Location", .hasHeaderSatisfying("Location",
(values) -> assertThat(values).hasSize(1) (values) -> assertThat(values).hasSize(1)
.element(0) .element(0)
.satisfies(HamcrestCondition.matching(RegexMatcher.matches("/[0-9]+")))); .satisfies(HamcrestCondition.matching(RegexMatcher.matches("/[0-9]+"))));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2024 the original author or authors. * Copyright 2012-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -54,7 +54,7 @@ class MessageControllerWebTests {
assertThat(this.mvc.post().uri("/").param("text", "FOO text").param("summary", "FOO")) assertThat(this.mvc.post().uri("/").param("text", "FOO text").param("summary", "FOO"))
.hasStatus(HttpStatus.FOUND) .hasStatus(HttpStatus.FOUND)
.headers() .headers()
.hasEntrySatisfying("Location", .hasHeaderSatisfying("Location",
(values) -> assertThat(values).hasSize(1) (values) -> assertThat(values).hasSize(1)
.element(0) .element(0)
.satisfies(HamcrestCondition.matching(RegexMatcher.matches("/[0-9]+")))); .satisfies(HamcrestCondition.matching(RegexMatcher.matches("/[0-9]+"))));