File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 44open System
55open System.Net
66open System.Net .Http
7+ open System.Net .Http .Headers
78open System.Threading .Tasks
89open Markdig
910open System.IO
@@ -39,6 +40,11 @@ let collectLinks node =
3940let exclusionCodes = Map.ofArray [|
4041 " https://www.lkokemohr.de/fsharp_godot.html" , HttpStatusCode.TooManyRequests // GitHub runner receives this often
4142|]
43+ let userAgents = Map.ofArray [|
44+ // Reddit doesn't like when we access it without any user-agent header.
45+ // Note that this won't work for every other resource; e.g., X doesn't like whe we *pass* the user-agent.
46+ " https://www.reddit.com/r/fsharp/" , " Mozilla/5.0 (compatible; +https://github.com/fsprojects/awesome-fsharp)"
47+ |]
4248
4349let printLock = Object()
4450let retryPipeline =
@@ -49,7 +55,13 @@ let checkLinkStatus (client: HttpClient) (url: string) = task {
4955 try
5056 lock printLock ( fun () -> printfn $" Verifying link {url}…" )
5157 let! response = retryPipeline.ExecuteAsync(
52- fun _ -> ValueTask< HttpResponseMessage>( client.GetAsync url)
58+ fun _ -> ValueTask< HttpResponseMessage>( task {
59+ use request = new HttpRequestMessage( HttpMethod.Get, url)
60+ Map.tryFind url userAgents |> Option.iter(
61+ fun ua -> request.Headers.TryAddWithoutValidation( " User-Agent" , ua) |> ignore
62+ )
63+ return ! client.SendAsync request
64+ })
5365 )
5466 if response.StatusCode <> HttpStatusCode.OK then
5567 return
You can’t perform that action at this time.
0 commit comments