Skip to content

Commit 4fab2b6

Browse files
authored
Add HEAD method support to ArtifactoryRequest
1 parent 2c84cb5 commit 4fab2b6

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

api/src/main/java/org/jfrog/artifactory/client/ArtifactoryRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
@JsonIgnoreProperties(ignoreUnknown = true)
1212
public interface ArtifactoryRequest {
1313

14-
enum Method { GET, POST, PUT, DELETE, PATCH, OPTIONS }
14+
enum Method { GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD }
1515

1616
ArtifactoryRequest method(Method method);
1717
ArtifactoryRequest apiUrl(String apiUrl);

services/src/main/groovy/org/jfrog/artifactory/client/impl/ArtifactoryImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ private HttpResponse handleArtifactoryRequest(ArtifactoryRequest artifactoryRequ
196196
httpRequest = new HttpOptions();
197197
break;
198198

199+
case HEAD:
200+
httpRequest = new HttpHead();
201+
break;
202+
199203
default:
200204
throw new IllegalArgumentException("Unsupported request method.");
201205
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=2.20.1
1+
version=2.20.x-SNAPSHOT

services/src/test/java/org/jfrog/artifactory/client/ArtifactoryTests.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@
22

33
import org.apache.http.HttpRequest;
44
import org.apache.http.HttpResponse;
5+
import org.apache.http.client.methods.HttpDelete;
6+
import org.apache.http.client.methods.HttpGet;
7+
import org.apache.http.client.methods.HttpHead;
8+
import org.apache.http.client.methods.HttpOptions;
9+
import org.apache.http.client.methods.HttpPatch;
10+
import org.apache.http.client.methods.HttpPost;
11+
import org.apache.http.client.methods.HttpPut;
12+
import org.apache.http.client.methods.HttpRequestWrapper;
513
import org.apache.http.protocol.HttpContext;
614
import org.apache.http.protocol.HttpProcessor;
715
import org.jfrog.artifactory.client.httpClient.http.ProxyConfig;
816
import org.jfrog.artifactory.client.impl.ArtifactoryRequestImpl;
17+
import org.testng.annotations.DataProvider;
918
import org.testng.annotations.Test;
1019

1120
import java.io.IOException;
@@ -19,6 +28,19 @@
1928
*/
2029
public class ArtifactoryTests {
2130

31+
@DataProvider(name = "httpMethods")
32+
public Object[][] getHttpMethodData() {
33+
return new Object[][]{
34+
{ArtifactoryRequest.Method.GET, HttpGet.class},
35+
{ArtifactoryRequest.Method.POST, HttpPost.class},
36+
{ArtifactoryRequest.Method.PUT, HttpPut.class},
37+
{ArtifactoryRequest.Method.DELETE, HttpDelete.class},
38+
{ArtifactoryRequest.Method.PATCH, HttpPatch.class},
39+
{ArtifactoryRequest.Method.OPTIONS, HttpOptions.class},
40+
{ArtifactoryRequest.Method.HEAD, HttpHead.class},
41+
};
42+
}
43+
2244
@Test
2345
public void urlsTest() throws IOException {
2446
Artifactory artifactory;
@@ -208,4 +230,22 @@ public void process(HttpResponse response, HttpContext context) {
208230
assertEquals(requestInterceptions.intValue(), 0);
209231
assertEquals(responseInterceptions.intValue(), 0);
210232
}
233+
234+
@Test(dataProvider = "httpMethods")
235+
public void httpMethodsTest(ArtifactoryRequest.Method method, Class<?> expectedClass) {
236+
ArtifactoryRequest artifactoryRequest = new ArtifactoryRequestImpl()
237+
.method(method);
238+
239+
ArtifactoryClientBuilder builder = ArtifactoryClientBuilder.create();
240+
builder.setUrl("http://local/");
241+
builder.addInterceptorLast((httpRequest, httpContext) ->
242+
assertEquals(((HttpRequestWrapper) httpRequest).getOriginal().getClass(), expectedClass)
243+
);
244+
245+
try {
246+
builder.build().restCall(artifactoryRequest);
247+
} catch (IOException e) {
248+
// We expect an IOException since http://local/ is not a valid URL, but the interceptor should have been called.
249+
}
250+
}
211251
}

0 commit comments

Comments
 (0)