mirror of
https://github.com/sprockets/sprockets.mixins.http.git
synced 2024-11-14 19:29:31 +00:00
Add HTTP_MAX_CLIENTS setting.
Add in support for the HTTP_MAX_CLIENTS environment variable to override the default tornado settings.
This commit is contained in:
parent
e1c7388047
commit
196dfd09d5
3 changed files with 30 additions and 3 deletions
|
@ -84,6 +84,15 @@ As with Tornado, to use the curl client which has numerous benefits:
|
|||
app.listen(8000)
|
||||
ioloop.IOLoop.current().start()
|
||||
|
||||
Environment Variables
|
||||
---------------------
|
||||
|
||||
+------------------+----------------------------------------------------------+
|
||||
| HTTP_MAX_CLIENTS | An optional setting that specifies the maximum number of |
|
||||
| | simultaneous asynchronous HTTP requests. If not |
|
||||
| | specified, the default Tornado value of 10 will be used. |
|
||||
+------------------+----------------------------------------------------------+
|
||||
|
||||
License
|
||||
-------
|
||||
``sprockets.mixins.http`` is released under the `3-Clause BSD license <https://github.com/sprockets/sprockets.mixins.http/blob/master/LICENSE>`_.
|
||||
|
|
|
@ -8,6 +8,7 @@ requests.
|
|||
import collections
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import socket
|
||||
import time
|
||||
|
||||
|
@ -22,6 +23,7 @@ LOGGER = logging.getLogger(__name__)
|
|||
CONTENT_TYPE_JSON = headers.parse_content_type('application/json')
|
||||
CONTENT_TYPE_MSGPACK = headers.parse_content_type('application/msgpack')
|
||||
DEFAULT_USER_AGENT = 'sprockets.mixins.http/{}'.format(__version__)
|
||||
DEFAULT_MAX_CLIENTS = 10
|
||||
|
||||
|
||||
HTTPResponse = collections.namedtuple(
|
||||
|
@ -99,7 +101,13 @@ class HTTPClientMixin(object):
|
|||
if body:
|
||||
body = self._http_req_body_serialize(
|
||||
body, request_headers['Content-Type'])
|
||||
|
||||
client = httpclient.AsyncHTTPClient()
|
||||
|
||||
# Workaround for Tornado defect.
|
||||
if hasattr(client, 'max_clients') and os.getenv('HTTP_MAX_CLIENTS'):
|
||||
client.max_clients = int(os.getenv('HTTP_MAX_CLIENTS'))
|
||||
|
||||
response, start_time = None, time.time()
|
||||
for attempt in range(0, self.MAX_HTTP_RETRIES):
|
||||
LOGGER.debug('%s %s (Attempt %i of %i) %r',
|
||||
|
|
16
tests.py
16
tests.py
|
@ -1,8 +1,9 @@
|
|||
import json
|
||||
import logging
|
||||
import os
|
||||
import uuid
|
||||
|
||||
from tornado import httputil, testing, web
|
||||
from tornado import httpclient, httputil, testing, web
|
||||
import mock
|
||||
import umsgpack
|
||||
|
||||
|
@ -400,6 +401,15 @@ class MixinTestCase(testing.AsyncHTTPTestCase):
|
|||
method='DELETE',
|
||||
body={'foo': 'bar', 'status_code': 200},
|
||||
allow_nonstandard_methods=True)
|
||||
|
||||
self.assertTrue(response.ok)
|
||||
self.assertEqual(response.code, 200)
|
||||
|
||||
@testing.gen_test()
|
||||
def test_max_clients_settings_supported(self):
|
||||
os.environ['HTTP_MAX_CLIENTS'] = '25'
|
||||
response = yield self.mixin.http_fetch(
|
||||
self.get_url('/test?foo=bar&status_code=200'))
|
||||
self.assertTrue(response.ok)
|
||||
del os.environ['HTTP_MAX_CLIENTS']
|
||||
client = httpclient.AsyncHTTPClient()
|
||||
self.assertEqual(client.max_clients, 25)
|
||||
|
||||
|
|
Loading…
Reference in a new issue