10
7
from StringIO import StringIO
12
from twisted.internet.endpoints import TCP4ClientEndpoint
13
9
from twisted.internet.ssl import ClientContextFactory
14
10
from twisted.internet.protocol import Protocol
15
11
from twisted.internet.defer import Deferred, succeed, fail
16
12
from twisted.python import failure
17
13
from twisted.web import http
18
14
from twisted.web.iweb import UNKNOWN_LENGTH
19
from twisted.web.client import Agent, ProxyAgent
15
from twisted.web.client import HTTPClientFactory
16
from twisted.web.client import Agent
20
17
from twisted.web.client import ResponseDone
21
from twisted.web.http import NO_CONTENT, PotentialDataLoss
18
from twisted.web.http import NO_CONTENT
22
19
from twisted.web.http_headers import Headers
23
20
from twisted.web.error import Error as TwistedWebError
133
130
self._received += len(bytes)
135
132
def connectionLost(self, reason):
136
reason.trap(ResponseDone, PotentialDataLoss)
133
reason.trap(ResponseDone)
137
134
d = self.finished
138
135
self.finished = None
139
136
streaming = self.content_length is UNKNOWN_LENGTH
223
220
if (self.body_producer is None) and (data is not None):
224
221
self.body_producer = FileBodyProducer(StringIO(data))
225
222
if scheme == "https":
226
proxy_endpoint = os.environ.get("https_proxy")
228
proxy_url = urlparse.urlparse(proxy_endpoint)
229
endpoint = TCP4ClientEndpoint(self.reactor, proxy_url.hostname, proxy_url.port)
230
agent = ProxyAgent(endpoint)
223
if self.endpoint.ssl_hostname_verification:
224
contextFactory = WebVerifyingContextFactory(host)
232
if self.endpoint.ssl_hostname_verification:
233
contextFactory = WebVerifyingContextFactory(host)
235
contextFactory = WebClientContextFactory()
236
agent = Agent(self.reactor, contextFactory)
226
contextFactory = WebClientContextFactory()
227
agent = Agent(self.reactor, contextFactory)
237
228
self.client.url = url
238
229
d = agent.request(method, url, self.request_headers,
239
230
self.body_producer)
241
proxy_endpoint = os.environ.get("http_proxy")
243
proxy_url = urlparse.urlparse(proxy_endpoint)
244
endpoint = TCP4ClientEndpoint(self.reactor, proxy_url.hostname, proxy_url.port)
245
agent = ProxyAgent(endpoint)
247
agent = Agent(self.reactor)
232
agent = Agent(self.reactor)
248
233
d = agent.request(method, url, self.request_headers,
249
234
self.body_producer)
250
235
d.addCallback(self._handle_response)