[PATCH 1 of 2 RFC] keepalive: honor urllib2 style get_method overrides

John Mulligan phlogistonjohn at asynchrono.us
Thu Feb 9 20:30:37 UTC 2017


# HG changeset patch
# User John Mulligan <phlogistonjohn at asynchrono.us>
# Date 1486671527 18000
#      Thu Feb 09 15:18:47 2017 -0500
# Node ID 71debb56ce136086187d7f9c1986eb7f3b9ee0a9
# Parent  eb78ec9e97b70310e2944f72c29463bedfc21442
keepalive: honor urllib2 style get_method overrides

In urllib2 docs and discussions it can be found that in order
to make a request other than GET or POST the get_method of a
Request object can be overriden. Make Mercurial's internal
version of this honor the return value of get_method.

Please see the followup patch to the bugzilla extension for
the reason for this change. Marking RFC because I'm not entirely
sure this is the right way make the HTTP requests.

diff --git a/mercurial/keepalive.py b/mercurial/keepalive.py
--- a/mercurial/keepalive.py
+++ b/mercurial/keepalive.py
@@ -310,14 +310,14 @@ class KeepAliveHandler(object):
         try:
             if req.has_data():
                 data = req.get_data()
-                h.putrequest('POST', req.get_selector(), **skipheaders)
+                h.putrequest(req.get_method(), req.get_selector(), **skipheaders)
                 if 'content-type' not in headers:
                     h.putheader('Content-type',
                                 'application/x-www-form-urlencoded')
                 if 'content-length' not in headers:
                     h.putheader('Content-length', '%d' % len(data))
             else:
-                h.putrequest('GET', req.get_selector(), **skipheaders)
+                h.putrequest(req.get_method(), req.get_selector(), **skipheaders)
         except socket.error as err:
             raise urlerr.urlerror(err)
         for k, v in headers.items():


More information about the Mercurial-devel mailing list