Skip to content

Instantly share code, notes, and snippets.

@panesofglass
Forked from loudej/option-a.cs
Created June 21, 2012 03:08
Show Gist options
  • Save panesofglass/2963577 to your computer and use it in GitHub Desktop.
Save panesofglass/2963577 to your computer and use it in GitHub Desktop.
Unify Request and Response representation
namespace Owin
{
public delegate void AppDelegate(
IDictionary<string, object> env,
IDictionary<string, string[]> headers,
Stream body,
ResultDelegate result,
Action<Exception> fault);
public delegate void ResultDelegate(
string status,
IDictionary<string, string[]> headers,
Func<Stream, CancellationToken, Task> body,
IDictionary<string, object> properties);
public delegate Task<Tuple<string /* status */, IDictionary<String, string[]> /* headers */, Func<Stream, CancellationToken, Task> /* body */, IDictionary<string, object> /*properties*/>>
AppTaskDelegate(IDictionary<string, object> env);
public interface IAppBuilder
{
IAppBuilder Use<TApp>(Func<TApp, TApp> middleware);
TApp Build<TApp>(Action<IAppBuilder> fork);
IAppBuilder AddAdapters<TApp1, TApp2>(Func<TApp1, TApp2> adapter1, Func<TApp2, TApp1> adapter2);
IDictionary<string, object> Context { get; }
}
}
namespace Owin
{
public struct CallParameters
{
public IDictionary<string, object> Environment;
public IDictionary<string, string[]> RequestHeaders;
public Stream RequestBody;
}
public struct ResultParameters
{
public string StatusCode;
public IDictionary<string, string[]> ResponseHeaders;
public Func<Stream, CancellationToken, Task> ResponseBody;
public IDictionary<string, object> ResponseProperties;
}
public delegate void AppDelegate(CallParameters call, Action<ResultParameters> result, Action<Exception> fault);
public delegate Task<ResultParameters> AppTaskDelegate(CallParameters call);
public interface IAppBuilder
{
IAppBuilder Use<TApp>(Func<TApp, TApp> middleware);
TApp Build<TApp>(Action<IAppBuilder> fork);
IAppBuilder AddAdapters<TApp1, TApp2>(Func<TApp1, TApp2> adapter1, Func<TApp2, TApp1> adapter2);
IDictionary<string, object> Properties { get; }
}
}
namespace Owin
open System
open System.Collections.Generic
open System.Threading
open System.Threading.Tasks
open FSharp.Control // from FSharpx.Core
//type BodyDelegate = (ArraySegment<byte> -> (unit -> unit) -> bool) -> (exn -> unit) -> CancellationToken -> unit
//type BodyObservable = IObservable<ArraySegment<byte> * (unit -> unit) * (unit -> unit)>
type MessageBody = AsyncSeq<ArraySegment<byte>>
[<Struct>]
type CallParameters =
val Environment : IDictionary<string, obj>
val RequestHeaders : IDictionary<string, string[]>
val RequestBody : MessageBody
[<Struct>]
type ResultParameters = {
val StatusCode : int
val ResponseHeaders : IDictionary<string, string[]>
val ResponseBody : MessageBody
val ResponseProperties : IDictionary<string, obj>
type AppDelegate = CallParameters -> Async<ResultParameters>
[<Interface>]
type IAppBuilder =
abstract member Use : 'a -> 'a -> IAppBuilder
abstract member Build : IAppBuilder -> unit
abstract member AddAdapters : ('a -> 'b) * ('b -> 'a) -> IAppBuilder
abstract member Properties : IDictionary<string, obj> with get
namespace Owin
{
public delegate void AppDelegate(IDictionary<string,object> env, Action<IDictionary<string,object>> result, Action<Exception> fault);
public delegate Task<IDictionary<string,object>> AppTaskDelegate(IDictionary<string,object> env);
public interface IAppBuilder
{
IAppBuilder Use<TApp>(Func<TApp, TApp> middleware);
TApp Build<TApp>(Action<IAppBuilder> fork);
IAppBuilder AddAdapters<TApp1, TApp2>(Func<TApp1, TApp2> adapter1, Func<TApp2, TApp1> adapter2);
IDictionary<string, object> Properties { get; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment