diff --git a/api/src/main/java/org/jfrog/artifactory/client/ArtifactoryRequest.java b/api/src/main/java/org/jfrog/artifactory/client/ArtifactoryRequest.java index 46670945..b3812b32 100644 --- a/api/src/main/java/org/jfrog/artifactory/client/ArtifactoryRequest.java +++ b/api/src/main/java/org/jfrog/artifactory/client/ArtifactoryRequest.java @@ -11,7 +11,7 @@ @JsonIgnoreProperties(ignoreUnknown = true) public interface ArtifactoryRequest { - enum Method { GET, POST, PUT, DELETE, PATCH, OPTIONS } + enum Method { GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD } ArtifactoryRequest method(Method method); ArtifactoryRequest apiUrl(String apiUrl); diff --git a/services/src/main/groovy/org/jfrog/artifactory/client/impl/ArtifactoryImpl.java b/services/src/main/groovy/org/jfrog/artifactory/client/impl/ArtifactoryImpl.java index ae159a2c..61cd3c40 100644 --- a/services/src/main/groovy/org/jfrog/artifactory/client/impl/ArtifactoryImpl.java +++ b/services/src/main/groovy/org/jfrog/artifactory/client/impl/ArtifactoryImpl.java @@ -196,6 +196,10 @@ private HttpResponse handleArtifactoryRequest(ArtifactoryRequest artifactoryRequ httpRequest = new HttpOptions(); break; + case HEAD: + httpRequest = new HttpHead(); + break; + default: throw new IllegalArgumentException("Unsupported request method."); } diff --git a/services/src/main/resources/artifactory.client.release.properties b/services/src/main/resources/artifactory.client.release.properties index 32b38dd8..1be8db75 100644 --- a/services/src/main/resources/artifactory.client.release.properties +++ b/services/src/main/resources/artifactory.client.release.properties @@ -1 +1 @@ -version=2.20.1 \ No newline at end of file +version=2.20.x-SNAPSHOT \ No newline at end of file diff --git a/services/src/test/java/org/jfrog/artifactory/client/ArtifactoryTests.java b/services/src/test/java/org/jfrog/artifactory/client/ArtifactoryTests.java index a3481822..3851f7bc 100644 --- a/services/src/test/java/org/jfrog/artifactory/client/ArtifactoryTests.java +++ b/services/src/test/java/org/jfrog/artifactory/client/ArtifactoryTests.java @@ -2,10 +2,19 @@ import org.apache.http.HttpRequest; import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpHead; +import org.apache.http.client.methods.HttpOptions; +import org.apache.http.client.methods.HttpPatch; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.client.methods.HttpRequestWrapper; import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpProcessor; import org.jfrog.artifactory.client.httpClient.http.ProxyConfig; import org.jfrog.artifactory.client.impl.ArtifactoryRequestImpl; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import java.io.IOException; @@ -19,6 +28,19 @@ */ public class ArtifactoryTests { + @DataProvider(name = "httpMethods") + public Object[][] getHttpMethodData() { + return new Object[][]{ + {ArtifactoryRequest.Method.GET, HttpGet.class}, + {ArtifactoryRequest.Method.POST, HttpPost.class}, + {ArtifactoryRequest.Method.PUT, HttpPut.class}, + {ArtifactoryRequest.Method.DELETE, HttpDelete.class}, + {ArtifactoryRequest.Method.PATCH, HttpPatch.class}, + {ArtifactoryRequest.Method.OPTIONS, HttpOptions.class}, + {ArtifactoryRequest.Method.HEAD, HttpHead.class}, + }; + } + @Test public void urlsTest() throws IOException { Artifactory artifactory; @@ -208,4 +230,22 @@ public void process(HttpResponse response, HttpContext context) { assertEquals(requestInterceptions.intValue(), 0); assertEquals(responseInterceptions.intValue(), 0); } + + @Test(dataProvider = "httpMethods") + public void httpMethodsTest(ArtifactoryRequest.Method method, Class expectedClass) { + ArtifactoryRequest artifactoryRequest = new ArtifactoryRequestImpl() + .method(method); + + ArtifactoryClientBuilder builder = ArtifactoryClientBuilder.create(); + builder.setUrl("http://local/"); + builder.addInterceptorLast((httpRequest, httpContext) -> + assertEquals(((HttpRequestWrapper) httpRequest).getOriginal().getClass(), expectedClass) + ); + + try { + builder.build().restCall(artifactoryRequest); + } catch (IOException e) { + // We expect an IOException since http://local/ is not a valid URL, but the interceptor should have been called. + } + } }