-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added *very simple* AspNet handler and sample. WARNING: The AspNet st…
…uff is barely specced because HttpRequest/HttpResponse don't like to be modified and I haven't gotten around to mocking them.
- Loading branch information
remi
committed
Dec 12, 2010
1 parent
ef22b6f
commit 2b90626
Showing
21 changed files
with
736 additions
and
375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Web; | ||
using System.Collections.Generic; | ||
using Owin; | ||
|
||
namespace AspNetAppSample { | ||
public class MyApp : AspNetApplication, IHttpHandler { | ||
public override IResponse Call(IRequest rawRequest) { | ||
Request request = new Request(rawRequest); | ||
Response response = new Response(); | ||
|
||
response.ContentType = "text/plain"; | ||
response.Write("{0} {1}\n\n", request.Method, request.Uri); | ||
|
||
foreach (KeyValuePair<string,string> param in request.Params) | ||
response.Write("Param {0} = {1}\n", param.Key, param.Value); | ||
|
||
foreach (KeyValuePair<string,IEnumerable<string>> header in request.Headers) | ||
foreach (string value in header.Value) | ||
response.Write("Header {0} = {1}\n", header.Key, value); | ||
|
||
return response; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0"?> | ||
<configuration> | ||
<system.web> | ||
<httpHandlers> | ||
<add verb="*" path="*" type="AspNetAppSample.MyApp, AspNetApp" /> | ||
</httpHandlers> | ||
</system.web> | ||
</configuration> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 11.00 | ||
# Visual Studio 2010 | ||
Project("{911E67C6-3D85-4FCE-B560-20A9C3E3FF48}") = "WebDev.WebServer20", "WebDev.WebServer20.EXE", "{55ED36A7-C0E7-4308-BC8C-D54BBD9C43B4}" | ||
ProjectSection(DebuggerProjectSystem) = preProject | ||
PortSupplier = 00000000-0000-0000-0000-000000000000 | ||
Executable = C:\Users\rtaylor\projects\remi\Owin.Common\examples\simple-aspnet-application\WebDev.WebServer20.EXE | ||
RemoteMachine = EMWL089 | ||
StartingDirectory = C:\Users\rtaylor\projects\remi\Owin.Common\examples\simple-aspnet-application | ||
Environment = Default | ||
LaunchingEngine = 00000000-0000-0000-0000-000000000000 | ||
LaunchSQLEngine = No | ||
AttachLaunchAction = No | ||
EndProjectSection | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|x86 = Debug|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{55ED36A7-C0E7-4308-BC8C-D54BBD9C43B4}.Debug|x86.ActiveCfg = Debug|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@echo off | ||
mkdir Bin | ||
xcopy ..\..\bin\Debug\*.dll . | ||
C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe /target:library AspNetApp.cs /r:owin.dll /r:Owin.Common.dll /r:Owin.Handlers.AspNet.dll | ||
xcopy *.dll Bin\ | ||
pause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
WebDev.WebServer20.EXE /port:8080 /path:"C:\Users\rtaylor\projects\remi\Owin.Common\examples\simple-aspnet-application" | ||
pause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
using System; | ||
using System.Web; | ||
using NUnit.Framework; | ||
|
||
namespace Owin.Handlers.Specs { | ||
|
||
[TestFixture] | ||
public class AspNetRequestSpec { | ||
|
||
AspNetRequest request; | ||
|
||
HttpRequest GetRequest() { | ||
return GetRequest("/"); | ||
} | ||
HttpRequest GetRequest(string uri) { | ||
return GetRequest("GET", uri); | ||
} | ||
HttpRequest GetRequest(string method, string uri) { | ||
return GetRequest(method, uri, ""); | ||
} | ||
HttpRequest GetRequest(string method, string uri, string queryStrings) { | ||
string url = uri; | ||
if (uri.StartsWith("/")) | ||
url = "http://localhost" + uri; | ||
if (queryStrings != "") | ||
url += "?" + queryStrings; | ||
HttpRequest request = new HttpRequest("", url, queryStrings); | ||
request.RequestType = method; | ||
return request; | ||
} | ||
|
||
[SetUp] | ||
public void Before() { request = null; } | ||
|
||
[TearDown] | ||
public void After() { | ||
if (request != null) | ||
Owin.Lint.Validate(request); | ||
} | ||
|
||
[TestFixture] | ||
public class Uri_Method_and_QueryStrings : AspNetRequestSpec { | ||
|
||
[Test] | ||
public void Method_gets_set_using_Request_RequestType() { | ||
request = new AspNetRequest(GetRequest()); | ||
Assert.That(request.Method, Is.EqualTo("GET")); | ||
|
||
request = new AspNetRequest(GetRequest("POST", "/")); | ||
Assert.That(request.Method, Is.EqualTo("POST")); | ||
} | ||
|
||
[Test] | ||
public void Uri_gets_set_using_Request_Path() { | ||
request = new AspNetRequest(GetRequest("/")); | ||
Assert.That(request.Uri, Is.EqualTo("/")); | ||
|
||
request = new AspNetRequest(GetRequest("/foo/bar")); | ||
Assert.That(request.Uri, Is.EqualTo("/foo/bar")); | ||
} | ||
|
||
[Test] | ||
public void Uri_includes_query_strings_from_QueryString() { | ||
request = new AspNetRequest(GetRequest("GET", "/", "")); | ||
Assert.That(request.Uri, Is.EqualTo("/")); | ||
|
||
request = new AspNetRequest(GetRequest("GET", "/", "foo=bar")); | ||
Assert.That(request.Uri, Is.EqualTo("/?foo=bar")); | ||
} | ||
|
||
[Test] | ||
public void Uri_gets_QueryString_from_QueryString() { | ||
request = new AspNetRequest(GetRequest("GET", "/", "")); | ||
Assert.That(request.QueryString, Is.EqualTo("")); | ||
|
||
request = new AspNetRequest(GetRequest("GET", "/", "foo=bar")); | ||
Assert.That(request.QueryString, Is.EqualTo("foo=bar")); | ||
} | ||
} | ||
|
||
[TestFixture] | ||
public class Items : AspNetRequestSpec { | ||
|
||
[Test] | ||
public void owin_base_path_gets_set_to_Request_ApplicationPath() { | ||
HttpRequest native = GetRequest(); | ||
Assert.That(native.ApplicationPath, Is.Null); // it returns null and we can't change it | ||
|
||
request = new AspNetRequest(native); | ||
Assert.That(request.BasePath, Is.EqualTo("")); | ||
} | ||
|
||
[Test] | ||
public void owin_server_name_gets_set_to_Request_Url_Host() { | ||
request = new AspNetRequest(GetRequest("http://localhost/")); | ||
Assert.That(request.Host, Is.EqualTo("localhost")); | ||
|
||
request = new AspNetRequest(GetRequest("http://google.com/")); | ||
Assert.That(request.Host, Is.EqualTo("google.com")); | ||
} | ||
|
||
[Test] | ||
public void owin_server_port_gets_set_to_Request_Url_Port() { | ||
request = new AspNetRequest(GetRequest("http://localhost/")); | ||
Assert.That(request.Port, Is.EqualTo(80)); | ||
|
||
request = new AspNetRequest(GetRequest("http://localhost:1234/")); | ||
Assert.That(request.Port, Is.EqualTo(1234)); | ||
} | ||
|
||
[Test] | ||
public void owin_request_protocol_gets_set_to_HTTP_1_1() { | ||
request = new AspNetRequest(GetRequest()); | ||
Assert.That(request.Protocol, Is.EqualTo("HTTP/1.1")); // not sure if we can detect this - just use 1.1 | ||
} | ||
|
||
[Test] | ||
public void owin_url_scheme_gets_set_using_scheme_seen_in_Request_Url_Scheme() { | ||
request = new AspNetRequest(GetRequest("http://localhost/")); | ||
Assert.That(request.Scheme, Is.EqualTo("http")); | ||
|
||
request = new AspNetRequest(GetRequest("https://localhost/")); | ||
Assert.That(request.Scheme, Is.EqualTo("https")); | ||
} | ||
|
||
[Test] | ||
public void owin_remote_endpoint_gets_set_using_Request_UserHostAddress_and_Port() { | ||
HttpRequest native = GetRequest(); // unfortunately, we can't set this :/ | ||
Assert.That(native.UserHostAddress, Is.Null); | ||
|
||
// if it's null, we'll do 0.0.0.0:80 ... cause, why not? | ||
request = new AspNetRequest(native); | ||
Assert.That(request.IPEndPoint.ToString(), Is.EqualTo("0.0.0.0:80")); | ||
|
||
// if we change the port, it should change the port in the end point | ||
request = new AspNetRequest(GetRequest("http://localhost:1234/foo")); | ||
Assert.That(request.IPEndPoint.ToString(), Is.EqualTo("0.0.0.0:1234")); | ||
} | ||
} | ||
|
||
[TestFixture] | ||
public class Headers : AspNetRequestSpec { | ||
|
||
[Test][Ignore("If you try to modify HttpRequest.Headers it throws a PlatformNotSupportedException")] | ||
public void All_environment_variables_become_headers() { | ||
} | ||
} | ||
|
||
[TestFixture] | ||
public class Body : AspNetRequestSpec { | ||
|
||
[Test][Ignore("If you try to modify HttpRequest.Form it throws NotSupportedException : Collection is read-only")] | ||
public void Can_get_posted_params() { | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.IO; | ||
using System.Web; | ||
using System.Text; | ||
using System.Collections.Generic; | ||
using NUnit.Framework; | ||
|
||
namespace Owin.Handlers.Specs { | ||
|
||
[TestFixture] | ||
public class AspNetResponseSpec { | ||
|
||
[Test][Ignore("Trying to get HttpResponse.Headers blows up with PlatformNotSupportedException : This operation requires IIS integrated pipeline mode")] | ||
public void Can_convert_IResponse_into_HttpResponse_given_an_HttpResponse_reference() { | ||
TextWriter body = new StringWriter(); | ||
HttpResponse response = new HttpResponse(body); | ||
|
||
// check Response defaults | ||
Assert.That(response.Status, Is.EqualTo("200 OK")); | ||
Assert.That(body.ToString(), Is.EqualTo("")); | ||
Assert.That(response.Headers.Count, Is.EqualTo(0)); | ||
|
||
AspNet.WriteResponse(response, new Response(404, "Oops, not found!", new Dictionary<string,string>{{"content-type","text/plains"}})); | ||
|
||
// check that WriteResponse() updated the response | ||
Assert.That(response.Status, Is.EqualTo("404 NotFound")); | ||
Assert.That(body.ToString(), Is.EqualTo("Oops, not found!")); | ||
Assert.That(response.Headers.Count, Is.EqualTo(1)); | ||
Assert.That(response.Headers["content-type"], Is.EqualTo("text/plain")); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.