@@ -807,7 +807,7 @@ def _try_load_http_cache_headers(
807
807
checksum_path : Path ,
808
808
project_url : Link ,
809
809
headers : Dict [str , str ],
810
- ) -> Tuple [Optional [str ], Optional [str ], Optional [str ]]:
810
+ ) -> Tuple [Optional [str ], Optional [str ], Optional [bytes ]]:
811
811
etag : Optional [str ] = None
812
812
try :
813
813
etag = etag_path .read_text ()
@@ -817,7 +817,7 @@ def _try_load_http_cache_headers(
817
817
etag_path ,
818
818
etag ,
819
819
)
820
- headers ["If-None-Match" ] = etag
820
+ headers ["If-None-Match" ] = f'" { etag } "'
821
821
except OSError as e :
822
822
logger .debug ("no etag found for url %s (%s)" , project_url , str (e ))
823
823
@@ -834,9 +834,9 @@ def _try_load_http_cache_headers(
834
834
except OSError as e :
835
835
logger .debug ("no date found for url %s (%s)" , project_url , str (e ))
836
836
837
- checksum : Optional [str ] = None
837
+ checksum : Optional [bytes ] = None
838
838
try :
839
- checksum = checksum_path .read_text ()
839
+ checksum = checksum_path .read_bytes ()
840
840
logger .debug (
841
841
"found checksum for url %s at %s: %s" ,
842
842
project_url ,
@@ -848,44 +848,53 @@ def _try_load_http_cache_headers(
848
848
849
849
return (etag , date , checksum )
850
850
851
- @staticmethod
851
+ _quoted_value = re .compile (r'^"([^"]*)"$' )
852
+
853
+ @classmethod
854
+ def _strip_quoted_value (cls , value : str ) -> str :
855
+ return cls ._quoted_value .sub (r"\1" , value )
856
+
857
+ @classmethod
852
858
def _write_http_cache_info (
859
+ cls ,
853
860
etag_path : Path ,
854
861
date_path : Path ,
855
862
checksum_path : Path ,
856
863
project_url : Link ,
857
864
index_response : IndexContent ,
858
865
prev_etag : Optional [str ],
859
- prev_checksum : Optional [str ],
860
- ) -> Tuple [Optional [str ], Optional [str ], str , bool ]:
866
+ prev_checksum : Optional [bytes ],
867
+ ) -> Tuple [Optional [str ], Optional [str ], bytes , bool ]:
861
868
hasher = sha256 ()
862
869
hasher .update (index_response .content )
863
- new_checksum = hasher .hexdigest ()
864
- checksum_path .write_text (new_checksum )
870
+ new_checksum = hasher .digest ()
871
+ checksum_path .write_bytes (new_checksum )
865
872
page_unmodified = new_checksum == prev_checksum
866
873
867
- new_etag = index_response .etag
874
+ new_etag : Optional [ str ] = index_response .etag
868
875
if new_etag is None :
869
876
logger .debug ("no etag returned from fetch for url %s" , project_url .url )
870
877
try :
871
878
etag_path .unlink ()
872
879
except OSError :
873
880
pass
874
- elif new_etag != prev_etag :
875
- logger .debug (
876
- "etag for url %s updated from %s -> %s" ,
877
- project_url .url ,
878
- prev_etag ,
879
- new_etag ,
880
- )
881
- etag_path .write_text (new_etag )
882
881
else :
883
- logger .debug (
884
- "etag was unmodified for url %s (%s)" , project_url .url , prev_etag
885
- )
886
- assert page_unmodified
882
+ new_etag = cls ._strip_quoted_value (new_etag )
883
+ if new_etag != prev_etag :
884
+ logger .debug (
885
+ "etag for url %s updated from %s -> %s" ,
886
+ project_url .url ,
887
+ prev_etag ,
888
+ new_etag ,
889
+ )
890
+ etag_path .write_text (new_etag )
891
+ else :
892
+ logger .debug (
893
+ "etag was unmodified for url %s (%s)" , project_url .url , prev_etag
894
+ )
895
+ assert page_unmodified
887
896
888
- new_date = index_response .date
897
+ new_date : Optional [ str ] = index_response .date
889
898
if new_date is None :
890
899
logger .debug (
891
900
"no date could be parsed from response for url %s" , project_url
0 commit comments