-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
Support for arbitrary url schemes? #2576
Comments
P.S.: I'm talking about this one:
|
Unfortunately the URL standard gets pretty awkward if you need to support schemes like mailto: and isbn: and file:. Not supporting the other schemes means the API can be simpler for HTTP. There's a simple workaround. Just manually do string replacement to force it to be a HTTP URL. One problem you might face with using HTTP over UNIX sockets is that the socket factory isn't provided the file path. Though maybe that's a constant anyway. |
@swankjesse thanks for the quick reply. I don't fully understand your proposed workaround. Do you mean I should use something like the following: The linked docker-client library internally uses the plain JDK api (HTTPUrlConnection stuff) along with its built in hooks to provide protocol handlers for It's ok for me to handle the special unix/npipe/SocketFactory stuff on my own, I simply ask for a more flexible handling of request URLs. Would it be possible to make the static |
@swankjesse @gesellix I am also trying to do the same thing for my rx-docker-client. I have to support unix socket using okhttp but unable to figure out how to make it work. I created by custom socket factory using the |
@shekhargulati I’m unsure. Can you provide a test case? |
@swankjesse I tried to use the encoded unix socket filename as hostname. Now I'm a bit lost thinking about a good layer where to hook into. A custom This is my test case:
... yielding that error:
Where would you suggest me to customise the client? I see several options like |
see square#2576 for details
Ah, sorry to bother yourself... I tried it with Now I'm where you probably have already seen the actual problem:
Yes, the information is lost. I assume it's a no-go to pass the path down into |
In case someone is interested in the WIP, it can be found there https://github.com/gesellix/okhttp/blob/master/samples/simple-client/src/main/java/okhttp3/sample/OkDocker.java |
Here’s a class that might help: Use it like this:
You’ll still need to figure out what else goes inside the |
well, that's nice, thanks! |
@swankjesse I decided to encode the hostname - as suggested. Thanks for the hint to also hook into the Dns lookups. Your example worked great and I don't even need any change in OkHttp :-) I guess I'm now able to continue by myself, so I'm closing this issue. Thanks to the whole team for that great library! |
Great. Also you might find Okio’s ByteString to be a little more natural to go between hex and utf8:
|
done - looks like I need to browse even more of your api... |
I'm trying to use OkHttp to connect to the Docker remote api. Since they support several ways of connecting to their daemon, including unix sockets, they use several url schemes. They still use HTTP, though, but connect via TCP, Unix Domain Sockets or even Names Pipes.
When trying to use a url like
unix:///var/run/docker.sock
, OkHttp refuses to use that url, because it enforces us to use eitherhttp
orhttps
.I know that OkHttp wasn't supposed to handle such hacky ways of connecting via Unix Sockets, which is why I won't ask for a solution directly in OkHttp itself. My concern is more about the strict parser to only accept http(s). Would you be willing to add an option to the url parser to accept arbitrary schemes? I guess it would even be enough to support some kind of overrides. For me it would be enough to tell OkHttp that I know what I'm doing.
For the bigger picture: given the url parser to accept arbitrary schemes, I still need to provide my own SocketFactory (to connect via unix or npipe). I assume that's possible? Essentially I only want to use OkHttp to leverage the HTTP stuff, but also be able to connect via different transport mechanisms. If you now tell me that I'm crazy and that you don't want OkHttp to also go crazy, please do so :-)
If you think opening OkHttp to support different connection strategies is a good thing, I'd be happy to provide pull requests, with the first one obviously making the url parser less strict.
The text was updated successfully, but these errors were encountered: