I'm running into a problem with duplicate slashes and I'm wondering if there is a solution built into Retrofit.
My server provides the base URL we should be using which will look something like this: .setEndpoint(http://some.url.com/)
The server also passes down a path URI that should be appended to that endpoint (with various requests). So my server might send back /channels/videos
.
This gets handed to Retrofit through the following method
@GET("/{uri}")
void GET(@Header("Authorization") String authHeader, @Path(value = "uri", encode = false) String uri,
@Header("Cache-Control") String cacheHeaderValue, Callback<Object> callback);
This is then problematic because the URL that is getting hit with the GET method is http://some.url.com//channels/videos
which will not work correctly in my situation.
I tried manually stripping out the trailing slash from my base endpoint - but I still saw a duplicate slash which I'm assuming resulted from the "/{uri}"
and the /channels/videos
.
I think my problem would be fixed by removing the leading slash in "/{uri}"
but that isn't allowed in Retrofit. And removing the leading slash in the path URI I get back from my server isn't entirely feasible.
throw methodError("URL path \"%s\" must start with '/'.", path);
retrofit.RetrofitError: GET: URL path "{uri}" must start with '/'.
Is there another solution to this problem?
Relevant Links:
Possible duplicate but they describe it a little differently
Jake Wharton saying it should be de-duped in what I think is the situation I'm describing