##// END OF EJS Templates
httpconnection: correctly handle redirects from http to https...
Augie Fackler -
r14346:bf85c263 default
parent child Browse files
Show More
@@ -132,7 +132,7 b' class http2handler(urllib2.HTTPHandler, '
132 self._connections = {}
132 self._connections = {}
133
133
134 # shamelessly borrowed from urllib2.AbstractHTTPHandler
134 # shamelessly borrowed from urllib2.AbstractHTTPHandler
135 def do_open(self, http_class, req):
135 def do_open(self, http_class, req, use_ssl):
136 """Return an addinfourl object for the request, using http_class.
136 """Return an addinfourl object for the request, using http_class.
137
137
138 http_class must implement the HTTPConnection API from httplib.
138 http_class must implement the HTTPConnection API from httplib.
@@ -173,7 +173,8 b' class http2handler(urllib2.HTTPHandler, '
173 if not host:
173 if not host:
174 raise urllib2.URLError('no host given')
174 raise urllib2.URLError('no host given')
175
175
176 allconns = self._connections.get((host, proxy), [])
176 connkey = use_ssl, host, proxy
177 allconns = self._connections.get(connkey, [])
177 conns = [c for c in allconns if not c.busy()]
178 conns = [c for c in allconns if not c.busy()]
178 if conns:
179 if conns:
179 h = conns[0]
180 h = conns[0]
@@ -185,7 +186,7 b' class http2handler(urllib2.HTTPHandler, '
185 if req.timeout is not socket._GLOBAL_DEFAULT_TIMEOUT:
186 if req.timeout is not socket._GLOBAL_DEFAULT_TIMEOUT:
186 timeout = req.timeout
187 timeout = req.timeout
187 h = http_class(host, timeout=timeout, proxy_hostport=proxy)
188 h = http_class(host, timeout=timeout, proxy_hostport=proxy)
188 self._connections.setdefault((host, proxy), []).append(h)
189 self._connections.setdefault(connkey, []).append(h)
189
190
190 headers = dict(req.headers)
191 headers = dict(req.headers)
191 headers.update(req.unredirected_hdrs)
192 headers.update(req.unredirected_hdrs)
@@ -217,7 +218,7 b' class http2handler(urllib2.HTTPHandler, '
217 def http_open(self, req):
218 def http_open(self, req):
218 if req.get_full_url().startswith('https'):
219 if req.get_full_url().startswith('https'):
219 return self.https_open(req)
220 return self.https_open(req)
220 return self.do_open(HTTPConnection, req)
221 return self.do_open(HTTPConnection, req, False)
221
222
222 def https_open(self, req):
223 def https_open(self, req):
223 res = readauthforuri(self.ui, req.get_full_url())
224 res = readauthforuri(self.ui, req.get_full_url())
@@ -227,7 +228,7 b' class http2handler(urllib2.HTTPHandler, '
227 self.ui.debug("using auth.%s.* for authentication\n" % group)
228 self.ui.debug("using auth.%s.* for authentication\n" % group)
228 else:
229 else:
229 self.auth = None
230 self.auth = None
230 return self.do_open(self._makesslconnection, req)
231 return self.do_open(self._makesslconnection, req, True)
231
232
232 def _makesslconnection(self, host, port=443, *args, **kwargs):
233 def _makesslconnection(self, host, port=443, *args, **kwargs):
233 keyfile = None
234 keyfile = None
General Comments 0
You need to be logged in to leave comments. Login now