-
Notifications
You must be signed in to change notification settings - Fork 41.5k
Handle Docker 407 (Proxy Authentication Required) with clear error message #47180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
siva-sai-udaygiri
wants to merge
3
commits into
spring-projects:3.3.x
Choose a base branch
from
siva-sai-udaygiri:3.3.x
base: 3.3.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+54
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
1bd6ffe
Handle Docker 407 (Proxy Authentication Required) with clear error me…
siva-sai-udaygiri dea1f3c
Handle Docker 407: always close response on error; use imports; remov…
siva-sai-udaygiri b31f951
Handle Docker 407: always close error responses; use HttpStatus const…
siva-sai-udaygiri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
import java.io.OutputStream; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import org.apache.hc.client5.http.classic.HttpClient; | ||
import org.apache.hc.client5.http.classic.methods.HttpDelete; | ||
|
@@ -33,6 +34,7 @@ | |
import org.apache.hc.core5.http.ClassicHttpResponse; | ||
import org.apache.hc.core5.http.HttpEntity; | ||
import org.apache.hc.core5.http.HttpHost; | ||
import org.apache.hc.core5.http.HttpStatus; | ||
import org.apache.hc.core5.http.io.entity.AbstractHttpEntity; | ||
|
||
import org.springframework.boot.buildpack.platform.io.Content; | ||
|
@@ -146,14 +148,37 @@ private Response execute(HttpUriRequest request) { | |
try { | ||
ClassicHttpResponse response = this.client.executeOpen(this.host, request, null); | ||
int statusCode = response.getCode(); | ||
|
||
if (statusCode >= 400 && statusCode <= 500) { | ||
byte[] content = readContent(response); | ||
response.close(); | ||
|
||
if (statusCode == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) { | ||
String detail = null; | ||
|
||
// Some Docker endpoints may still send a JSON body; prefer it if | ||
// present, | ||
// otherwise fall back to plain text. | ||
Message json = deserializeMessage(content); | ||
if (json != null && StringUtils.hasText(json.getMessage())) { | ||
detail = json.getMessage(); | ||
} | ||
else if (content != null && content.length > 0) { | ||
detail = new String(content, StandardCharsets.UTF_8); | ||
} | ||
|
||
String msg = "Proxy authentication required for host: " + this.host.toHostString() + ", uri: " | ||
+ request.getUri() + (StringUtils.hasText(detail) ? " - " + detail : ""); | ||
|
||
throw new ProxyAuthenticationException(msg); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm still not sure that this is needed. Could it be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please address this comment. |
||
} | ||
|
||
Errors errors = (statusCode != 500) ? deserializeErrors(content) : null; | ||
Message message = deserializeMessage(content); | ||
throw new DockerEngineException(this.host.toHostString(), request.getUri(), statusCode, | ||
response.getReasonPhrase(), errors, message); | ||
} | ||
|
||
return new HttpClientResponse(response); | ||
} | ||
catch (IOException | URISyntaxException ex) { | ||
|
29 changes: 29 additions & 0 deletions
29
...pringframework/boot/buildpack/platform/docker/transport/ProxyAuthenticationException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.buildpack.platform.docker.transport; | ||
|
||
public class ProxyAuthenticationException extends RuntimeException { | ||
|
||
public ProxyAuthenticationException(String message) { | ||
super(message); | ||
} | ||
|
||
public ProxyAuthenticationException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you handling JSON here? The issue states that the error has "a plain text message".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still doesn't look right to me, I'm afraid. Why would a JSON
Message
be sent back in an error case? If you have evidence of that, please do share it. Otherwise, I think this should just deal with plain text.