kennethreitz/requests — pull request #2355 by msabramo (2014-11-25 00:18:28+00:00)
Title: Unix domain sockets

This adds support for unix domain sockets by using a slightly modified version of the unix domain socket adapter from the [docker-py](https://github.com/docker/docker-py) project:

https://github.com/docker/docker-py/blob/master/docker/unixconn/unixconn.py

The modifications are to make the adapter more usable in a greater variety of contexts by getting rid of the context of a `base_url` for the adapter and inventing a URL syntax that allows embedding the socket path into the URL. Basically the socket name goes in the netloc (host) part of the URL, but it's URL-encoded so that slashes become `%2F`'s so that the slashes don't interfere with separating the netloc and path parts of the URLs. This was roughly inspired by URL syntaxes that are mentioned in the following comments:

- http://daniel.haxx.se/blog/2008/04/14/http-over-unix-domain-sockets/
- http://lists.w3.org/Archives/Public/uri/2008Oct/0000.html

So for example if I had a server listening on `/tmp/profilesvc.sock`:

```
$ gunicorn --paste development.ini --log-config development.ini --bind unix:/tmp/profilesvc.sock
...
2014-11-24 16:14:54,943 INFO [MainThread][gunicorn.error.info][glogging.py +213] Listening at: unix:/tmp/profilesvc.sock (95775)
...
```

I can access it as follows:

```python
import requests

resp = requests.get('http+unix://%2Ftmp%2Fprofilesvc.sock/status/pid')
```

In case you're curious about the motivation for adding unix domain socket support, it was inspired by:

https://github.com/jakubroztocil/httpie/issues/209

Cc: @shin-, @jakubroztocil, @monsanto, @np, @nuxlli, @matrixise, @remmelt