Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FSharp.Data HTTP request - unable to set request timeout

Tags:

f#

f#-data

We have a simple F# console app that sends a HTTP POST request to a WebAPI endpoint via FSharp.Data Http.Request. We are using the customizeHttpRequest parameter in order to try to set the request timeout property. Our usage is as follows:

let response = Http.Request(
    serviceEndpoint,
    headers = requestHeaders,
    body = requestBody,
    silentHttpErrors = true,
    customizeHttpRequest = (fun request -> request.Timeout <- 1000; request))

We are observing that our custom timeout is ignored (i.e. the request does not timeout after 1 second as in this example). We have also observed that the request will not timeout after the default System.Net.HttpWebRequest timeout of 100,000ms.

Is there an issue here, or are we not using the customizeHttpRequest parameter correctly?

like image 806
daithimurf Avatar asked Oct 19 '22 13:10

daithimurf


1 Answers

FSharp.Data uses the asynchronous GetResponse method. According to MSDN, in that case the timeout set on the HttpWebRequest object isn't considered and handling the timeout is left for the client code to implement.

Unfortunately FSharp.Data doesn't do it. There's an open issue for implementing it here.

like image 182
scrwtp Avatar answered Jan 04 '23 05:01

scrwtp