From ed642cfb6d471f2462953ac5f4f33a443750bd02 Mon Sep 17 00:00:00 2001 From: John Szakmeister Date: Sun, 2 Dec 2012 11:25:18 -0500 Subject: [PATCH 1/5] Add the ability to turn off HTTP 0.9 support. 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 | 2 +- requests/defaults.py | 1 + requests/sessions.py | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/requests/api.py b/requests/api.py index ded79352..ce8495c6 100644 --- a/requests/api.py +++ b/requests/api.py @@ -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: diff --git a/requests/defaults.py b/requests/defaults.py index 91d038bc..6f18875e 100644 --- a/requests/defaults.py +++ b/requests/defaults.py @@ -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 diff --git a/requests/sessions.py b/requests/sessions.py index f0d4f3c7..5887f74b 100644 --- a/requests/sessions.py +++ b/requests/sessions.py @@ -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): From 1a08cea0079ab43f9552ad0795e5e24c19f605e4 Mon Sep 17 00:00:00 2001 From: Artur Dryomov Date: Mon, 3 Dec 2012 20:20:47 +0300 Subject: [PATCH 2/5] Use console syntax highlighting in the readme file. --- README.rst | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index b9e039f5..29d09c8a 100644 --- a/README.rst +++ b/README.rst @@ -16,7 +16,7 @@ perform the simplest of tasks. Things shouldn't be this way. Not in Python. -:: +.. code-block:: pycon >>> r = requests.get('https://api.github.com', auth=('user', 'pass')) >>> r.status_code @@ -54,11 +54,15 @@ Features Installation ------------ -To install requests, simply: :: +To install requests, simply: + +.. code-block:: bash $ pip install requests -Or, if you absolutely must: :: +Or, if you absolutely must: + +.. code-block:: bash $ easy_install requests From 93b2be48f0db93d96495212da96257051ae24ee9 Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Tue, 4 Dec 2012 18:10:33 +0000 Subject: [PATCH 3/5] Prefetch must be false to use response.raw. Resolves issue #979. --- docs/user/quickstart.rst | 7 ++++--- requests/models.py | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/user/quickstart.rst b/docs/user/quickstart.rst index 159d651a..31848b09 100644 --- a/docs/user/quickstart.rst +++ b/docs/user/quickstart.rst @@ -137,12 +137,13 @@ In case the JSON decoding fails, ``r.json`` simply returns ``None``. Raw Response Content -------------------- -In the rare case that you'd like to get the absolute raw socket response from the server, -you can access ``r.raw``:: +In the rare case that you'd like to get the raw socket response from the +server, you can access ``r.raw``. If you want to do this, make sure you set +``prefetch=False`` in your initial request. Once you do, you can do this:: + >>> r = requests.get('https:/github.com/timeline.json', prefetch=False) >>> r.raw - >>> r.raw.read(10) '\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03' diff --git a/requests/models.py b/requests/models.py index 045b3a58..10c85876 100644 --- a/requests/models.py +++ b/requests/models.py @@ -700,6 +700,8 @@ class Response(object): self.headers = CaseInsensitiveDict() #: File-like object representation of response (for advanced usage). + #: Requires that ``prefetch=False` on the request. + # This requirement does not apply for use internally to Requests. self.raw = None #: Final URL location of Response. From 710f09f806404fedc4b54e3a31125a2aa1bd7543 Mon Sep 17 00:00:00 2001 From: Lyndsy Simon Date: Wed, 5 Dec 2012 16:19:14 -0600 Subject: [PATCH 4/5] Updates from ISC to Apache2 --- README.rst | 2 +- docs/index.rst | 2 +- docs/user/intro.rst | 8 ++++---- requests/__init__.py | 4 ++-- requests/api.py | 2 +- setup.py | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.rst b/README.rst index 29d09c8a..64021b8c 100644 --- a/README.rst +++ b/README.rst @@ -5,7 +5,7 @@ Requests: HTTP for Humans .. image:: https://secure.travis-ci.org/kennethreitz/requests.png?branch=develop :target: https://secure.travis-ci.org/kennethreitz/requests -Requests is an ISC Licensed HTTP library, written in Python, for human +Requests is an Apache2 Licensed HTTP library, written in Python, for human beings. Most existing Python modules for sending HTTP requests are extremely diff --git a/docs/index.rst b/docs/index.rst index d469c66d..312c4e7e 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -8,7 +8,7 @@ Requests: HTTP for Humans Release v\ |version|. (:ref:`Installation `) -Requests is an :ref:`ISC Licensed ` HTTP library, written in Python, for human beings. +Requests is an :ref:`Apache2 Licensed ` HTTP library, written in Python, for human beings. Python's standard **urllib2** module provides most of the HTTP capabilities you need, but the API is thoroughly **broken**. diff --git a/docs/user/intro.rst b/docs/user/intro.rst index c40528de..ae5e6393 100644 --- a/docs/user/intro.rst +++ b/docs/user/intro.rst @@ -17,9 +17,9 @@ Requests was developed with a few :pep:`20` idioms in mind. All contributions to Requests should keep these important rules in mind. -.. _`isc`: +.. _`apache2`: -ISC License +Apache2 License ----------- A large number of open source projects you find today are `GPL Licensed`_. @@ -33,10 +33,10 @@ The MIT, BSD, ISC, and Apache2 licenses are great alternatives to the GPL that allow your open-source software to be used freely in proprietary, closed-source software. -Requests is released under terms of `The ISC License`_. +Requests is released under terms of `Apache2 License`_. .. _`GPL Licensed`: http://www.opensource.org/licenses/gpl-license.php -.. _`The ISC License`: http://www.opensource.org/licenses/isc-license +.. _`Apache2 License`: http://opensource.org/licenses/Apache-2.0 Requests License diff --git a/requests/__init__.py b/requests/__init__.py index 70162ee7..8e5b6b0e 100644 --- a/requests/__init__.py +++ b/requests/__init__.py @@ -37,7 +37,7 @@ The other HTTP methods are supported - see `requests.api`. Full documentation is at . :copyright: (c) 2012 by Kenneth Reitz. -:license: ISC, see LICENSE for more details. +:license: Apache 2.0, see LICENSE for more details. """ @@ -45,7 +45,7 @@ __title__ = 'requests' __version__ = '0.14.2' __build__ = 0x001402 __author__ = 'Kenneth Reitz' -__license__ = 'ISC' +__license__ = 'Apache 2.0' __copyright__ = 'Copyright 2012 Kenneth Reitz' diff --git a/requests/api.py b/requests/api.py index a0c17312..cb64b69c 100644 --- a/requests/api.py +++ b/requests/api.py @@ -7,7 +7,7 @@ requests.api This module implements the Requests API. :copyright: (c) 2012 by Kenneth Reitz. -:license: ISC, see LICENSE for more details. +:license: Apache2, see LICENSE for more details. """ diff --git a/setup.py b/setup.py index 82ee8709..6c39182b 100755 --- a/setup.py +++ b/setup.py @@ -45,7 +45,7 @@ setup( 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', 'Natural Language :: English', - 'License :: OSI Approved :: ISC License (ISCL)', + 'License :: OSI Approved :: Apache Software License', 'Programming Language :: Python', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', From 500dc7886712b1e2cb112b837769230544d88b1e Mon Sep 17 00:00:00 2001 From: Jamshid Afshar Date: Tue, 11 Dec 2012 18:14:13 -0600 Subject: [PATCH 5/5] Issue #996 Location should not be followed unless 30X response. --- requests/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requests/models.py b/requests/models.py index 10c85876..9c768b5f 100644 --- a/requests/models.py +++ b/requests/models.py @@ -233,7 +233,7 @@ class Request(object): if r.status_code in REDIRECT_STATI and not self.redirect: - while (('location' in r.headers) and + while (('location' in r.headers and r.status_code in REDIRECT_STATI) and ((r.status_code is codes.see_other) or (self.allow_redirects))): r.content # Consume socket so it can be released