Skip to content

Commit

Permalink
Check for content-type after headers dict has been populated
Browse files Browse the repository at this point in the history
  • Loading branch information
dwoz authored and s0undt3ch committed Mar 14, 2024
1 parent 773772c commit 7c61ac7
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions salt/utils/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7c61ac7

Please sign in to comment.