Skip to content

devlead/OwinHttpMessageHandler

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

An implementation of System.Net.Http.HttpMessageHandler that translates an HttpRequestMessage into an OWIN compatible environment dictionary

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 96.5%
  • PowerShell 3.5%