httpbuilder icon indicating copy to clipboard operation
httpbuilder copied to clipboard

No way to encode forward-slash in path

Open tyrel opened this issue 8 years ago • 2 comments

I cannot find a way to encode a forward-slash (/) into a path in HTTPBuilder (as %2F).

Example:

def http = new HTTPBuilder('https://gitlab.com/api/v3/')
http.setHeaders ['PRIVATE-TOKEN': API_TOKEN]
http.get(path: 'projects/group-name%2Fproject-name') { resp, json ->
   // ...
}

I need to have %2F encoded in order to identify the project in the GitLab API. According to their API documentation:

If using namespaced projects call make sure that the NAMESPACE/PROJECT_NAME is URL-encoded, eg. /api/v3/projects/diaspora%2Fdiaspora (where / is represented by %2F).

However, if I make this call, the underlying code in HTTPBuilder calls a constructor of java.net.URI which escapes the % causing it to be %%2F, which then returns a 404 Not Found from the server. Similarly I can't just put /, because that also returns a 404 Not Found. I must send just %2F.

I can't find a way to pass the path so that URI doesn't escape the %.

tyrel avatar Mar 13 '17 21:03 tyrel

Consider taking a look at HttpBuilder-NG - it was originally a fork of this project and it is modernized and actively developed.

We support encoded slashes in the URL.

cjstehno avatar Nov 30 '17 21:11 cjstehno

This works:

def uri = new URIBuilder(
        new URI( restClient.uri.toString() + '/api/vhosts/%2Fmy-card' )
)
restClient.get(uri: uri) { response, json ->
       assertEquals('The vhost has the expected name', '/my-card', json['name'])
}

Assuming that restClient is a instance of groovyx.net.http.RESTClient.

But probably using HttpBuilder-NG is a better long term option.

glasswalk3r avatar Apr 12 '18 21:04 glasswalk3r