@@ -588,8 +588,8 @@ def get_cargo_config(request: Request):
588588 Returns a properly configured Cargo config that sets it to look ONLY at the
589589 crates.io mirror.
590590
591- This file is saved as ~/.cargo/ config.toml on Linux devices by default, but
592- will be saved as %USERPROFILE%\\ .cargo\\ config.toml on Windows ones .
591+ The default path for this config on Linux devices is ~/.cargo/config.toml,
592+ and its default path on Windows is %USERPROFILE%\\ .cargo\\ config.toml.
593593 """
594594
595595 # Construct URL to our mirror of the Rust sparse index
@@ -600,14 +600,12 @@ def get_cargo_config(request: Request):
600600 # Construct and return the config.toml file
601601 config_data = "\n " .join (
602602 [
603- "[registries.murfey- crates]" ,
604- f'index = "sparse+ { index_mirror } "' , # sparse+ to use sparse index logic
603+ "[source. crates-io ]" ,
604+ 'replace-with = "murfey-crates "' , # Redirect to our mirror
605605 "" ,
606- "[registry ]" ,
607- 'default = "murfey-crates "' , # Use our registry as default
606+ "[source.murfey-crates ]" ,
607+ f'registry = "sparse+ { index_mirror } "' , # sparse+ to use sparse protocol
608608 "" ,
609- "[registries.crates-io]" ,
610- 'index = "false"' , # Disables using crates.io
611609 ]
612610 )
613611 config_bytes = io .BytesIO (config_data .encode ("utf-8" ))
@@ -619,6 +617,11 @@ def get_cargo_config(request: Request):
619617 )
620618
621619
620+ """
621+ crates.io Sparse Index Registry Key Endpoints
622+ """
623+
624+
622625@rust .get ("/index" )
623626def get_index_page ():
624627 """
@@ -739,6 +742,49 @@ def get_index_package_metadata_for_short_package_names(
739742 )
740743
741744
745+ @rust .get ("/crates/{package}/{version}/download" , response_class = StreamingResponse )
746+ def get_rust_package_download (
747+ request : Request ,
748+ package : str ,
749+ version : str ,
750+ ):
751+ """
752+ Obtain and pass through a crate download request for a Rust package via the
753+ sparse index registry.
754+ """
755+
756+ logger .debug (f"Received request to access { str (request .url )} " )
757+
758+ # Validate package and version
759+ if not re .fullmatch (r"[\w\-]+" , package ):
760+ raise ValueError ("Invalid package name" )
761+ if not re .fullmatch (r"[\w\-\.\+]+" , version ):
762+ raise ValueError ("Invalid version number" )
763+
764+ # Request and return crate from https://static.crates.io
765+ url = f"{ rust_dl } /{ package } /{ version } /download"
766+ response = http_session .get (url )
767+ file_name = f"{ package } -{ version } .crate" # Construct file name to save package as
768+ if response .status_code != 200 :
769+ raise HTTPException (status_code = response .status_code )
770+ return StreamingResponse (
771+ content = response .iter_content (chunk_size = 8192 ),
772+ headers = {
773+ "Content-Disposition" : f'attachment; filename="{ file_name } "' ,
774+ "Content-Type" : response .headers .get (
775+ "Content-Type" , "application/octet-stream"
776+ ),
777+ "Content-Length" : response .headers .get ("Content-Length" ),
778+ },
779+ status_code = response .status_code ,
780+ )
781+
782+
783+ """
784+ crates.io API Key Endpoints
785+ """
786+
787+
742788@rust .get ("/api/v1/crates" )
743789def get_rust_api_package_index (
744790 request : Request ,
@@ -867,43 +913,6 @@ def get_rust_api_package_download(
867913 )
868914
869915
870- @rust .get ("/crates/{package}/{version}/download" , response_class = StreamingResponse )
871- def get_rust_package_download (
872- request : Request ,
873- package : str ,
874- version : str ,
875- ):
876- """
877- Obtain and pass through a crate download request for a Rust package.
878- """
879-
880- logger .debug (f"Received request to access { str (request .url )} " )
881-
882- # Validate package and version
883- if not re .fullmatch (r"[\w\-]+" , package ):
884- raise ValueError ("Invalid package name" )
885- if not re .fullmatch (r"[\w\-\.\+]+" , version ):
886- raise ValueError ("Invalid version number" )
887-
888- # Request and return crate from https://static.crates.io
889- url = f"{ rust_dl } /{ package } /{ version } /download"
890- response = http_session .get (url )
891- file_name = f"{ package } -{ version } .crate" # Construct file name to save package as
892- if response .status_code != 200 :
893- raise HTTPException (status_code = response .status_code )
894- return StreamingResponse (
895- content = response .iter_content (chunk_size = 8192 ),
896- headers = {
897- "Content-Disposition" : f'attachment; filename="{ file_name } "' ,
898- "Content-Type" : response .headers .get (
899- "Content-Type" , "application/octet-stream"
900- ),
901- "Content-Length" : response .headers .get ("Content-Length" ),
902- },
903- status_code = response .status_code ,
904- )
905-
906-
907916@rust .get ("/crates/{package}/{crate}" , response_class = StreamingResponse )
908917def get_rust_package_crate (
909918 request : Request ,
0 commit comments