@@ -382,7 +382,7 @@ def __init__(
382382 timeout : Optional [int ] = None ,
383383 ssl_verify_cert : Union [bool , str ] = True ,
384384 ssl_cert : Union [str , Tuple [str , str ], None ] = None ,
385- headers : Dict [str , str ] = None ,
385+ headers : Mapping [str , str ] = None ,
386386 huge_tree : bool = False ,
387387 ) -> None :
388388 """
@@ -425,12 +425,12 @@ def __init__(
425425 self .proxy = _proxy
426426
427427 # Build global headers
428- self .headers = {
428+ self .headers = CaseInsensitiveDict ( {
429429 "User-Agent" : "python-caldav/" + __version__ ,
430430 "Content-Type" : "text/xml" ,
431431 "Accept" : "text/xml, text/calendar" ,
432- }
433- self .headers .update (headers )
432+ })
433+ self .headers .update (headers or {} )
434434 if self .url .username is not None :
435435 username = unquote (self .url .username )
436436 password = unquote (self .url .password )
@@ -644,7 +644,7 @@ def request(
644644 headers = headers or {}
645645
646646 combined_headers = self .headers .copy ()
647- combined_headers .update (headers )
647+ combined_headers .update (headers or {} )
648648 if (body is None or body == "" ) and "Content-Type" in combined_headers :
649649 del combined_headers ["Content-Type" ]
650650
@@ -695,13 +695,15 @@ def request(
695695 if not r .status_code == 401 :
696696 raise
697697
698+ ## Returned headers
699+ r_headers = CaseInsensitiveDict (r .headers )
698700 if (
699701 r .status_code == 401
700- and "WWW-Authenticate" in r . headers
702+ and "WWW-Authenticate" in r_headers
701703 and not self .auth
702704 and self .username
703705 ):
704- auth_types = self .extract_auth_types (r . headers ["WWW-Authenticate" ])
706+ auth_types = self .extract_auth_types (r_headers ["WWW-Authenticate" ])
705707
706708 if self .password and self .username and "digest" in auth_types :
707709 self .auth = niquests .auth .HTTPDigestAuth (self .username , self .password )
@@ -719,7 +721,7 @@ def request(
719721
720722 elif (
721723 r .status_code == 401
722- and "WWW-Authenticate" in r . headers
724+ and "WWW-Authenticate" in r_headers
723725 and self .auth
724726 and self .password
725727 and isinstance (self .password , bytes )
@@ -733,7 +735,7 @@ def request(
733735 ## sequence and not a string (see commit 13a4714, which
734736 ## introduced this regression)
735737
736- auth_types = self .extract_auth_types (r . headers ["WWW-Authenticate" ])
738+ auth_types = self .extract_auth_types (r_headers ["WWW-Authenticate" ])
737739
738740 if self .password and self .username and "digest" in auth_types :
739741 self .auth = niquests .auth .HTTPDigestAuth (
0 commit comments