mercurial/keepalive.py
changeset 34467 1232f7fa00c3
parent 34436 5326e4ef1dab
child 35373 03112a2c9c83
equal deleted inserted replaced
34466:80d4681150b9 34467:1232f7fa00c3
    91 import threading
    91 import threading
    92 
    92 
    93 from .i18n import _
    93 from .i18n import _
    94 from . import (
    94 from . import (
    95     pycompat,
    95     pycompat,
       
    96     urllibcompat,
    96     util,
    97     util,
    97 )
    98 )
    98 
    99 
    99 httplib = util.httplib
   100 httplib = util.httplib
   100 urlerr = util.urlerr
   101 urlerr = util.urlerr
   204     #### Transaction Execution
   205     #### Transaction Execution
   205     def http_open(self, req):
   206     def http_open(self, req):
   206         return self.do_open(HTTPConnection, req)
   207         return self.do_open(HTTPConnection, req)
   207 
   208 
   208     def do_open(self, http_class, req):
   209     def do_open(self, http_class, req):
   209         host = req.get_host()
   210         host = urllibcompat.gethost(req)
   210         if not host:
   211         if not host:
   211             raise urlerr.urlerror('no host given')
   212             raise urlerr.urlerror('no host given')
   212 
   213 
   213         try:
   214         try:
   214             h = self._cm.get_ready_conn(host)
   215             h = self._cm.get_ready_conn(host)
   315         skipheaders = {}
   316         skipheaders = {}
   316         for n in ('host', 'accept-encoding'):
   317         for n in ('host', 'accept-encoding'):
   317             if n in headers:
   318             if n in headers:
   318                 skipheaders['skip_' + n.replace('-', '_')] = 1
   319                 skipheaders['skip_' + n.replace('-', '_')] = 1
   319         try:
   320         try:
   320             if req.has_data():
   321             if urllibcompat.hasdata(req):
   321                 data = req.get_data()
   322                 data = urllibcompat.getdata(req)
   322                 h.putrequest(
   323                 h.putrequest(
   323                     req.get_method(), req.get_selector(), **skipheaders)
   324                     req.get_method(), urllibcompat.getselector(req),
       
   325                     **skipheaders)
   324                 if 'content-type' not in headers:
   326                 if 'content-type' not in headers:
   325                     h.putheader('Content-type',
   327                     h.putheader('Content-type',
   326                                 'application/x-www-form-urlencoded')
   328                                 'application/x-www-form-urlencoded')
   327                 if 'content-length' not in headers:
   329                 if 'content-length' not in headers:
   328                     h.putheader('Content-length', '%d' % len(data))
   330                     h.putheader('Content-length', '%d' % len(data))
   329             else:
   331             else:
   330                 h.putrequest(
   332                 h.putrequest(
   331                     req.get_method(), req.get_selector(), **skipheaders)
   333                     req.get_method(), urllibcompat.getselector(req),
       
   334                     **skipheaders)
   332         except socket.error as err:
   335         except socket.error as err:
   333             raise urlerr.urlerror(err)
   336             raise urlerr.urlerror(err)
   334         for k, v in headers.items():
   337         for k, v in headers.items():
   335             h.putheader(k, v)
   338             h.putheader(k, v)
   336         h.endheaders()
   339         h.endheaders()
   337         if req.has_data():
   340         if urllibcompat.hasdata(req):
   338             h.send(data)
   341             h.send(data)
   339 
   342 
   340 class HTTPHandler(KeepAliveHandler, urlreq.httphandler):
   343 class HTTPHandler(KeepAliveHandler, urlreq.httphandler):
   341     pass
   344     pass
   342 
   345