Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2.20.1
version=2.20.x-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.
}
}
}