121 _configuredlogging = False |
122 _configuredlogging = False |
122 LOGFMT = '%(levelname)s:%(name)s:%(lineno)d:%(message)s' |
123 LOGFMT = '%(levelname)s:%(name)s:%(lineno)d:%(message)s' |
123 # Subclass BOTH of these because otherwise urllib2 "helpfully" |
124 # Subclass BOTH of these because otherwise urllib2 "helpfully" |
124 # reinserts them since it notices we don't include any subclasses of |
125 # reinserts them since it notices we don't include any subclasses of |
125 # them. |
126 # them. |
126 class http2handler(urllib2.HTTPHandler, urllib2.HTTPSHandler): |
127 class http2handler(urlreq.httphandler, urlreq.httpshandler): |
127 def __init__(self, ui, pwmgr): |
128 def __init__(self, ui, pwmgr): |
128 global _configuredlogging |
129 global _configuredlogging |
129 urllib2.AbstractHTTPHandler.__init__(self) |
130 urlreq.abstracthttphandler.__init__(self) |
130 self.ui = ui |
131 self.ui = ui |
131 self.pwmgr = pwmgr |
132 self.pwmgr = pwmgr |
132 self._connections = {} |
133 self._connections = {} |
133 # developer config: ui.http2debuglevel |
134 # developer config: ui.http2debuglevel |
134 loglevel = ui.config('ui', 'http2debuglevel', default=None) |
135 loglevel = ui.config('ui', 'http2debuglevel', default=None) |
185 proxy = (proxyhost, proxyport) |
186 proxy = (proxyhost, proxyport) |
186 else: |
187 else: |
187 proxy = None |
188 proxy = None |
188 |
189 |
189 if not host: |
190 if not host: |
190 raise urllib2.URLError('no host given') |
191 raise urlerr.urlerror('no host given') |
191 |
192 |
192 connkey = use_ssl, host, proxy |
193 connkey = use_ssl, host, proxy |
193 allconns = self._connections.get(connkey, []) |
194 allconns = self._connections.get(connkey, []) |
194 conns = [c for c in allconns if not c.busy()] |
195 conns = [c for c in allconns if not c.busy()] |
195 if conns: |
196 if conns: |
215 if path[0] != '/': |
216 if path[0] != '/': |
216 path = '/' + path |
217 path = '/' + path |
217 h.request(req.get_method(), path, req.data, headers) |
218 h.request(req.get_method(), path, req.data, headers) |
218 r = h.getresponse() |
219 r = h.getresponse() |
219 except socket.error as err: # XXX what error? |
220 except socket.error as err: # XXX what error? |
220 raise urllib2.URLError(err) |
221 raise urlerr.urlerror(err) |
221 |
222 |
222 # Pick apart the HTTPResponse object to get the addinfourl |
223 # Pick apart the HTTPResponse object to get the addinfourl |
223 # object initialized properly. |
224 # object initialized properly. |
224 r.recv = r.read |
225 r.recv = r.read |
225 |
226 |
226 resp = urllib.addinfourl(r, r.headers, req.get_full_url()) |
227 resp = urlreq.addinfourl(r, r.headers, req.get_full_url()) |
227 resp.code = r.status |
228 resp.code = r.status |
228 resp.msg = r.reason |
229 resp.msg = r.reason |
229 return resp |
230 return resp |
230 |
231 |
231 # httplib always uses the given host/port as the socket connect |
232 # httplib always uses the given host/port as the socket connect |