// ----------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // ----------------------------------------------------------------------- namespace Microsoft.Samples.Kinect.Webserver { using System.Net; using System.Threading.Tasks; /// /// Interface called upon to handle HTTP requests. /// /// /// /// Objects that implement this interface are not expected to be thread-safe but are expected /// to support async operations, so instances should be created and instance methods should /// always be called from a single thread that is associated with a SynchronizationContext /// that provides single-threaded message dispatch /// (e.g.: System.Windows.Threading.DispatcherSynchronizationContext). /// /// /// This means that IHttpRequestHandlers still have to be aware of potential reentrancy /// resulting from asynchronous operations, but they don't have to protect data access with /// locks. /// /// public interface IHttpRequestHandler { /// /// Prepares handler to start receiving HTTP requests. /// /// /// Await-able task. /// /// /// Return value should never be null. Implementations should use Task.FromResult(0) /// if function is implemented synchronously so that callers can await without /// needing to check for null. /// Task InitializeAsync(); /// /// Handle an http request. /// /// /// Context containing HTTP request data, which will also contain associated /// response upon return. /// /// /// Request URI path relative to the URI prefix associated with this request /// handler in the HttpListener. /// /// /// Await-able task. /// /// /// Return value should never be null. Implementations should use Task.FromResult(0) /// if function is implemented synchronously so that callers can await without /// needing to check for null. /// Task HandleRequestAsync(HttpListenerContext requestContext, string subpath); /// /// Cancel all pending operations. /// void Cancel(); /// /// Lets handler know that no more HTTP requests will be received, so that it can /// clean up resources associated with request handling. /// /// /// Await-able task. /// /// /// Return value should never be null. Implementations should use Task.FromResult(0) /// if function is implemented synchronously so that callers can await without /// needing to check for null. /// Task UninitializeAsync(); } }