Skip to content

Latest commit

 

History

History
50 lines (39 loc) · 2.23 KB

README.md

File metadata and controls

50 lines (39 loc) · 2.23 KB

OwinHttpMessageHandler Build status NuGet Status

An implementation of System.Net.Http.HttpMessageHandler that translates an HttpRequestMessage into an OWIN compatible environment dictionary, calls the supplied AppFunc and translates the result to an HttpResponseMessage. This allows you to call an OWIN application / middleware using HttpClient without actually hitting the network stack. Useful for testing and embedded scenarios.

Install via nuget.

Using

var handler = new OwinHttpMessageHandler(appFunc) // Alternatively you can pass in a MidFunc
{
    UseCookies = true,
    AllowAutoRedirect = true // The handler will auto follow 301/302
}
var httpClient = new HttpClient(handler)
{
    BaseAddress = new Uri("http://localhost")
}

var response = await httpClient.GetAsync("/");

By default, the OWIN environment is defined to look as though the source of the request is local. You can adjust the OWIN environment by passing in a closure:

Func<IDictionary<string, object>, Task> appFunc;
...
var httpClient = new HttpClient(new OwinHttpMessageHandler(appFunc, env =>
{
    env[Constants.ServerRemoteIpAddressKey] ="10.1.1.1";
}));

More information on Http Message Handlers

Licence : MIT

Follow me @randompunter