Added super hacky RawOwinHttpContext for K profile.

This commit is contained in:
David Fowler 2014-01-26 03:44:21 -08:00
parent 44de535930
commit 724897d0eb
5 changed files with 222 additions and 8 deletions

View File

@ -29,6 +29,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.PipelineCo
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Abstractions.Owin.net45", "src\Microsoft.AspNet.Abstractions.Owin\Microsoft.AspNet.Abstractions.Owin.net45.csproj", "{E6B7056F-547E-4B96-9E58-858DDDAE75D3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Abstractions.Owin.k10", "src\Microsoft.AspNet.Abstractions.Owin\Microsoft.AspNet.Abstractions.Owin.k10.csproj", "{C5C104A4-EE38-4D77-AC77-DF599FD5443A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -79,6 +81,10 @@ Global
{E6B7056F-547E-4B96-9E58-858DDDAE75D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E6B7056F-547E-4B96-9E58-858DDDAE75D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E6B7056F-547E-4B96-9E58-858DDDAE75D3}.Release|Any CPU.Build.0 = Release|Any CPU
{C5C104A4-EE38-4D77-AC77-DF599FD5443A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C5C104A4-EE38-4D77-AC77-DF599FD5443A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C5C104A4-EE38-4D77-AC77-DF599FD5443A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C5C104A4-EE38-4D77-AC77-DF599FD5443A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -95,5 +101,6 @@ Global
{E31CF247-FDA9-4007-B194-A7DBAC18532C} = {D38DDB2B-1138-4F45-8A6A-9499E880F620}
{659F2FD7-D44F-4953-A69D-94AF3D41BA21} = {D38DDB2B-1138-4F45-8A6A-9499E880F620}
{E6B7056F-547E-4B96-9E58-858DDDAE75D3} = {D38DDB2B-1138-4F45-8A6A-9499E880F620}
{C5C104A4-EE38-4D77-AC77-DF599FD5443A} = {D38DDB2B-1138-4F45-8A6A-9499E880F620}
EndGlobalSection
EndGlobal

View File

@ -1,4 +1,5 @@
using System;
#if NET45
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNet.Abstractions;
@ -6,13 +7,13 @@ using Microsoft.Owin;
namespace Microsoft.AspNet.Abstractions.Owin
{
public class OwinHttpContext : HttpContext
public class MicrosoftOwinHttpContext : HttpContext
{
private readonly IOwinContext _context;
private readonly HttpRequest _request;
private readonly HttpResponse _response;
public OwinHttpContext(IOwinContext context)
public MicrosoftOwinHttpContext(IOwinContext context)
{
_context = context;
_request = new OwinHttpRequest(this, context.Request);
@ -173,3 +174,4 @@ namespace Microsoft.AspNet.Abstractions.Owin
}
}
}
#endif

View File

@ -1,4 +1,5 @@
using System;
#if NET45
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.Abstractions.Owin;
@ -11,10 +12,11 @@ namespace Owin
{
app.Run(context =>
{
var httpContext = new OwinHttpContext(context);
var httpContext = new MicrosoftOwinHttpContext(context);
return handler(httpContext);
});
}
}
}
#endif

View File

@ -0,0 +1,199 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace Microsoft.AspNet.Abstractions.Owin
{
public class RawOwinHttpContext : HttpContext
{
private readonly HttpRequest _request;
private readonly HttpResponse _response;
public RawOwinHttpContext(IDictionary<string, object> env)
{
_request = new RawOwinHttpRequest(this, env);
_response = new RawOwinHttpResponse(this, env);
}
public override void Dispose()
{
}
public override object GetInterface(Type type)
{
return null;
}
public override HttpRequest Request
{
get { return _request; }
}
public override HttpResponse Response
{
get { return _response; }
}
public override void SetInterface(Type type, object instance)
{
}
private class RawOwinHttpRequest : HttpRequest
{
private HttpContext _context;
private readonly IDictionary<string, object> _env;
public RawOwinHttpRequest(HttpContext context, IDictionary<string, object> env)
{
_context = context;
_env = env;
}
public override Stream Body
{
get
{
return (Stream)_env["owin.ResponseBody"];
}
set
{
_env["owin.ResponseBody"] = value;
}
}
public override HttpContext HttpContext
{
get { return _context; }
}
public override PathString Path
{
get
{
return new PathString((string)_env["owin.RequestPath"]);
}
set
{
_env["owin.RequestPath"] = value.Value;
}
}
public override PathString PathBase
{
get
{
return new PathString((string)_env["owin.RequestPathBase"]);
}
set
{
_env["owin.RequestPathBase"] = value.Value;
}
}
public override QueryString QueryString
{
get
{
return new QueryString((string)_env["owin.RequestQueryString"]);
}
set
{
_env["owin.RequestQueryString"] = value.Value;
}
}
public override Uri Uri
{
get
{
// TODO: Implement this sometime
throw new NotImplementedException();
}
}
}
private class RawOwinHttpResponse : HttpResponse
{
private readonly HttpContext _context;
private readonly IDictionary<string, object> _env;
public RawOwinHttpResponse(HttpContext context, IDictionary<string, object> env)
{
_context = context;
_env = env;
}
public override Stream Body
{
get
{
return (Stream)_env["owin.ResponseBody"];
}
set
{
_env["owin.ResponseBody"] = value;
}
}
public override string ContentType
{
get
{
return GetHeader("Content-Type");
}
set
{
SetHeader("Content-Type", value);
}
}
public override HttpContext HttpContext
{
get { return _context; }
}
public override int StatusCode
{
get
{
return (int)_env["owin.ResponseStatusCode"];
}
set
{
_env["owin.ResponseStatusCode"] = value;
}
}
public override Task WriteAsync(string data)
{
var bytes = Encoding.UTF8.GetBytes(data);
return Body.WriteAsync(bytes, 0, bytes.Length);
}
private void SetHeader(string name, string value)
{
var headers = (IDictionary<string, string[]>)_env["owin.ResponseHeaders"];
headers[name] = new[] { value };
}
private string GetHeader(string name)
{
var headers = (IDictionary<string, string[]>)_env["owin.ResponseHeaders"];
string[] values;
if (headers.TryGetValue(name, out values) && values.Length > 0)
{
return values[0];
}
return null;
}
}
}
}

View File

@ -1,11 +1,15 @@
{
"version": "0.1-alpha-*",
"dependencies": {
"Owin": "1.0",
"Microsoft.Owin": "2.1.0",
"Microsoft.AspNet.Abstractions": ""
},
"configurations": {
"net45": { }
"net45": {
"dependencies": {
"Owin": "1.0",
"Microsoft.Owin": "2.1.0"
}
},
"k10": {}
}
}