Skip to content

Commit

Permalink
Place back the force
Browse files Browse the repository at this point in the history
  • Loading branch information
novitae authored Sep 27, 2024
1 parent b78c83f commit 4478640
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions curl_cffi/requests/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ def _update_url_params(url: str, *params_list: Union[Dict, List, Tuple, None]) -
return new_url


def _update_header_line(header_lines: List[str], key: str, value: str):
def _update_header_line(header_lines: List[str], key: str, value: str, force: bool = False):
"""Update header line list by key value pair."""
for idx, line in enumerate(header_lines):
if line.lower().startswith(key.lower() + ":"):
if line.lower().startswith(key.lower() + ":") and force:
header_lines[idx] = f"{key}: {value}"
break
else: # if not break
Expand Down Expand Up @@ -455,14 +455,14 @@ def _set_curl_options(

# Add content-type if missing
if json is not None:
_update_header_line(header_lines, "Content-Type", "application/json")
_update_header_line(header_lines, "Content-Type", "application/json", force=True)
if isinstance(data, dict) and method != "POST":
_update_header_line(header_lines, "Content-Type", "application/x-www-form-urlencoded")
if isinstance(data, (str, bytes)):
_update_header_line(header_lines, "Content-Type", "application/octet-stream")

# Never send `Expect` header.
_update_header_line(header_lines, "Expect", "")
_update_header_line(header_lines, "Expect", "", force=True)

c.setopt(CurlOpt.HTTPHEADER, [h.encode() for h in header_lines])

Expand Down

0 comments on commit 4478640

Please sign in to comment.