Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,66 +66,31 @@ protected HttpClientTransport(HttpClient client, HttpHost host) {
this.host = host;
}

/**
* Perform an HTTP GET operation.
* @param uri the destination URI
* @return the operation response
*/
Comment on lines 68 to 72
Copy link
Member

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.

@Override
public Response get(URI uri) {
return execute(new HttpGet(uri));
}

/**
* Perform an HTTP POST operation.
* @param uri the destination URI
* @return the operation response
*/
Comment on lines 78 to 82
Copy link
Member

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.

@Override
public Response post(URI uri) {
return execute(new HttpPost(uri));
}

/**
* Perform an HTTP POST operation.
* @param uri the destination URI
* @param registryAuth registry authentication credentials
* @return the operation response
*/
Comment on lines 88 to 93
Copy link
Member

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.

@Override
public Response post(URI uri, String registryAuth) {
return execute(new HttpPost(uri), registryAuth);
}

/**
* 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
*/
Comment on lines 99 to 105
Copy link
Member

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.

@Override
public Response post(URI uri, String contentType, IOConsumer<OutputStream> writer) {
return execute(new HttpPost(uri), contentType, writer);
}

/**
* 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
*/
Comment on lines 111 to 117
Copy link
Member

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.

@Override
public Response put(URI uri, String contentType, IOConsumer<OutputStream> writer) {
return execute(new HttpPut(uri), contentType, writer);
}

/**
* Perform an HTTP DELETE operation.
* @param uri the destination URI
* @return the operation response
*/
Comment on lines 123 to 127
Copy link
Member

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.

@Override
public Response delete(URI uri) {
return execute(new HttpDelete(uri));
Expand All @@ -146,14 +112,35 @@ 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);
// Always close the response for error paths
Copy link
Member

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.

response.close();

if (statusCode == 407) {
Copy link
Member

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.

String detail = null;
Message json = deserializeMessage(content);
if (json != null && StringUtils.hasText(json.getMessage())) {
detail = json.getMessage();
}
Comment on lines +162 to +165
Copy link
Member

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".

Copy link
Member

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.

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);
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

The 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) {
Expand Down
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);
}

}