Skip to content

Commit 97ed923

Browse files
committed
Explicitly set Host header when using LocalHttpClientTransport
Closes gh-45028
1 parent 257ce0a commit 97ed923

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/HttpClientTransport.java

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.hc.core5.http.Header;
3636
import org.apache.hc.core5.http.HttpEntity;
3737
import org.apache.hc.core5.http.HttpHost;
38+
import org.apache.hc.core5.http.HttpRequest;
3839
import org.apache.hc.core5.http.io.entity.AbstractHttpEntity;
3940

4041
import org.springframework.boot.buildpack.platform.io.Content;
@@ -156,6 +157,7 @@ private Response execute(HttpUriRequestBase request, String registryAuth) {
156157

157158
private Response execute(HttpUriRequest request) {
158159
try {
160+
beforeExecute(request);
159161
ClassicHttpResponse response = this.client.executeOpen(this.host, request, null);
160162
int statusCode = response.getCode();
161163
if (statusCode >= 400 && statusCode <= 500) {
@@ -173,6 +175,9 @@ private Response execute(HttpUriRequest request) {
173175
}
174176
}
175177

178+
protected void beforeExecute(HttpRequest request) {
179+
}
180+
176181
private byte[] readContent(ClassicHttpResponse response) throws IOException {
177182
HttpEntity entity = response.getEntity();
178183
if (entity == null) {

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/LocalHttpClientTransport.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
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.
@@ -35,6 +35,7 @@
3535
import org.apache.hc.client5.http.routing.HttpRoutePlanner;
3636
import org.apache.hc.client5.http.ssl.TlsSocketStrategy;
3737
import org.apache.hc.core5.http.HttpHost;
38+
import org.apache.hc.core5.http.HttpRequest;
3839
import org.apache.hc.core5.http.config.Lookup;
3940
import org.apache.hc.core5.http.protocol.HttpContext;
4041
import org.apache.hc.core5.util.TimeValue;
@@ -62,6 +63,11 @@ private LocalHttpClientTransport(HttpClient client, HttpHost host) {
6263
super(client, host);
6364
}
6465

66+
@Override
67+
protected void beforeExecute(HttpRequest request) {
68+
request.setHeader("Host", LOCAL_DOCKER_HOST.toHostString());
69+
}
70+
6571
static LocalHttpClientTransport create(ResolvedDockerHost dockerHost) {
6672
HttpClientBuilder builder = HttpClients.custom()
6773
.setConnectionManager(new LocalConnectionManager(dockerHost))

0 commit comments

Comments
 (0)