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

Request Headers #420

Open
lolyinseo opened this issue Oct 28, 2024 · 4 comments
Open

Request Headers #420

lolyinseo opened this issue Oct 28, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@lolyinseo
Copy link

lolyinseo commented Oct 28, 2024

According CURL doc https://curl.se/libcurl/c/CURLOPT_HTTPHEADER.html
All headers with empty value should be removed, without replacing with default headers

If you add a header with no content as in 'Accept:' (no data on the right side of the colon), the internally used header is disabled/removed. With this option you can add new headers, replace internal headers and remove internal headers. To add a header with no content (nothing to the right side of the colon), use the form 'name;' (note the ending semicolon).

But this will not happen. For example

{'Content-Type': ''}

In the request it becomes like

Content-Type:

Headers like

{'Content-Type': None}

Produces a huge number of errors(since you always expect a string)

If I removing the header completely the default Curl header appearing(As it should be according to the documentation).

Content-Type: application/x-www-form-urlencoded

suggest that the correct behavior for {'Some-Header': None} is remove headers ( set Some-Header: for curl), and for {'Some-Header': ''} is set Some-Header; (note the ending semicolon).

@lolyinseo lolyinseo added the bug Something isn't working label Oct 28, 2024
@perklet
Copy link
Collaborator

perklet commented Oct 29, 2024

It makes sense to me. Anyway, can you describe a situation where you would want to completely make the Content-Type header removed in the request?

@lolyinseo
Copy link
Author

It makes sense to me. Anyway, can you describe a situation where you would want to completely make the Content-Type header removed in the request?

not only Content-Type, this behavior should apply to all headers. In my case, the server only accepts requests with missing Content-Type

@PalmtopTiger
Copy link

Agree. Need a way to remove default headers by setting them to None.

Here's another example:
curl_cffi by default sends Sec-Fetch-User header with each request:
Sec-Fetch-User: ?1
This header signals that the request was initiated by user. According to the documentation, it can only have one value - "?1". Otherwise, this header should not be sent. For example, when requesting images or styles. Removing this header is necessary to pretend to be a browser.

@hectorgarciatorres
Copy link

this is a huge issue, has anyone found a solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants