Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit af7dc8d

Browse files
committed
Patch #831747: Add skip_accept_encoding parameter to putrequest.
1 parent a53f4eb commit af7dc8d

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

Doc/lib/libhttplib.tex

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,16 @@ \subsection{HTTPConnection Objects \label{httpconnection-objects}}
174174
\method{getreply()} has been called.
175175
\end{methoddesc}
176176

177-
\begin{methoddesc}{putrequest}{request, selector}
177+
\begin{methoddesc}{putrequest}{request, selector\optional{,
178+
skip\_host\optional{, skip_accept_encoding}}}
178179
This should be the first call after the connection to the server has
179180
been made. It sends a line to the server consisting of the
180181
\var{request} string, the \var{selector} string, and the HTTP version
181-
(\code{HTTP/1.1}).
182+
(\code{HTTP/1.1}). To disable automatic sending of \code{Host:} or
183+
\code{Accept-Encoding:} headers (for example to accept additional
184+
content encodings), specify \var{skip_host} or \var{skip_accept_encoding}
185+
with non-False values.
186+
\versionchanged[\var{skip_accept_encoding} argument added]{2.4}
182187
\end{methoddesc}
183188

184189
\begin{methoddesc}{putheader}{header, argument\optional{, ...}}

Lib/httplib.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,18 +596,21 @@ def _send_output(self):
596596
del self._buffer[:]
597597
self.send(msg)
598598

599-
def putrequest(self, method, url, skip_host=0):
599+
def putrequest(self, method, url, skip_host=0, skip_accept_encoding=0):
600600
"""Send a request to the server.
601601
602602
`method' specifies an HTTP request method, e.g. 'GET'.
603603
`url' specifies the object being requested, e.g. '/index.html'.
604+
`skip_host' if True does not add automatically a 'Host:' header
605+
`skip_accept_encoding' if True does not add automatically an
606+
'Accept-Encoding:' header
604607
"""
605608

606609
# if a prior response has been completed, then forget about it.
607610
if self.__response and self.__response.isclosed():
608611
self.__response = None
609612

610-
#
613+
611614
# in certain cases, we cannot issue another request on this connection.
612615
# this occurs when:
613616
# 1) we are in the process of sending a request. (_CS_REQ_STARTED)
@@ -676,7 +679,8 @@ def putrequest(self, method, url, skip_host=0):
676679

677680
# we only want a Content-Encoding of "identity" since we don't
678681
# support encodings such as x-gzip or x-deflate.
679-
self.putheader('Accept-Encoding', 'identity')
682+
if not skip_accept_encoding:
683+
self.putheader('Accept-Encoding', 'identity')
680684

681685
# we can accept "chunked" Transfer-Encodings, but no others
682686
# NOTE: no TE header implies *only* "chunked"

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ Extension modules
116116
Library
117117
-------
118118

119+
- httplib.HTTP.putrequest now offers to omit the implicit Accept-Encoding.
120+
119121
- Patch #841977: modulefinder didn't find extension modules in packages
120122

121123
- imaplib.IMAP4.thread was added.

0 commit comments

Comments
 (0)