gitlab4j-api icon indicating copy to clipboard operation
gitlab4j-api copied to clipboard

MediaType.WILDCARD to replace MediaType.MEDIA_TYPE_WILDCARD to fix 406 error

Open wlbaker opened this issue 4 years ago • 0 comments

In the file package org.gitlab4j.api.RepositoryFileApi, lines 423 to 435 contain references to MediaType.MEDIA_TYPE_WILDCARD which is a simple "*":

    public InputStream getRawFile(Object projectIdOrPath, String ref, String filepath) throws GitLabApiException {

	Form formData = new GitLabApiForm().withParam("ref", (ref != null ? ref : null), true);
        if (isApiVersion(ApiVersion.V3)) {
            Response response = getWithAccepts(Response.Status.OK, formData.asMap(), MediaType.MEDIA_TYPE_WILDCARD,
                "projects", getProjectIdOrPath(projectIdOrPath), "repository", "blobs", ref);
            return (response.readEntity(InputStream.class));
        } else {
            Response response = getWithAccepts(Response.Status.OK, formData.asMap(),  MediaType.MEDIA_TYPE_WILDCARD,
                "projects", getProjectIdOrPath(projectIdOrPath), "repository", "files", urlEncode(filepath), "raw");
            return (response.readEntity(InputStream.class));
        }
    }

This fails with a 406 on my version of GITLAB (V4/GitLab Enterprise Edition 13.6.5-ee). The problem is that the expected wildcard is "/". Replacing MediaType.MEDIA_TYPE_WILDCARD with MediaType.WILDCARD fixes this error. In my case, I am using the ApiVersion.V4 and have no way of testing other versions of GITLAB.

wlbaker avatar Jul 08 '21 03:07 wlbaker