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

Unable to Monkeypatch h11._headers.normalize_and_validate in h11 v0.14.0 #167

Open
makaramkd opened this issue Oct 11, 2023 · 1 comment

Comments

@makaramkd
Copy link

I'm currently working with h11 v0.14.0 and python 3.10 and I'm attempting to monkeypatch the h11._headers.normalize_and_validate method to customize its behavior. However, I've encountered an issue where the native function always takes precedence, and my custom monkeypatch does not have any effect. I am trying to fix Transfer-Encoding headers issue: multiple Transfer-Encoding headers

What I've Tried:
I've successfully monkeypatched other methods, such as h11._headers.get_comma_header, with no issues.

Expected Behavior:
I expect to be able to monkeypatch the h11._headers.normalize_and_validate method and have my custom implementation take effect.

Actual Behavior:
The native h11._headers.normalize_and_validate method is always used, and my monkeypatch does not have any effect.

Sample:
WORKING:

import pytest
mp = pytest.MonkeyPatch()

def get_comma(headers, name):
    print('some change')
    ...

mp.setattr("h11._headers.get_comma_header", get_comma)

I can successfully patch get_comma_header

NOT WORKING

import pytest
mp = pytest.MonkeyPatch()

def normalize(headers, _parsed=False):
    print("Normalize")
    ...

mk.setattr("h11._headers.normalize_and_validate", normalize)

Cannot patch. Its still using the native method for this.

@njsmith
Copy link
Member

njsmith commented Oct 12, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants