Ahh... debug and you shall find :)
This discussion gave me the hint I needed for the fix. Get request should already work, but for anything that requires sending data first, you need to modify Http.Async.cs as follows:
In private void RequestStreamCallback(IAsyncResult result, Action<HttpResponse> callback)
The last line is
webRequest.BeginGetResponse(r => ResponseCallback(r, callback), webRequest);
And therein lies the problem. As the
MSDN Article shows, you need to start the timeout mechanism after calling BeginGetResponse. And that is never done for POST/PUT/..
So, I replaced the line with
IAsyncResult asyncResult = webRequest.BeginGetResponse(r => ResponseCallback(r, callback), webRequest);
SetTimeout(asyncResult, _timeoutState);
The way the code on git is written, it works for GET (from private HttpWebRequest GetStyleMethodInternalAsync(string method, Action<HttpResponse> callback)
....
var asyncResult = webRequest.BeginGetResponse(result => ResponseCallback(result, callback), webRequest);
SetTimeout(asyncResult, _timeoutState);
...
but in private void WriteRequestBodyAsync(HttpWebRequest webRequest, Action<HttpResponse> callback),
if (HasBody || HasFiles)
asyncResult = webRequest.BeginGetRequestStream(result => RequestStreamCallback(result, callback), webRequest);
..
SetTimeout(asyncResult, _timeoutState);
If the request has no body or files, then
asyncResult = webRequest.BeginGetResponse(r => ResponseCallback(r, callback), webRequest);
So SetTimeout is set on the proper asynchResult. But with a body/files, the timeout was only set for getting the request stream... so if the server is not around, you'd get the timeout, but if you get the request stream to write to, you can write, and the if the server doesn't respond within the required time, you don't get the timeout.
I'm now off to test if this works on M4A or if I need to write my own timeout mechanism for that.
Hope it helps.
Cheers
Stephan