From d7b3f5d98ff786b79583ee08f670dba0cc308344 Mon Sep 17 00:00:00 2001 From: Josef Cacek Date: Fri, 2 Oct 2015 15:00:55 +0200 Subject: [PATCH] [JCLOUDS-1011] force closing HTTP client connection after using Docker build REST API method --- .../org/jclouds/docker/features/MiscApi.java | 4 ++-- .../docker/features/MiscApiMockTest.java | 22 +++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/apis/docker/src/main/java/org/jclouds/docker/features/MiscApi.java b/apis/docker/src/main/java/org/jclouds/docker/features/MiscApi.java index 6c49436632..8e5548ede7 100644 --- a/apis/docker/src/main/java/org/jclouds/docker/features/MiscApi.java +++ b/apis/docker/src/main/java/org/jclouds/docker/features/MiscApi.java @@ -65,7 +65,7 @@ public interface MiscApi { @Named("image:build") @POST @Path("/build") - @Headers(keys = "Content-Type", values = "application/tar") + @Headers(keys = { "Content-Type", "Connection" }, values = { "application/tar", "close" }) InputStream build(Payload inputStream); /** @@ -79,7 +79,7 @@ public interface MiscApi { @Named("image:build") @POST @Path("/build") - @Headers(keys = "Content-Type", values = "application/tar") + @Headers(keys = { "Content-Type", "Connection" }, values = { "application/tar", "close" }) InputStream build(Payload inputStream, BuildOptions options); } diff --git a/apis/docker/src/test/java/org/jclouds/docker/features/MiscApiMockTest.java b/apis/docker/src/test/java/org/jclouds/docker/features/MiscApiMockTest.java index 630d7af3b1..4fe87caac6 100644 --- a/apis/docker/src/test/java/org/jclouds/docker/features/MiscApiMockTest.java +++ b/apis/docker/src/test/java/org/jclouds/docker/features/MiscApiMockTest.java @@ -18,6 +18,8 @@ package org.jclouds.docker.features; import com.squareup.okhttp.mockwebserver.MockResponse; import com.squareup.okhttp.mockwebserver.MockWebServer; +import com.squareup.okhttp.mockwebserver.RecordedRequest; + import org.jclouds.docker.DockerApi; import org.jclouds.docker.internal.BaseDockerMockTest; import org.jclouds.docker.parse.InfoParseTest; @@ -26,11 +28,14 @@ import org.jclouds.io.Payload; import org.jclouds.io.Payloads; import org.testng.annotations.Test; +import static org.assertj.core.api.Assertions.assertThat; import static org.jclouds.docker.compute.BaseDockerApiLiveTest.tarredDockerfile; import static org.testng.Assert.assertEquals; import java.io.File; import java.io.FileInputStream; +import javax.ws.rs.core.HttpHeaders; + /** * Mock tests for the {@link org.jclouds.docker.features.MiscApi} class. */ @@ -64,7 +69,8 @@ public class MiscApiMockTest extends BaseDockerMockTest { MiscApi api = api(DockerApi.class, server.getUrl("/").toString()).getMiscApi(); try { api.build(tarredDockerfile()); - assertSent(server, "POST", "/build"); + RecordedRequest request = assertSent(server, "POST", "/build"); + assertDockerBuildHttpHeaders(request); } finally { server.shutdown(); } @@ -79,10 +85,22 @@ public class MiscApiMockTest extends BaseDockerMockTest { payload.getContentMetadata().setContentLength(file.length()); try { api.build(payload); - assertSent(server, "POST", "/build"); + RecordedRequest request = assertSent(server, "POST", "/build"); + assertDockerBuildHttpHeaders(request); } finally { server.shutdown(); } } + /** + * Asserts that correct values of HTTP headers are used in Docker build REST + * API calls. + * + * @param request + */ + private void assertDockerBuildHttpHeaders(RecordedRequest request) { + assertThat(request.getHeader("Connection")).isEqualTo("close"); + assertThat(request.getHeader(HttpHeaders.CONTENT_TYPE)).isEqualTo("application/tar"); + } + }