diff -r 3738d270c54a Doc/library/http.client.rst --- a/Doc/library/http.client.rst Mon Dec 31 11:59:48 2012 -0600 +++ b/Doc/library/http.client.rst Mon Dec 31 15:28:20 2012 -0800 @@ -405,7 +405,7 @@ :class:`HTTPConnection` instances have the following methods: -.. method:: HTTPConnection.request(method, url, body=None, headers={}) +.. method:: HTTPConnection.request(method, url, body=None, headers={}, skip_host=False, skip_accept_encoding=False) This will send a request to the server using the HTTP request method *method* and the selector *url*. If the *body* argument is @@ -424,10 +424,16 @@ The *headers* argument should be a mapping of extra HTTP headers to send with the request. + + To disable automatic sending of ``Host:`` or ``Accept-Encoding:`` headers, + specify *skip_host* or *skip_accept_encoding* with non-False values. .. versionadded:: 3.2 *body* can now be an iterable. + .. versonchanged:: 3.4 + added *skip_host* and *skip_accept_encoding*. + .. method:: HTTPConnection.getresponse() Should be called after a request is sent to get the response from the server. diff -r 3738d270c54a Lib/http/client.py --- a/Lib/http/client.py Mon Dec 31 11:59:48 2012 -0600 +++ b/Lib/http/client.py Mon Dec 31 15:28:20 2012 -0800 @@ -1047,9 +1047,9 @@ raise CannotSendHeader() self._send_output(message_body) - def request(self, method, url, body=None, headers={}): + def request(self, method, url, body=None, headers={}, skip_host=False, skip_accept_encoding=False): """Send a complete request to the server.""" - self._send_request(method, url, body, headers) + self._send_request(method, url, body, headers, skip_host=skip_host, skip_accept_encoding=skip_accept_encoding) def _set_content_length(self, body): # Set the content-length based on the body. @@ -1068,13 +1068,13 @@ if thelen is not None: self.putheader('Content-Length', thelen) - def _send_request(self, method, url, body, headers): + def _send_request(self, method, url, body, headers, skip_host=False, skip_accept_encoding=False): # Honor explicitly requested Host: and Accept-Encoding: headers. header_names = dict.fromkeys([k.lower() for k in headers]) skips = {} - if 'host' in header_names: + if skip_host or ('host' in header_names): skips['skip_host'] = 1 - if 'accept-encoding' in header_names: + if skip_accept_encoding or ('accept-encoding' in header_names): skips['skip_accept_encoding'] = 1 self.putrequest(method, url, **skips) diff -r 3738d270c54a Lib/test/test_httplib.py --- a/Lib/test/test_httplib.py Mon Dec 31 11:59:48 2012 -0600 +++ b/Lib/test/test_httplib.py Mon Dec 31 15:28:20 2012 -0800 @@ -822,6 +822,16 @@ self.assertEqual("5", message.get("content-length")) self.assertEqual(b'body\xc1', f.read()) + def test_skip_accept_encoding(self): + self.conn.request("PUT", "/url", "body", skip_accept_encoding=True) + message, f = self.get_headers_and_fp() + self.assertIsNone(message.get("accept-encoding")) + + def test_skip_host(self): + self.conn.request("PUT", "/url", "body", skip_host=True) + message, f = self.get_headers_and_fp() + self.assertIsNone(message.get("host")) + class HTTPResponseTest(TestCase): diff -r 3738d270c54a Misc/ACKS --- a/Misc/ACKS Mon Dec 31 11:59:48 2012 -0600 +++ b/Misc/ACKS Mon Dec 31 15:28:20 2012 -0800 @@ -114,6 +114,7 @@ David Binger Dominic Binks Philippe Biondi +Bryan Bishop Stuart Bishop Roy Bixler Jonathan Black