aspnet / AspNetKatana

Microsoft's OWIN implementation, the Katana project
Apache License 2.0
967 stars 334 forks source link

Q: What is the proper way to check if the client disconnected in OWIN/Katana? #296

Closed Peperud closed 5 years ago

Peperud commented 5 years ago

There is Request.IsClientDisconnected for HttpContext pages. What is the best way to do the same in OWIN/Katana?

Seems like a request cancelling middleware could be a decent choice to deal with https://github.com/aspnet/AspNetWebStack/issues/249

Tratcher commented 5 years ago

Check IOwinRequest.CallCancelled.IsCancellationRequested https://github.com/aspnet/AspNetKatana/blob/40de8011dab132b020e8d6e89239f4a0bda7d82c/src/Microsoft.Owin/IOwinRequest.cs#L133-L138

Peperud commented 5 years ago

@Tratcher Thanks Chris, it was in front of me, no idea how I missed it. A follow up - is throwing still the (preferred/best) way to abort a request in Katana?

Tratcher commented 5 years ago

If the client has already disconnected then it's just a matter of how you want the request to show up in the logs. E.g. you could return something like a 404, but that might be confusing in your logs. Throwing tends to be the most understandable.

Peperud commented 5 years ago

499 seems to be the appropriate code. Might go that way, since at this point the situation is handled. Thanks.