Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httplib: could not skip "ACCEPT-ENCODING" header #73665

Closed
song1st mannequin opened this issue Feb 8, 2017 · 4 comments
Closed

httplib: could not skip "ACCEPT-ENCODING" header #73665

song1st mannequin opened this issue Feb 8, 2017 · 4 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@song1st
Copy link
Mannequin

song1st mannequin commented Feb 8, 2017

BPO 29479
Nosy @vadmium, @iritkatriel

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2021-06-20.17:14:48.846>
created_at = <Date 2017-02-08.10:18:59.969>
labels = ['invalid', 'type-bug', 'library']
title = 'httplib: could not skip "ACCEPT-ENCODING" header'
updated_at = <Date 2021-06-20.17:14:48.845>
user = 'https://bugs.python.org/song1st'

bugs.python.org fields:

activity = <Date 2021-06-20.17:14:48.845>
actor = 'iritkatriel'
assignee = 'none'
closed = True
closed_date = <Date 2021-06-20.17:14:48.846>
closer = 'iritkatriel'
components = ['Library (Lib)']
creation = <Date 2017-02-08.10:18:59.969>
creator = 'song1st'
dependencies = []
files = []
hgrepos = []
issue_num = 29479
keywords = []
message_count = 4.0
messages = ['287295', '287296', '287298', '396181']
nosy_count = 3.0
nosy_names = ['martin.panter', 'song1st', 'iritkatriel']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue29479'
versions = ['Python 2.7']

@song1st
Copy link
Mannequin Author

song1st mannequin commented Feb 8, 2017

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

@song1st song1st mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Feb 8, 2017
@vadmium
Copy link
Member

vadmium commented Feb 8, 2017

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\>.

@song1st
Copy link
Mannequin Author

song1st mannequin commented Feb 8, 2017

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.

@iritkatriel
Copy link
Member

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

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants