Permalink
Browse files

fix basic ordering and GET hang in sample code

  • Loading branch information...
1 parent fab5374 commit 5a174112522287ca35f77b8a864041d00e06db1e Chip Salzenberg committed Dec 12, 2011
Showing with 24 additions and 24 deletions.
  1. +24 −24 KayakExamples/Program.cs
View
@@ -73,28 +73,7 @@ class RequestDelegate : IHttpRequestDelegate
public void OnRequest(HttpRequestHead request, IDataProducer requestBody,
IHttpResponseDelegate response)
{
-
- if (request.Uri.StartsWith("/"))
- {
- var body = string.Format(
- "Hello world.\r\nHello.\r\n\r\nUri: {0}\r\nPath: {1}\r\nQuery:{2}\r\nFragment: {3}\r\n",
- request.Uri,
- request.Path,
- request.QueryString,
- request.Fragment);
-
- var headers = new HttpResponseHead()
- {
- Status = "200 OK",
- Headers = new Dictionary<string, string>()
- {
- { "Content-Type", "text/plain" },
- { "Content-Length", body.Length.ToString() },
- }
- };
- response.OnResponse(headers, new BufferedProducer(body));
- }
- else if (request.Uri.StartsWith("/bufferedecho"))
+ if (request.Method.ToUpperInvariant() == "POST" && request.Uri.StartsWith("/bufferedecho"))
{
// when you subecribe to the request body before calling OnResponse,
// the server will automatically send 100-continue if the client is
@@ -118,25 +97,46 @@ class RequestDelegate : IHttpRequestDelegate
// uh oh, what happens?
}));
}
- else if (request.Uri.StartsWith("/echo"))
+ else if (request.Method.ToUpperInvariant() == "POST" && request.Uri.StartsWith("/echo"))
{
var headers = new HttpResponseHead()
{
Status = "200 OK",
Headers = new Dictionary<string, string>()
{
{ "Content-Type", "text/plain" },
- { "Content-Length", request.Headers["Content-Length"] },
{ "Connection", "close" }
}
};
+ if (request.Headers.ContainsKey("Content-Length"))
+ headers.Headers["Content-Length"] = request.Headers["Content-Length"];
// if you call OnResponse before subscribing to the request body,
// 100-continue will not be sent before the response is sent.
// per rfc2616 this response must have a 'final' status code,
// but the server does not enforce it.
response.OnResponse(headers, requestBody);
}
+ else if (request.Uri.StartsWith("/"))
+ {
+ var body = string.Format(
+ "Hello world.\r\nHello.\r\n\r\nUri: {0}\r\nPath: {1}\r\nQuery:{2}\r\nFragment: {3}\r\n",
+ request.Uri,
+ request.Path,
+ request.QueryString,
+ request.Fragment);
+
+ var headers = new HttpResponseHead()
+ {
+ Status = "200 OK",
+ Headers = new Dictionary<string, string>()
+ {
+ { "Content-Type", "text/plain" },
+ { "Content-Length", body.Length.ToString() },
+ }
+ };
+ response.OnResponse(headers, new BufferedProducer(body));
+ }
else
{
var responseBody = "The resource you requested ('" + request.Uri + "') could not be found.";

0 comments on commit 5a17411

Please sign in to comment.