enonic / lib-http-client

Http Client Library for Enonic XP.
Apache License 2.0
0 stars 4 forks source link

Error when request url contains spaces #115

Closed Roeland-Bouvet closed 2 years ago

Roeland-Bouvet commented 2 years ago

Hi, the request function currently throws a "java.lang.IllegalArgumentException: Illegal character in path at..." error when the url parameter contains a space. Ideally people shouldn't be using spaces in urls when making requests, but there can be cases where this could happen. So perhaps the http-client lib should try to url-encode before making the request?

sigdestad commented 2 years ago

I assume it is safer that the caller does this encoding?

rymsha commented 2 years ago

You can use encodeURI , if you are concerned about spaces.

http.request({
        url: encodeURI('http://example.com/my/url/?= ')
})

Doing it in the library itself is unsafe.

Roeland-Bouvet commented 2 years ago

Ok. Out of curiosity though, is it possible in versions 2.x.x the library was in fact doing url-encoding? With okhttp3.HttpUrl.parse ?

rymsha commented 2 years ago

The backend has been changed from okhttp3 to native HttpClient in version 3.0.0 Native HttpClient accepts only valid URI.