question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for arbitrary url schemes?

See original GitHub issue

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 either http or https.

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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
swankjessecommented, May 28, 2016

Here’s a class that might help: https://gist.github.com/swankjesse/7ffbc7f7ec9d6fc9deb026d8726eae84

Use it like this:

    UnixSocketFactory socketFactory = new UnixSocketFactory();

    OkHttpClient client = new OkHttpClient.Builder()
        .socketFactory(socketFactory)
        .dns(socketFactory)
        .build();

    HttpUrl url = socketFactory.urlForPath("/var/run/docker.sock");
    Call call = client.newCall(new Request.Builder()
        .url(url)
        .build());
    Response response = call.execute();

You’ll still need to figure out what else goes inside the connect() method. All this does is retrieve the path through a backchannel.

0reactions
gesellixcommented, May 28, 2016

done - looks like I need to browse even more of your api…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Allow arbitrary URLs, expect arbitrary code execution
Applications that let users open external URLs should validate the URLs with a URI scheme allowlist; Applications that register themselves as a ...
Read more >
Defining a custom URL scheme for your app - Apple Developer
Custom URL schemes provide a way to reference resources inside your app. Users tapping a custom URL in an email, for example, launch...
Read more >
iOS Custom URI Handlers / Deeplinks / Custom Schemes
Custom URL schemes allow apps to communicate via a custom protocol. An app must declare support for the schemes and handle incoming URLs...
Read more >
URL Schemes Supported in Lynx
Enumerate, describe and provide examples of Lynx's URL support on Unix and VMS. Lynx supports both Web standards and extensions.
Read more >
A"ack Surface Extended by URL Schemes
SSRF can creat a evil request to any arbitrary reachable networks ... There are all url schemes those libcurl supports. --via SSRF bible....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found