File tree 3 files changed +19
-2
lines changed
3 files changed +19
-2
lines changed Original file line number Diff line number Diff line change
1
+ Fixed assembling the :class: `~yarl.URL ` for web requests when the host contains a non-default port or IPv6 address -- by :user: `bdraco `.
Original file line number Diff line number Diff line change @@ -431,6 +431,10 @@ def host(self) -> str:
431
431
- overridden value by .clone(host=new_host) call.
432
432
- HOST HTTP header
433
433
- socket.getfqdn() value
434
+
435
+ For example, 'example.com' or 'localhost:8080'.
436
+
437
+ For historical reasons, the port number may be included.
434
438
"""
435
439
host = self ._message .headers .get (hdrs .HOST )
436
440
if host is not None :
@@ -454,8 +458,10 @@ def remote(self) -> Optional[str]:
454
458
455
459
@reify
456
460
def url (self ) -> URL :
457
- url = URL .build (scheme = self .scheme , host = self .host )
458
- return url .join (self ._rel_url )
461
+ """The full URL of the request."""
462
+ # authority is used here because it may include the port number
463
+ # and we want yarl to parse it correctly
464
+ return URL .build (scheme = self .scheme , authority = self .host ).join (self ._rel_url )
459
465
460
466
@reify
461
467
def path (self ) -> str :
Original file line number Diff line number Diff line change @@ -526,6 +526,16 @@ def test_url_url() -> None:
526
526
assert URL ("http://example.com/path" ) == req .url
527
527
528
528
529
+ def test_url_non_default_port () -> None :
530
+ req = make_mocked_request ("GET" , "/path" , headers = {"HOST" : "example.com:8123" })
531
+ assert req .url == URL ("http://example.com:8123/path" )
532
+
533
+
534
+ def test_url_ipv6 () -> None :
535
+ req = make_mocked_request ("GET" , "/path" , headers = {"HOST" : "[::1]:8123" })
536
+ assert req .url == URL ("http://[::1]:8123/path" )
537
+
538
+
529
539
def test_clone () -> None :
530
540
req = make_mocked_request ("GET" , "/path" )
531
541
req2 = req .clone ()
You can’t perform that action at this time.
0 commit comments