|
22 | 22 | import java.io.OutputStream; |
23 | 23 | import java.net.URI; |
24 | 24 | import java.net.URISyntaxException; |
| 25 | +import java.nio.charset.StandardCharsets; |
25 | 26 |
|
26 | 27 | import org.apache.hc.client5.http.classic.HttpClient; |
27 | 28 | import org.apache.hc.client5.http.classic.methods.HttpDelete; |
|
36 | 37 | import org.apache.hc.core5.http.HttpEntity; |
37 | 38 | import org.apache.hc.core5.http.HttpHost; |
38 | 39 | import org.apache.hc.core5.http.HttpRequest; |
| 40 | +import org.apache.hc.core5.http.HttpStatus; |
39 | 41 | import org.apache.hc.core5.http.io.entity.AbstractHttpEntity; |
40 | 42 |
|
41 | 43 | import org.springframework.boot.buildpack.platform.io.Content; |
@@ -160,14 +162,27 @@ private Response execute(HttpUriRequest request) { |
160 | 162 | beforeExecute(request); |
161 | 163 | ClassicHttpResponse response = this.client.executeOpen(this.host, request, null); |
162 | 164 | int statusCode = response.getCode(); |
| 165 | + |
163 | 166 | if (statusCode >= 400 && statusCode <= 500) { |
164 | 167 | byte[] content = readContent(response); |
165 | 168 | 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 | + |
166 | 180 | Errors errors = (statusCode != 500) ? deserializeErrors(content) : null; |
167 | 181 | Message message = deserializeMessage(content); |
168 | 182 | throw new DockerEngineException(this.host.toHostString(), request.getUri(), statusCode, |
169 | 183 | response.getReasonPhrase(), errors, message); |
170 | 184 | } |
| 185 | + |
171 | 186 | return new HttpClientResponse(response); |
172 | 187 | } |
173 | 188 | catch (IOException | URISyntaxException ex) { |
|
0 commit comments