-
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
base: 3.3.x
Are you sure you want to change the base?
Conversation
|
||
String detail = null; | ||
Message json = deserializeMessage(content); | ||
if (json != null && org.springframework.util.StringUtils.hasText(json.getMessage())) { |
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.
StringUtils
is already imported so there's no need to fully-qualify the type.
|
||
String msg = "Proxy authentication required for host: " + this.host.toHostString() + ", uri: " | ||
+ request.getUri() | ||
+ (org.springframework.util.StringUtils.hasText(detail) ? " - " + detail : ""); |
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.
StringUtils
is already imported so there's no need to fully-qualify the type.
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class ProxyAuthenticationExceptionTests { |
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.
I don't think we need tests for ProxyAuthenticationException
. Please remove this class.
detail = json.getMessage(); | ||
} | ||
else { | ||
detail = new String(content, java.nio.charset.StandardCharsets.UTF_8); |
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.
StandardCharsets
should be imported rather than using the fully-qualified type here.
Also, please sign your commits as described in the DCO check failure. |
response.close(); | ||
|
||
if (statusCode == 407) { | ||
response.close(); |
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 looks wrong to me as the response will now only be closed when the status code is 407.
…ssage (Fixes spring-projects#46262) Signed-off-by: Siva Sai Udayagiri <[email protected]>
7348c31
to
1bd6ffe
Compare
Update: Close response on all error paths before throwing. Use imports (no fully-qualified names). Removed ProxyAuthenticationExceptionTests. Rebased, squashed, DCO signed. |
Those changes sound good, but I can't see them in the PR. Please check that you've pushed them. |
…e FQNs Signed-off-by: Siva Sai Udayagiri <[email protected]>
Pushed the updates: always close error responses, replaced FQNs with imports, removed ProxyAuthenticationExceptionTests. |
/** | ||
* Perform an HTTP GET operation. | ||
* @param uri the destination URI | ||
* @return the operation response | ||
*/ |
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 javadoc should not be removed.
/** | ||
* Perform an HTTP POST operation. | ||
* @param uri the destination URI | ||
* @return the operation response | ||
*/ |
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 javadoc should not be removed.
/** | ||
* Perform an HTTP POST operation. | ||
* @param uri the destination URI | ||
* @param registryAuth registry authentication credentials | ||
* @return the operation response | ||
*/ |
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 javadoc should not be removed.
/** | ||
* Perform an HTTP POST operation. | ||
* @param uri the destination URI | ||
* @param contentType the content type to write | ||
* @param writer a content writer | ||
* @return the operation response | ||
*/ |
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 javadoc should not be removed.
/** | ||
* Perform an HTTP PUT operation. | ||
* @param uri the destination URI | ||
* @param contentType the content type to write | ||
* @param writer a content writer | ||
* @return the operation response | ||
*/ |
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 javadoc should not be removed.
/** | ||
* Perform an HTTP DELETE operation. | ||
* @param uri the destination URI | ||
* @return the operation response | ||
*/ |
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 javadoc should not be removed.
|
||
if (statusCode >= 400 && statusCode <= 500) { | ||
byte[] content = readContent(response); | ||
// Always close the response for error paths |
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 comment is not necessary. Please remove.
+ request.getUri() | ||
+ (StringUtils.hasText(detail) ? " - " + detail : ""); | ||
|
||
throw new ProxyAuthenticationException(msg); |
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.
I'm still not sure that this is needed. Could it be a DockerEngineException
with a better message?
// Always close the response for error paths | ||
response.close(); | ||
|
||
if (statusCode == 407) { |
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.
Use SC_PROXY_AUTHENTICATION_REQUIRED
from org.apache.hc.core5.http.HttpStatus
here rather than 407.
Message json = deserializeMessage(content); | ||
if (json != null && StringUtils.hasText(json.getMessage())) { | ||
detail = json.getMessage(); | ||
} |
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".
Problem
When Docker returns 407 (Proxy Authentication Required), the response is often plain text, so the current code fails to surface a helpful error.
Solution
Tests
Notes
Fixes: #46262