Add the ability to turn off HTTP 0.9 support.
authorJohn Szakmeister <john@szakmeister.net>
Sun, 2 Dec 2012 16:25:18 +0000 (11:25 -0500)
committerJohn Szakmeister <john@szakmeister.net>
Sun, 2 Dec 2012 16:25:18 +0000 (11:25 -0500)
While debugging an issue I discovered requests was coming back with 200
response, when it really shouldn't have.  It turns out this happened for
two reasons: the jetty server running the app was rather lame and
didn't fail the request as a Bad Request, and httplib was happy to let
malformed data through and call it success.

It turns out httplib's strict flag controls this behavior of whether or
not to validate the status line.  The underlying urllib3 supports the
concept as well.  There was a bug there to that is now fixed upstream.

The last step is exposing this through requests.  This introduces a
supports_http0.9 flag to help control this behavior.  It defaults to
to True to preserve the current behavior.   Setting it to False will
allow the underlying HTTPConnection to validate the status line.

requests/api.py
requests/defaults.py
requests/sessions.py

index ded793525af87f80465e3d506bd45396d9e91560..ce8495c6c7eebcf7de6805c4013a4c6f93323e22 100644 (file)
@@ -44,7 +44,7 @@ def request(method, url, **kwargs):
     adhoc_session = False
     session = kwargs.pop('session', None)
     if session is None:
-        session = sessions.session()
+        session = sessions.session(config=kwargs.get('config', None))
         adhoc_session = True
 
     try:
index 91d038bcb14e126c13ff3a31f194d41002f26bdd..6f18875eda1207eda6c9bd90eea0d15f157fd45d 100644 (file)
@@ -48,3 +48,4 @@ defaults['keep_alive'] = True
 defaults['encode_uri'] = True
 defaults['trust_env'] = True
 defaults['store_cookies'] = True
+defaults['support_http0.9'] = True
index f0d4f3c7e873e6a475c929c0f8ce48e92e571585..5887f74b5c45e5deacfa7b7a1160ea78414fe507 100644 (file)
@@ -98,7 +98,8 @@ class Session(object):
     def init_poolmanager(self):
         self.poolmanager = PoolManager(
             num_pools=self.config.get('pool_connections'),
-            maxsize=self.config.get('pool_maxsize')
+            maxsize=self.config.get('pool_maxsize'),
+            strict=not self.config.get('support_http0.9')
         )
 
     def __repr__(self):