Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/requests/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ def sha512_utf8(x):
p_parsed = urlparse(url)
#: path is request-uri defined in RFC 2616 which should not be empty
path = p_parsed.path or "/"
if p_parsed.params:
path += f";{p_parsed.params}"
if p_parsed.query:
path += f"?{p_parsed.query}"

Expand Down
38 changes: 38 additions & 0 deletions tests/test_digestauth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Tests for Digest Auth URI handling (issue #6990)."""

import requests
from requests.auth import HTTPDigestAuth


def test_digest_auth_uri_includes_semicolon_params():
"""Digest auth URI must include semicolon path parameters (issue #6990)."""
auth = HTTPDigestAuth("user", "pass")
auth._thread_local.chal = {
"realm": "testrealm",
"nonce": "testnonce",
"qop": "auth",
}
auth._thread_local.last_nonce = ""
auth._thread_local.nonce_count = 0

url = "http://example.com/path;jsessionid=abc123?q=1"
header = auth.build_digest_header("GET", url)

assert 'uri="/path;jsessionid=abc123?q=1"' in header


def test_digest_auth_uri_without_semicolon_params():
"""Digest auth URI is unchanged for URLs without semicolon path params."""
auth = HTTPDigestAuth("user", "pass")
auth._thread_local.chal = {
"realm": "testrealm",
"nonce": "testnonce",
"qop": "auth",
}
auth._thread_local.last_nonce = ""
auth._thread_local.nonce_count = 0

url = "http://example.com/path?q=1"
header = auth.build_digest_header("GET", url)

assert 'uri="/path?q=1"' in header