From 97ed923e504beedb8af6b75a34cea340528f1071 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Tue, 8 Apr 2025 14:29:16 +0200 Subject: [PATCH] Explicitly set Host header when using LocalHttpClientTransport Closes gh-45028 --- .../platform/docker/transport/HttpClientTransport.java | 5 +++++ .../docker/transport/LocalHttpClientTransport.java | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/HttpClientTransport.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/HttpClientTransport.java index 28eaf45715b..373b69edf79 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/HttpClientTransport.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/HttpClientTransport.java @@ -35,6 +35,7 @@ import org.apache.hc.core5.http.ClassicHttpResponse; import org.apache.hc.core5.http.Header; import org.apache.hc.core5.http.HttpEntity; import org.apache.hc.core5.http.HttpHost; +import org.apache.hc.core5.http.HttpRequest; import org.apache.hc.core5.http.io.entity.AbstractHttpEntity; import org.springframework.boot.buildpack.platform.io.Content; @@ -156,6 +157,7 @@ abstract class HttpClientTransport implements HttpTransport { private Response execute(HttpUriRequest request) { try { + beforeExecute(request); ClassicHttpResponse response = this.client.executeOpen(this.host, request, null); int statusCode = response.getCode(); if (statusCode >= 400 && statusCode <= 500) { @@ -173,6 +175,9 @@ abstract class HttpClientTransport implements HttpTransport { } } + protected void beforeExecute(HttpRequest request) { + } + private byte[] readContent(ClassicHttpResponse response) throws IOException { HttpEntity entity = response.getEntity(); if (entity == null) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/LocalHttpClientTransport.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/LocalHttpClientTransport.java index 7f99a339043..ec2b0c41e86 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/LocalHttpClientTransport.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/LocalHttpClientTransport.java @@ -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"); * you may not use this file except in compliance with the License. @@ -35,6 +35,7 @@ import org.apache.hc.client5.http.io.HttpClientConnectionManager; import org.apache.hc.client5.http.routing.HttpRoutePlanner; import org.apache.hc.client5.http.ssl.TlsSocketStrategy; import org.apache.hc.core5.http.HttpHost; +import org.apache.hc.core5.http.HttpRequest; import org.apache.hc.core5.http.config.Lookup; import org.apache.hc.core5.http.protocol.HttpContext; import org.apache.hc.core5.util.TimeValue; @@ -62,6 +63,11 @@ final class LocalHttpClientTransport extends HttpClientTransport { super(client, host); } + @Override + protected void beforeExecute(HttpRequest request) { + request.setHeader("Host", LOCAL_DOCKER_HOST.toHostString()); + } + static LocalHttpClientTransport create(ResolvedDockerHost dockerHost) { HttpClientBuilder builder = HttpClients.custom() .setConnectionManager(new LocalConnectionManager(dockerHost))