Skip to content

Instantly share code, notes, and snippets.

@bvanderveen
Forked from panesofglass/IApplication.cs
Created November 30, 2010 18:33
Show Gist options
  • Save bvanderveen/722135 to your computer and use it in GitHub Desktop.
Save bvanderveen/722135 to your computer and use it in GitHub Desktop.
public interface IApplication {
// either may throw exception
IAsyncResult BeginInvoke(IRequest request, AsyncCallback callback, object state);
IResponse EndInvoke(IAsyncResult result);
}
public interface IRequest {
// a bucket into which the host, app, middleware, or whomever can throw things.
IDictionary<string, object> Items { get; }
string Method { get; }
string Uri { get; }
IDictionary<string, IEnumerable<string>> Headers { get; }
// application calls pair until EndReadBody returns 0. either may throw exception.
IAsyncResult BeginReadBody(byte[] buffer, int offset, int count, AsyncCallback callback, object state);
int EndReadBody(IAsyncResult result);
}
public interface IResponse {
string Status { get; } // e.g., "200 OK"
IDictionary<string, IEnumerable<string>> Headers {get;}
// can contain string, byte[], ArraySegment<byte>, FileInfo,
// Task<string>, Task<byte[]>, Task<ArraySegment<byte>>, Task<FileInfo>
//
// exceptions:
// - GetBody() could throw
// - GetBody().GetEnumerator() could throw
// - GetBody().GetEnumerator().MoveNext() could throw
// - GetBody().GetEnumerator().Current could throw
IEnumerable GetBody();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment