Merge branch '2.3.x'
Closes gh-22304
This commit is contained in:
@@ -50,6 +50,8 @@ import org.springframework.boot.buildpack.platform.system.Environment;
|
||||
*/
|
||||
final class LocalHttpClientTransport extends HttpClientTransport {
|
||||
|
||||
private static final String UNIX_SOCKET_PREFIX = "unix://";
|
||||
|
||||
private static final String DOCKER_HOST = "DOCKER_HOST";
|
||||
|
||||
private static final HttpHost LOCAL_DOCKER_HOST = HttpHost.create("docker://localhost");
|
||||
@@ -60,11 +62,17 @@ final class LocalHttpClientTransport extends HttpClientTransport {
|
||||
|
||||
static LocalHttpClientTransport create(Environment environment) {
|
||||
HttpClientBuilder builder = HttpClients.custom();
|
||||
builder.setConnectionManager(new LocalConnectionManager(environment.get(DOCKER_HOST)));
|
||||
builder.setConnectionManager(new LocalConnectionManager(socketFilePath(environment)));
|
||||
builder.setSchemePortResolver(new LocalSchemePortResolver());
|
||||
return new LocalHttpClientTransport(builder.build());
|
||||
}
|
||||
|
||||
private static String socketFilePath(Environment environment) {
|
||||
String host = environment.get(DOCKER_HOST);
|
||||
return (host != null && host.startsWith(UNIX_SOCKET_PREFIX)) ? host.substring(UNIX_SOCKET_PREFIX.length())
|
||||
: host;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link HttpClientConnectionManager} for local Docker.
|
||||
*/
|
||||
|
||||
@@ -40,6 +40,8 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
final class RemoteHttpClientTransport extends HttpClientTransport {
|
||||
|
||||
private static final String UNIX_SOCKET_PREFIX = "unix://";
|
||||
|
||||
private static final String DOCKER_HOST = "DOCKER_HOST";
|
||||
|
||||
private static final String DOCKER_TLS_VERIFY = "DOCKER_TLS_VERIFY";
|
||||
@@ -63,8 +65,9 @@ final class RemoteHttpClientTransport extends HttpClientTransport {
|
||||
}
|
||||
|
||||
private static boolean isLocalFileReference(String host) {
|
||||
String filePath = host.startsWith(UNIX_SOCKET_PREFIX) ? host.substring(UNIX_SOCKET_PREFIX.length()) : host;
|
||||
try {
|
||||
return Files.exists(Paths.get(host));
|
||||
return Files.exists(Paths.get(filePath));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return false;
|
||||
|
||||
@@ -50,6 +50,15 @@ class HttpTransportTests {
|
||||
assertThat(transport).isInstanceOf(LocalHttpClientTransport.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createWhenDockerHostVariableIsUnixSchemePrefixedFileReturnsLocal(@TempDir Path tempDir) throws IOException {
|
||||
String dummySocketFilePath = "unix://"
|
||||
+ Files.createTempFile(tempDir, "http-transport", null).toAbsolutePath().toString();
|
||||
Map<String, String> environment = Collections.singletonMap("DOCKER_HOST", dummySocketFilePath);
|
||||
HttpTransport transport = HttpTransport.create(environment::get);
|
||||
assertThat(transport).isInstanceOf(LocalHttpClientTransport.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createWhenDoesNotHaveDockerHostVariableReturnsLocal() {
|
||||
HttpTransport transport = HttpTransport.create((name) -> null);
|
||||
|
||||
Reference in New Issue
Block a user