Example #1
0
            private static void Reply(IHttpResponseDelegate response, String contentType, byte[] data, bool allowCache, String status, Dictionary <String, String> headers)
            {
                var body = new BufferedBody(data);

                headers = headers ?? new Dictionary <string, string>();
                headers["Content-Type"]   = contentType;
                headers["Content-Length"] = body.Length.ToString();

                if (allowCache)
                {
                    headers["Cache-Control"] = "max-age=31556926";
                }
                response.OnResponse(new HttpResponseHead
                {
                    Status  = status ?? "200 OK",
                    Headers = headers
                }, body);
            }
Example #2
0
            public void OnRequest(HttpRequestHead request, IDataProducer requestBody,
             IHttpResponseDelegate response)
            {
                if(request.Uri == "/favicon.ico") return;

                var actionName = request.Uri.Substring(1);
                var action = Repository.GetAction(actionName);
                action.Command.Run();
                var headers = new HttpResponseHead()
                                          {
                                             Status = "200 OK",
                                             Headers = new Dictionary<string, string>()
                                                          {
                                                             { "Content-Type", "text/plain" },
                                                             { "Content-Length", "20" },
                                                          }
                                          };
                IDataProducer body = new BufferedBody("Hello world.\r\nHello.");
                response.OnResponse(headers, body);
            }
Example #3
0
            public void OnRequest(HttpRequestHead request, IDataProducer requestBody,
                IHttpResponseDelegate response)
            {
                HttpResponseHead headers;
                IDataProducer body = null;

                if (request.Uri == "/")
                {
                    headers = new HttpResponseHead()
                    {
                        Status = "200 OK",
                        Headers = new Dictionary<string, string>()
                    {
                        { "Content-Type", "text/plain" },
                        { "Content-Length", "20" },
                    }
                    };
                    body = new BufferedBody("Hello world.\r\nHello.");
                }
                else if (request.Uri == "/echo")
                {
                    headers = new HttpResponseHead()
                    {
                        Status = "200 OK",
                        Headers = new Dictionary<string, string>()
                    {
                        { "Content-Type", "text/plain" },
                        { "Content-Length", request.Headers["Content-Length"] },
                        { "Connection", "close" }
                    }
                    };
                    body = requestBody;
                }
                else
                {
                    var responseBody = "The resource you requested ('" + request.Uri + "') could not be found.";
                    headers = new HttpResponseHead()
                    {
                        Status = "404 Not Found",
                        Headers = new Dictionary<string, string>()
                    {
                        { "Content-Type", "text/plain" },
                        { "Content-Length", responseBody.Length.ToString() }
                    }
                    };
                    body = new BufferedBody(responseBody);
                }

                response.OnResponse(headers, body);
            }