Open msabramo opened 5 years ago
Example of usage:
import json
from requests.compat import urlparse
from requests_unixsocket import Session, UnixAdapter
def custom_urlparse(url):
parsed_url = urlparse(url)
return UnixAdapter.Settings.ParseResult(
sockpath=parsed_url.path,
reqpath=parsed_url.fragment,
)
session = Session(settings=UnixAdapter.Settings(urlparse=custom_urlparse))
r = session.get('http+unix://sock.localhost/var/run/docker.sock#/info')
registry_config = r.json()['RegistryConfig']
print(json.dumps(registry_config, indent=4))
@msabramo The correct example of usage:
import json
from requests.compat import urlparse
from requests_unixsocket import Session, Settings
def custom_urlparse(url):
parsed_url = urlparse(url)
return Settings.ParseResult(
sockpath=parsed_url.path,
reqpath=parsed_url.fragment,
)
session = Session(settings=Settings(urlparse=custom_urlparse))
r = session.get('http+unix://sock.localhost/var/run/docker.sock#/info')
registry_config = r.json().get('RegistryConfig', {})
print(json.dumps(registry_config, indent=4))
This way people can customize it to their liking, as there a lot of opinions about this, as evidenced by the comments on GH-34.
The default parsing is still the same as before, so new version don't break existing code. But the user has the option of passing in a settings object, which has a
urlparse
attribute that can be set to a custom function that processes the URL and splits into asockpath
and areqpath
.Sem-Ver: feature