Skip to content

Jclouds httpresponse API does not include content-length when downloading an artifact #94

@Dhivyaa21

Description

@Dhivyaa21

I am trying to get the content-length header while downloading an artifact from artifactory. I could see all the headers returned in the response object but content-length and content-type. Download artifact request returns all the headers when I use other clients (Postman, java httpclient, chrome browser etc).
Gradle debug log prints all the headers returned by the API but it is not the same in the response headers returned by the httpresponse object
I am not sure if jclouds has a restriction on the number of headers returned via the httpresponse object.

Expected Behavior

jclouds httpresponse object returns all the response headers

Steps to Reproduce (for bugs)

I created a pojo called DownloadContent

@AutoValue
public abstract class DownloadContent {
    @Nullable
    public abstract InputStream inputStream();

    @Nullable
    public abstract Integer contentLength();

    @SerializedNames({"inputStream", "contentLength"})
    public static DownloadContent create(InputStream inputStream, int contentLength) {
        return new AutoValue_DownloadContent(inputStream, contentLength);
    }
}

parser to parse the jclouds httpresponse object returned by the ArtifactAPI

public class InputStreamContentParser implements Function<HttpResponse, DownloadContent> {

    @Override
    public DownloadContent apply(HttpResponse response) {
        int contentLength = 0;
        Map<String, Collection<String>> headers = response.getHeaders().asMap();
        if (response.getHeaders() != null && response.getHeaders().containsKey("content-length")) {
            contentLength = Integer.parseInt(response.getHeaders().get("content-length").toArray()[0].toString());
        }
        try {
            return DownloadContent.create(response.getPayload().openStream(), contentLength);
        } catch (IOException e) {
            throw new RuntimeException(e.getMessage());
        }
    }
}

Then I add this parser to the download API

@Named("artifact:download")
    @Path("/{repoKey}/{itemPath}")
    @Fallback(Fallbacks.NullOnNotFoundOr404.class)
    @Consumes(MediaType.WILDCARD)
    @ResponseParser(InputStreamContentParser.class)
    @GET
    DownloadContent downloadArtifact(@PathParam("repoKey") String sourceRepo, @PathParam("itemPath") String sourcePath,
                                     @QueryParam("skipUpdateStats") boolean skipUpdateStats);

I ran a live test on my local instance of artifactory. The following are the jclouds log returned by gradle for download request

11:03:03.807 [Test worker] DEBUG org.jclouds.rest.internal.InvokeHttpMethod - >> invoking artifact:download
    11:03:03.807 [Test worker] DEBUG org.jclouds.http.internal.JavaUrlHttpCommandExecutorService - Sending request 1440517688: GET https://localhost:8080/my-repo/com/me/test/a-headers-test/e1616cd40fa6459c891a5795ca0d36c6.txt?skipUpdateStats=false HTTP/1.1
    11:03:03.807 [Test worker] DEBUG jclouds.headers - >> GET https://localhost:8080/my-repo/com/me/test/a-headers-test/e1616cd40fa6459c891a5795ca0d36c6.txt?skipUpdateStats=false HTTP/1.1
    11:03:03.807 [Test worker] DEBUG jclouds.headers - >> Accept: */*
    11:03:03.808 [Test worker] DEBUG jclouds.headers - >> X-JFrog-Art-Api: 
    11:03:03.829 [Test worker] DEBUG org.jclouds.http.internal.JavaUrlHttpCommandExecutorService - Receiving response 1440517688: HTTP/1.1 200 null
    11:03:03.829 [Test worker] DEBUG jclouds.headers - << HTTP/1.1 200 null
    11:03:03.829 [Test worker] DEBUG jclouds.headers - << Keep-Alive: timeout=75
    11:03:03.829 [Test worker] DEBUG jclouds.headers - << Server: openresty
    11:03:03.829 [Test worker] DEBUG jclouds.headers - << X-Checksum-Sha1: 60fde9c2310b0d4cad6b04387efba289
    11:03:03.830 [Test worker] DEBUG jclouds.headers - << Connection: keep-alive
    11:03:03.830 [Test worker] DEBUG jclouds.headers - << X-Checksum-Md5: bea825213cdf007273
    11:03:03.830 [Test worker] DEBUG jclouds.headers - << Last-Modified: Fri, 15 Jul 2022 15:03:03 GMT
    11:03:03.830 [Test worker] DEBUG jclouds.headers - << X-Artifactory-Filename: e1616cd40fa6459c891a5795ca0d36c6.txt
    11:03:03.830 [Test worker] DEBUG jclouds.headers - << Date: Fri, 15 Jul 2022 15:03:03 GMT
    11:03:03.830 [Test worker] DEBUG jclouds.headers - << Accept-Ranges: bytes
    11:03:03.830 [Test worker] DEBUG jclouds.headers - << Strict-Transport-Security: max-age=15552000; includeSubDomains
    11:03:03.830 [Test worker] DEBUG jclouds.headers - << X-Artifactory-Id: 30837e0cf288e:-3036:1819f759141:-8000
    11:03:03.830 [Test worker] DEBUG jclouds.headers - << X-JFrog-Version: Artifactory/7.38.10 73810900
    11:03:03.830 [Test worker] DEBUG jclouds.headers - << X-Cache-Status: MISS
    11:03:03.830 [Test worker] DEBUG jclouds.headers - << X-Checksum-Sha256: c98c24b677eff44860afea6bb209c6fc2bbb47f66ff2ad31
    11:03:03.830 [Test worker] DEBUG jclouds.headers - << ETag: 60fde9c2310b0d4cad4dab8d126b04387efba289
    11:03:03.830 [Test worker] DEBUG jclouds.headers - << Content-Type: text/plain
    11:03:03.830 [Test worker] DEBUG jclouds.headers - << Content-Length: 14
    11:03:03.830 [Test worker] DEBUG jclouds.wire - << "Hello, World![\n]"

The headers returned by the jclouds httpresponse object in InputStreamContentParser are as follows

Keep-Alive:[timeout=75]
    Server:[openresty]
    X-Checksum-Sha1:[60fde9c2310b0d4cad6b04387efba289]
    Connection:[keep-alive]
    X-Checksum-Md5:[bea825213cdf007273]
    Last-Modified:[Fri, 15 Jul 2022 15:03:03 GMT]
    X-Artifactory-Filename:[e1616cd40fa6459c891a5795ca0d36c6.txt]
    Date:[Fri, 15 Jul 2022 15:03:03 GMT]
    Accept-Ranges:[bytes]
    Strict-Transport-Security:[max-age=15552000; includeSubDomains]
    X-Artifactory-Id:[30837e0cf288e:-3036:1819f759141:-8000]
    X-JFrog-Version:[Artifactory/7.38.10 73810900]
    X-Cache-Status:[MISS]
    X-Checksum-Sha256:[c98c24b677eff44860afea6bb209c6fc2bbb47f66ff2ad31]
    ETag:[60fde9c2310b0d4cad4dab8d126b04387efba289]

The number of headers is always 15.

Your Environment

Artifactory-Version: Artifactory/7.38.10 73810900

Any help on this issue is much appreciated! Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions