-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Making sure Host request header is the first one
Signed-off-by: Lucas Kanashiro <kanashiro.duarte@gmail.com> Signed-off-by: Sergio Oliveira <seocam@seocam.com>
- Loading branch information
Showing
3 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
from urllib3.connection import HTTPConnection, HTTPSConnection | ||
from urllib3.connectionpool import HTTPConnectionPool, HTTPSConnectionPool | ||
|
||
|
||
def _output(self, s): | ||
"""Host header should always be first""" | ||
|
||
if s.lower().startswith('host: '): | ||
self._buffer.insert(1, s) | ||
else: | ||
self._buffer.append(s) | ||
|
||
HTTPConnectionPool.ConnectionCls = type( | ||
'RevProxyHTTPConnection', | ||
(HTTPConnection,), | ||
{'_output': _output}, | ||
) | ||
|
||
HTTPSConnectionPool.ConnectionCls = type( | ||
'RevProxyHTTPSConnection', | ||
(HTTPSConnection,), | ||
{'_output': _output} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
from urllib3.poolmanager import PoolManager as PoolManager_, SSL_KEYWORDS | ||
|
||
from .connection import HTTPConnectionPool, HTTPSConnectionPool | ||
|
||
pool_classes_by_scheme = { | ||
'http': HTTPConnectionPool, | ||
'https': HTTPSConnectionPool, | ||
} | ||
|
||
|
||
class PoolManager(PoolManager_): | ||
def _new_pool(self, scheme, host, port): | ||
""" | ||
Create a new :class:`ConnectionPool` based on host, port and scheme. | ||
This method is used to actually create the connection pools handed out | ||
by :meth:`connection_from_url` and companion methods. It is intended | ||
to be overridden for customization. | ||
""" | ||
pool_cls = pool_classes_by_scheme[scheme] | ||
kwargs = self.connection_pool_kw | ||
if scheme == 'http': | ||
kwargs = self.connection_pool_kw.copy() | ||
for kw in SSL_KEYWORDS: | ||
kwargs.pop(kw, None) | ||
|
||
return pool_cls(host, port, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters