Пример #1
0
        public void DispatchRequest(HttpRequest HttpRequest)
        {
            string RequestUri;

            if (!HttpRequest.Enviroment.TryGetValue("REQUEST_URI", out RequestUri))
            {
                RequestUri = "";
            }

            foreach (var Pair in Criterias)
            {
                if (Pair.Item1.IsMatch(RequestUri))
                {
                    Pair.Item2.DispatchRequest(HttpRequest);
                    return;
                }
            }

            throw (new Exception(String.Format("No criteria for '{0}'", RequestUri)));
        }
Пример #2
0
        protected override void HandleHttpRequest(HttpRequest HttpRequest)
        {
            if (HttpRequest.Post.ContainsKey("Title") && HttpRequest.Post.ContainsKey("Body"))
            {
                Posts.Add(new Post()
                {
                    Title = HttpRequest.Post["Title"],
                    Body = HttpRequest.Post["Body"],
                });
            }

            HttpRequest.Output.Write(TemplateFactory.GetTemplateCodeByFile("Test.html").RenderToString(new TemplateScope(new Dictionary<String, dynamic>()
            {
                { "Count", Count++ },
                { "Params", HttpRequest.Enviroment },
                { "Posts", Posts },
                { "POST", HttpRequest.Post },
            })));

            HttpRequest.Output.WriteLine("<pre>");
            foreach (var Param in HttpRequest.Enviroment)
            {
                HttpRequest.Output.WriteLine("{0}: {1}", Param.Key, Param.Value);
            }
            HttpRequest.Output.WriteLine("</pre>");

            /*
            if (HttpRequest.StdinBytes.Length > 0)
            {
                File.WriteAllBytes("Stdin.bin", HttpRequest.StdinBytes);
            }
            HttpRequest.Output.WriteLine(HttpRequest.Stdin);
            */

            HttpRequest.OutputDebug = true;
        }
Пример #3
0
		sealed protected override void HandleFascgiRequest(FastcgiRequest FastcgiRequest)
		{
			FastcgiRequest.StdinStream.SetPosition(0);
			Dictionary<string, string> Post = new Dictionary<string, string>();
			Dictionary<string, HttpFile> Files = new Dictionary<string, HttpFile>();
			bool HandledPost = false;

			//foreach (var Param in FastcgiRequest.Params) Console.WriteLine(Param);

			HttpHeader ContentType = new HttpHeader("Content-Type", FastcgiRequest.GetParam("CONTENT_TYPE"));

			var ContentTypeParts = ContentType.ParseValue("type");
			if (ContentTypeParts["type"] == "multipart/form-data")
			{
				string Boundary = ContentTypeParts["boundary"];
				//File.WriteAllBytes("Boundary.bin", Encoding.ASCII.GetBytes(Boundary));
				MultipartDecoder MultipartDecoder = new MultipartDecoder(FastcgiRequest.StdinStream, "--" + Boundary);
				var Parts = MultipartDecoder.Parse();

				foreach (var Part in Parts)
				{
					if (Part.IsFile)
					{
						Files.Add(Part.Name, new HttpFile()
						{
							TempFile = new FileInfo(Part.TempFilePath),
							FileName = Part.FileName,
							ContentType = Part.ContentType,
						});
					}
					else
					{
						Post[Part.Name] = Part.Content;
					}

					HandledPost = true;
				}
			}

			if (!HandledPost)
			{
				Post = HttpUtils.ParseUrlEncoded(Encoding.UTF8.GetString(FastcgiRequest.StdinStream.ReadAll()));
			}

			//CONTENT_TYPE: multipart/form-data; boundary=----WebKitFormBoundaryIMw3ByBOPx38V6Bd

			using (var OutputTextWriter = new StringWriter())
			{
				var HttpRequest = new HttpRequest()
				{
					Headers = new HttpHeaderList(),
					Output = OutputTextWriter,
					Enviroment = FastcgiRequest.Params,
					StdinStream = FastcgiRequest.StdinStream,
					Post = Post,
					Files = Files,
					Get = HttpUtils.ParseUrlEncoded(FastcgiRequest.GetParam("QUERY_STRING")),
					Cookies = new Dictionary<String, String>(),
				};

				HttpRequest.Headers.Set("X-Dynamic", "C#");
				HttpRequest.SetContentType("text/html", Encoding.UTF8);

				var Stopwatch = new Stopwatch();
				Stopwatch.Start();
				{
					HandleHttpRequest(HttpRequest);
				}
				Stopwatch.Stop();
				double GenerationTime = (double)Stopwatch.ElapsedTicks / (double)Stopwatch.Frequency;

				HttpRequest.Headers.Set("X-GenerationTime", String.Format("{0}", GenerationTime.ToString("F8")));

				using (var Stdout = new StreamWriter(FastcgiRequest.StdoutStream))
				{
					HttpRequest.Headers.WriteTo(Stdout);
				}

				using (var Stdout = new StreamWriter(FastcgiRequest.StdoutStream, HttpRequest.Encoding))
				{
					Stdout.Write(OutputTextWriter.ToString());
					if (HttpRequest.OutputDebug)
					{
						Stdout.WriteLine("<pre>");
						Stdout.WriteLine("Generation Time: {0}", GenerationTime);
						Stdout.WriteLine("</pre>");
					}
				}
			}
		}
Пример #4
0
		protected abstract void HandleHttpRequest(HttpRequest HttpRequest);