web-push-libs / web-push-csharp

Web Push library for C#
Mozilla Public License 2.0
429 stars 108 forks source link

Indicating timeout for push request #45

Closed zahyvolf closed 5 years ago

zahyvolf commented 6 years ago

Is there a plan to add timeout for the the HttpClient? i've noticed the WebPushClient constructor can receive an HttpClientHandler, unfortunately the timeout argument belong to the HttpClient itself which is private/protected.

(The motivation is of course to prevent hangs during SendNotification. I would use the Async method but that would mask the real send failures)

tuwrraphael commented 6 years ago

At the moment you could use the GenerateRequestDetails method of WebPushClient, and use your own HttpClient instance.

var httpClient = new HttpClient();
// set your options
var request = webPushClient.GenerateRequestDetails(...);
// override request parameters
await httpClient.SendAsync(request);
coryjthompson commented 6 years ago

A timeout would definitely be helpful. I'll look into it 👍

coryjthompson commented 5 years ago

WebPushClient now has an option to specify your own httpclient in which you can set your own timeout value.

var httpClient = new HttpClient();

httpClient.Timeout = TimeSpan.FromSeconds(100);

var webPush = new WebPushClient(httpClient);