@@ -984,18 +984,29 @@ def test_http_header_priority(self):
984984 # gh-47005: regular headers set via add_header() must override
985985 # unredirected headers with the same name in do_open(), consistent
986986 # with get_header() and header_items().
987+ cases = [
988+ ("Content-Type" , "application/json" , "application/x-www-form-urlencoded" ),
989+ ("Content-Length" , "99" , "0" ),
990+ ("Host" , "override.example.com" , "internal.example.com" ),
991+ ("Authorization" , "Bearer user-token" , "Basic stale=" ),
992+ ("Cookie" , "a=1" , "b=2" ),
993+ ("User-Agent" , "MyApp/1.0" , "Python-urllib/test" ),
994+ ]
987995 h = urllib .request .AbstractHTTPHandler ()
988996 h .parent = MockOpener ()
989997
990- req = Request ("http://example.com/" , headers = {"Content-Type" : "application/json" })
991- req .timeout = None
992- req .add_unredirected_header ("Content-Type" , "application/x-www-form-urlencoded" )
998+ for key , regular , unredirected in cases :
999+ req = Request ("http://example.com/" , headers = {key : regular })
1000+ req .timeout = None
1001+ req .add_unredirected_header (key , unredirected )
9931002
994- http = MockHTTPClass ()
995- h .do_open (http , req )
1003+ http = MockHTTPClass ()
1004+ h .do_open (http , req )
9961005
997- sent_headers = dict (http .req_headers )
998- self .assertEqual (sent_headers ["Content-Type" ], "application/json" )
1006+ sent_headers = dict (http .req_headers )
1007+ self .assertEqual (sent_headers [key ], regular )
1008+ self .assertEqual (req .get_header (key ), regular )
1009+ self .assertEqual (dict (req .header_items ())[key ], regular )
9991010
10001011 def test_http_body_file (self ):
10011012 # A regular file - chunked encoding is used unless Content Length is
0 commit comments