public void TestMethod1() { HttpHeader ContentType = new HttpHeader("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundaryIMw3ByBOPx38V6Bd"); var ContentTypeParts = ContentType.ParseValue("type"); CollectionAssert.AreEqual(new Dictionary<string, string>() { { "type", "multipart/form-data" }, { "boundary", "----WebKitFormBoundaryIMw3ByBOPx38V6Bd" }, }, ContentTypeParts); ContentType = new HttpHeader("Content-Type", "multipart/form-data; boundary=\"----WebKitFormBoundaryIMw3ByBOPx38V6Bd\""); ContentTypeParts = ContentType.ParseValue("type"); CollectionAssert.AreEqual(new Dictionary<string, string>() { { "type", "multipart/form-data" }, { "boundary", "----WebKitFormBoundaryIMw3ByBOPx38V6Bd" }, }, ContentTypeParts); }
public bool TryGetOne(String Name, out HttpHeader HttpHeader) { String NormalizedName = HttpHeader.GetNormalizedName(Name); List<HttpHeader> List; if (Headers.TryGetValue(NormalizedName, out List)) { if (List.Count > 0) { HttpHeader = List[0]; return true; } else { HttpHeader = null; return false; } } HttpHeader = null; return false; }
protected HttpHeaderList _Set(String _Name, String _Value, bool Append = false, bool Overwrite = true) { var HttpHeader = new HttpHeader(_Name, _Value); if (Append) { if (!Headers.ContainsKey(HttpHeader.NormalizedName)) { Headers[HttpHeader.NormalizedName] = new List<HttpHeader>(); } Headers[HttpHeader.NormalizedName].Add(HttpHeader); } else { if (Overwrite || !Headers.ContainsKey(HttpHeader.NormalizedName)) { Headers[HttpHeader.NormalizedName] = new List<HttpHeader>() { HttpHeader }; } } return this; }
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>"); } } } }