Skip to content

Commit 5aa841d

Browse files
siva-sai-udaygiriphilwebb
authored andcommitted
Handle HTTP 407 with clear error message
Refine error handling logic so that HTTP 407 (Proxy Authentication Required) responses from the Docker daemon are treated as plain text rather than JSON. See gh-47180 Signed-off-by: Siva Sai Udayagiri <[email protected]>
1 parent cf7e30f commit 5aa841d

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.OutputStream;
2323
import java.net.URI;
2424
import java.net.URISyntaxException;
25+
import java.nio.charset.StandardCharsets;
2526

2627
import org.apache.hc.client5.http.classic.HttpClient;
2728
import org.apache.hc.client5.http.classic.methods.HttpDelete;
@@ -36,6 +37,7 @@
3637
import org.apache.hc.core5.http.HttpEntity;
3738
import org.apache.hc.core5.http.HttpHost;
3839
import org.apache.hc.core5.http.HttpRequest;
40+
import org.apache.hc.core5.http.HttpStatus;
3941
import org.apache.hc.core5.http.io.entity.AbstractHttpEntity;
4042

4143
import org.springframework.boot.buildpack.platform.io.Content;
@@ -160,14 +162,27 @@ private Response execute(HttpUriRequest request) {
160162
beforeExecute(request);
161163
ClassicHttpResponse response = this.client.executeOpen(this.host, request, null);
162164
int statusCode = response.getCode();
165+
163166
if (statusCode >= 400 && statusCode <= 500) {
164167
byte[] content = readContent(response);
165168
response.close();
169+
170+
if (statusCode == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) {
171+
String detail = (content != null && content.length > 0)
172+
? new String(content, StandardCharsets.UTF_8) : null;
173+
174+
String msg = "Proxy authentication required for host: " + this.host.toHostString() + ", uri: "
175+
+ request.getUri() + (StringUtils.hasText(detail) ? " - " + detail : "");
176+
177+
throw new ProxyAuthenticationException(msg);
178+
}
179+
166180
Errors errors = (statusCode != 500) ? deserializeErrors(content) : null;
167181
Message message = deserializeMessage(content);
168182
throw new DockerEngineException(this.host.toHostString(), request.getUri(), statusCode,
169183
response.getReasonPhrase(), errors, message);
170184
}
185+
171186
return new HttpClientResponse(response);
172187
}
173188
catch (IOException | URISyntaxException ex) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2012-2025 the original author or authors.
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+
* https://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+
17+
package org.springframework.boot.buildpack.platform.docker.transport;
18+
19+
public class ProxyAuthenticationException extends RuntimeException {
20+
21+
public ProxyAuthenticationException(String message) {
22+
super(message);
23+
}
24+
25+
public ProxyAuthenticationException(String message, Throwable cause) {
26+
super(message, cause);
27+
}
28+
29+
}

0 commit comments

Comments
 (0)