12 |
|
|
13 |
class HTTPConnection_async(asyncore.dispatcher_with_send): |
class HTTPConnection_async(asyncore.dispatcher_with_send): |
14 |
# asynchronous http client |
# asynchronous http client |
15 |
def __init__(self, host, ip, port, consumer, sock=None, map=None, |
def __init__(self, host, ip, port, consumer, sock=None, map=None, proxy=None): |
|
proxy=None): |
|
16 |
asyncore.dispatcher_with_send.__init__(self) |
asyncore.dispatcher_with_send.__init__(self) |
17 |
|
|
18 |
if ip == None: |
if ip is None: |
19 |
ip = host |
ip = host |
20 |
self.ip = ip |
self.ip = ip |
21 |
self.host = host |
self.host = host |
41 |
if self.proxy and self.proxy_port: |
if self.proxy and self.proxy_port: |
42 |
self.path = "http://%s%s" % (self.host, path) |
self.path = "http://%s%s" % (self.host, path) |
43 |
self._initialize_chunked() |
self._initialize_chunked() |
44 |
send_data.append( |
send_data.append("%s %s %s\r\n" % (self.method, self.path, self.http_version)) |
|
"%s %s %s\r\n" % (self.method, self.path, self.http_version)) |
|
45 |
host_found = 0 |
host_found = 0 |
46 |
cl_found = 0 |
cl_found = 0 |
47 |
for h, v in headers.items(): |
for h, v in headers.items(): |
113 |
|
|
114 |
self.data = data |
self.data = data |
115 |
if self.status[1] in (301, 302): |
if self.status[1] in (301, 302): |
116 |
self.consumer.http_redirect(self.header.getheader('location'), |
self.consumer.http_redirect(self.header.getheader('location'),self.status[1] == 301) |
|
self.status[1] == 301) |
|
117 |
self.close() |
self.close() |
118 |
return |
return |
119 |
elif self.header.getheader( |
elif self.header.getheader('transfer-encoding', '').lower() == 'chunked': |
|
'transfer-encoding', '').lower() == 'chunked': |
|
120 |
self._initialize_chunked(1) |
self._initialize_chunked(1) |
121 |
else: |
else: |
122 |
self.consumer.http_header(self.status, self.header) |
self.consumer.http_header(self.status, self.header) |