curl_cffi icon indicating copy to clipboard operation
curl_cffi copied to clipboard

fix: don't create `Headers` object if headers are already of that type

Open serozhenka opened this issue 1 year ago • 2 comments

The Headers.encoding gets stripped off in the BaseSession._set_curl_options method if the headers are already of type Headers. This PR aims to fix this by checking whether the headers are of the expected type.

serozhenka avatar Oct 03 '24 07:10 serozhenka

That's indeed a bug, but what about fixing it in the __init__ method of Headers?

https://github.com/lexiforest/curl_cffi/blob/5074660e0f32b7531eca384cf5e2d8d0b1c94103/curl_cffi/requests/headers.py#L114-L115

The _encoding attribute is not copied from the headers passed in.

Anyway, it would be better to add a simple unittest in the test_headers.py file.

lexiforest avatar Oct 03 '24 15:10 lexiforest

@lexiforest alrighty, will do it inside the Headers' __init__ it also makes more sense for me, and will add the unit test.

serozhenka avatar Oct 03 '24 16:10 serozhenka

@lexiforest sorry for abandoning this, just got back here as we faced the issue again. I have transferred the preservation of the encoding into the Headers __init__ and added two unit tests. Hope for a quick merge here!

p.s. didn't want to spend much time resolving conflicts, so just discarded the older commit, merged my branch with the main, and added the new commit on top.

serozhenka avatar Feb 21 '25 11:02 serozhenka