This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: httplib: could not skip "ACCEPT-ENCODING" header
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: iritkatriel, martin.panter, song1st
Priority: normal Keywords:

Created on 2017-02-08 10:18 by song1st, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg287295 - (view) Author: song1st (song1st) Date: 2017-02-08 10:18
When I tried to skip "ACCEPT-ENCODING" of header, I found the behavior was not right.
I think the issue is the following two "if" in _send_request of httplib.

    def _send_request(self, method, url, body, headers):
        # Honor explicitly requested Host: and Accept-Encoding: headers.
        header_names = dict.fromkeys([k.lower() for k in headers])
        skips = {}
        if 'host' in header_names:
            skips['skip_host'] = 1
        if 'accept-encoding' in header_names:
            skips['skip_accept_encoding'] = 1
msg287296 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2017-02-08 10:51
Please explain what the wrong behaviour that you see is, and what you expect the right behaviour should be.

That code is intended to either keep any user-supplied Accept-Encoding header field, or send “Accept-Encoding: identity” if the field is not supplied.

If you are looking for a way to avoid adding this field entirely, see the lower level putrequest() and related methods. This is documented behaviour: <https://docs.python.org/2.7/library/httplib.html#httplib.HTTPConnection.putrequest>.
msg287298 - (view) Author: song1st (song1st) Date: 2017-02-08 11:08
Sorry, I thought I misunderstood the meaning.

I want no "ACCEPT-ENCODING" even "ACCEPT-ENCODING: identity".
I tried to modify the code from 
    if 'accept-encoding' in header_names:
to
    if not 'accept-encoding' in header_names:

The http request will be no "ACCEPT-ENCODING".
This is what I want.
msg396181 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-06-20 17:14
As Martin has stated, this can be achieved with putrequest as explained in the doc:

https://docs.python.org/3.10/library/http.client.html#http.client.HTTPConnection.putrequest
History
Date User Action Args
2022-04-11 14:58:42adminsetgithub: 73665
2021-06-20 17:14:48iritkatrielsetstatus: open -> closed

nosy: + iritkatriel
messages: + msg396181

resolution: not a bug
stage: test needed -> resolved
2017-02-08 11:08:29song1stsetmessages: + msg287298
2017-02-08 10:51:28martin.pantersetnosy: + martin.panter

messages: + msg287296
stage: test needed
2017-02-08 10:18:59song1stcreate