Check for content-type after headers dict has been populated

This commit is contained in:
Daniel A. Wozniak 2024-03-13 15:53:58 -07:00 committed by Pedro Algarvio
parent 773772c426
commit 7c61ac738e

View file

@ -247,17 +247,6 @@ def query(
else:
http_proxy_url = f"http://{proxy_host}:{proxy_port}"
if header_dict is None:
header_dict = {}
if method == "POST" and "Content-Type" not in header_dict:
log.debug(
"Content-Type not provided for POST request, assuming application/x-www-form-urlencoded"
)
header_dict["Content-Type"] = "application/x-www-form-urlencoded"
if "Content-Length" not in header_dict:
header_dict["Content-Length"] = f"{len(data)}"
match = re.match(
r"https?://((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)($|/)",
url,
@ -364,6 +353,19 @@ def query(
agent = f"{agent} http.query()"
header_dict["User-agent"] = agent
if (
proxy_host
and proxy_port
and method == "POST"
and "Content-Type" not in header_dict
):
log.debug(
"Content-Type not provided for POST request, assuming application/x-www-form-urlencoded"
)
header_dict["Content-Type"] = "application/x-www-form-urlencoded"
if "Content-Length" not in header_dict:
header_dict["Content-Length"] = f"{len(data)}"
if backend == "requests":
sess = requests.Session()
sess.auth = auth