Skip to content

Commit fb04ecc

Browse files
eendebakptclaude
andcommitted
Use urlsplit() instead of urlparse() in http.cookiejar.request_host()
request_host() only needs the netloc, which is the same for both, and urlsplit() is cached while urlparse() is not. It is called once for every stored domain on each CookieJar.add_cookie_header() call, which is now about 2.5x faster. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 21a36aa commit fb04ecc

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

‎Lib/http/cookiejar.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ def request_host(request):
627627
628628
"""
629629
url = request.get_full_url()
630-
host = urllib.parse.urlparse(url).netloc
630+
host = urllib.parse.urlsplit(url).netloc
631631
if host == "":
632632
host = request.get_header("Host", "")
633633

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Speed up :meth:`http.cookiejar.CookieJar.add_cookie_header` by about 2.5x by
2+
parsing the request URL with :func:`urllib.parse.urlsplit` instead of
3+
:func:`urllib.parse.urlparse` when checking each stored domain.

0 commit comments

Comments
 (0)