An implementation of System.Net.Http.HttpMessageHandler that translates an HttpRequestMessage into an OWIN compatible environment dictionary
C# PowerShell
Latest commit 9bc724e Jan 7, 2017 @damianh Some more code cleanup
Permalink
Failed to load latest commit information.
src Some more code cleanup Jan 7, 2017
tools Fix build script Jul 14, 2013
.gitignore Remove packages from version control. Jun 22, 2014
README.md
build.ps1 Don't need buildfunctions.psm1 anymore May 10, 2015
default.ps1
license.txt Add licence.txt Jun 30, 2013

README.md

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, // Will send cookies on subsequent requests. Default is false.
    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 via a delegate:

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