@@ -89,8 +89,9 @@ function ProcessLink([System.Uri]$linkUri) {
8989 # and invalid links return a 302 redirecting the user to a Bing search
9090 return ProcessRedirectLink $linkUri - invalidStatusCodes 302
9191 }
92- elseif ($linkUri -match ' ^https?://crates\.io/(?<path>(crates|users|teams)/.+)' ) {
93- return ProcessCratesIoLink $linkUri $matches.path
92+ elseif ($linkUri -match ' ^https?://crates\.io(/(?<path>(crates|users|teams)/.+))?' ) {
93+ # See comment in function below for details.
94+ return ProcessCratesIoLink $linkUri $matches [' path' ]
9495 }
9596 else {
9697 return ProcessStandardLink $linkUri
@@ -113,8 +114,14 @@ function ProcessRedirectLink([System.Uri]$linkUri, [int[]]$invalidStatusCodes) {
113114}
114115
115116function ProcessCratesIoLink ([System.Uri ]$linkUri , $path ) {
116- # Crates.io links are handled by a SPA. Even for missing pages, the response will be a 200, and the spa will only
117- # show a 404 page after it makes a request to the api. We can check the api to see if the page exists.
117+ # crates.io is an SPA that will return a 404 if no 'accept: text/html' header is sent; however, even if you do
118+ # send that header it will 200 on every request - even for missing pages. If a create/user/team path was sent,
119+ # call into their API documented at https://doc.rust-lang.org/cargo/reference/registry-web-api.html; otherwise,
120+ # assume the page exists since there's no other way to know.
121+ if (! $path ) {
122+ return $true
123+ }
124+
118125 $apiUri = " https://crates.io/api/v1/$path "
119126
120127 # Invoke-WebRequest will throw an exception for invalid status codes. They are handled in CheckLink
0 commit comments