txaws-dev team mailing list archive
-
txaws-dev team
-
Mailing list archive
-
Message #00140
[Merge] lp:~franciscosouza/txaws/txaws-proxysupport into lp:txaws
Francisco Souza has proposed merging lp:~franciscosouza/txaws/txaws-proxysupport into lp:txaws.
Requested reviews:
txAWS Committers (txaws-dev)
For more details, see:
https://code.launchpad.net/~franciscosouza/txaws/txaws-proxysupport/+merge/134896
client: add support for http and https proxying
https://codereview.appspot.com/6852064/
--
https://code.launchpad.net/~franciscosouza/txaws/txaws-proxysupport/+merge/134896
Your team txAWS Committers is requested to review the proposed merge of lp:~franciscosouza/txaws/txaws-proxysupport into lp:txaws.
=== modified file 'txaws/client/base.py'
--- txaws/client/base.py 2012-05-16 02:35:26 +0000
+++ txaws/client/base.py 2012-11-19 12:58:40 +0000
@@ -1,3 +1,6 @@
+import os
+import urlparse
+
try:
from xml.etree.ElementTree import ParseError
except ImportError:
@@ -6,14 +9,14 @@
import warnings
from StringIO import StringIO
+from twisted.internet.endpoints import TCP4ClientEndpoint
from twisted.internet.ssl import ClientContextFactory
from twisted.internet.protocol import Protocol
from twisted.internet.defer import Deferred, succeed, fail
from twisted.python import failure
from twisted.web import http
from twisted.web.iweb import UNKNOWN_LENGTH
-from twisted.web.client import HTTPClientFactory
-from twisted.web.client import Agent
+from twisted.web.client import Agent, ProxyAgent
from twisted.web.client import ResponseDone
from twisted.web.http import NO_CONTENT
from twisted.web.http_headers import Headers
@@ -220,16 +223,28 @@
if (self.body_producer is None) and (data is not None):
self.body_producer = FileBodyProducer(StringIO(data))
if scheme == "https":
- if self.endpoint.ssl_hostname_verification:
- contextFactory = WebVerifyingContextFactory(host)
+ proxy_endpoint = os.environ.get("https_proxy")
+ if proxy_endpoint:
+ proxy_url = urlparse.urlparse(proxy_endpoint)
+ endpoint = TCP4ClientEndpoint(self.reactor, proxy_url.hostname, proxy_url.port)
+ agent = ProxyAgent(endpoint, self.reactor)
else:
- contextFactory = WebClientContextFactory()
- agent = Agent(self.reactor, contextFactory)
+ if self.endpoint.ssl_hostname_verification:
+ contextFactory = WebVerifyingContextFactory(host)
+ else:
+ contextFactory = WebClientContextFactory()
+ agent = Agent(self.reactor, contextFactory)
self.client.url = url
d = agent.request(method, url, self.request_headers,
self.body_producer)
else:
- agent = Agent(self.reactor)
+ proxy_endpoint = os.environ.get("http_proxy")
+ if proxy_endpoint:
+ proxy_url = urlparse.urlparse(proxy_endpoint)
+ endpoint = TCP4ClientEndpoint(self.reactor, proxy_url.hostname, proxy_url.port)
+ agent = ProxyAgent(endpoint, self.reactor)
+ else:
+ agent = Agent(self.reactor)
d = agent.request(method, url, self.request_headers,
self.body_producer)
d.addCallback(self._handle_response)
Follow ups