import socket
from .models import Response
+from .auth import HTTPProxyAuth
from .packages.urllib3.poolmanager import PoolManager
from .hooks import dispatch_hook
+from .compat import urlparse
from .utils import DEFAULT_CA_BUNDLE_PATH, get_encoding_from_headers
from .structures import CaseInsensitiveDict
from .packages.urllib3.exceptions import MaxRetryError
response = dispatch_hook('response', req.hooks, response)
return response
+ def get_connection(self, url, proxies=None):
+ proxies = proxies or {}
+ proxy = proxies.get(urlparse(url).scheme)
+
+ if proxy:
+ conn = poolmanager.proxy_from_url(proxy)
+ else:
+ conn = self.poolmanager.connection_from_url(url)
+
+ return conn
+ # no_proxy = filter(lambda x: x.strip(), self.proxies.get('no', '').split(','))
+
+
def close(self):
"""Dispose of any internal state.
"""
self.poolmanager.clear()
- def send(self, request, prefetch=True, timeout=None, verify=True, cert=None):
+ def send(self, request, prefetch=True, timeout=None, verify=True, cert=None, proxies=None):
"""Sends PreparedRequest object. Returns Response object."""
- conn = self.poolmanager.connection_from_url(request.url)
+ conn = self.get_connection(request.url, proxies)
+
self.cert_verify(conn, request.url, verify, cert)
try:
# from datetime import datetime
from io import BytesIO
-from types import GeneratorType
from .hooks import dispatch_hook, default_hooks
from .structures import CaseInsensitiveDict
from .status_codes import codes
from .auth import HTTPBasicAuth, HTTPProxyAuth
from .cookies import cookiejar_from_dict, extract_cookies_to_jar, get_cookie_header
-# from .packages.urllib3.exceptions import MaxRetryError, LocationParseError
-# from .packages.urllib3.exceptions import TimeoutError
-# from .packages.urllib3.exceptions import SSLError as _SSLError
-# from .packages.urllib3.exceptions import HTTPError as _HTTPError
-# from .packages.urllib3 import connectionpool, poolmanager
from .packages.urllib3.filepost import encode_multipart_formdata
-
from .exceptions import (
ConnectionError, HTTPError, RequestException, Timeout, TooManyRedirects,
URLRequired, SSLError, MissingSchema, InvalidSchema, InvalidURL)
REDIRECT_STATI = (codes.moved, codes.found, codes.other, codes.temporary_moved)
CONTENT_CHUNK_SIZE = 10 * 1024
+ITER_CHUNK_SIZE = 10 * 1024
log = logging.getLogger(__name__)
p = urlsplit(self.url)
- # Proxies use full URLs.
- # if p.scheme in self.proxies:
- # url_base, frag = urldefrag(self.url)
- # return url_base
-
-
path = p.path
if not path:
path = '/'
"""Prepares the given HTTP body data."""
# If a generator is provided, error out.
- if isinstance(data, types.GeneratorType)
+ if isinstance(data, type(_ for _ in [])):
raise NotImplementedError('Generator bodies are not supported yet.')
# Nottin' on you.
return gen
- def iter_lines(self, chunk_size=10 * 1024, decode_unicode=None):
+ def iter_lines(self, chunk_size=ITER_CHUNK_SIZE, decode_unicode=None):
"""Iterates over the response data, one line at a time. This
avoids reading the content at once into memory for large
responses.