Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No way to encode forward-slash in path #72

Open
tyrel opened this issue Mar 13, 2017 · 2 comments
Open

No way to encode forward-slash in path #72

tyrel opened this issue Mar 13, 2017 · 2 comments

Comments

@tyrel
Copy link

tyrel commented Mar 13, 2017

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 %.

@cjstehno
Copy link

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.

@glasswalk3r
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants