public HttpRequestHead(string head) { this.Content = head; string[] lines = head.Split('\n'); for(int i = 0; i < lines.Length; i++) { lines[i] = lines[i].TrimEnd('\r'); } string[] words = lines[0].Split(' '); switch(words[0].Trim().ToLower()) { case "get": Method = HttpMethod.GET; break; case "post": Method = HttpMethod.POST; break; case "put": Method = HttpMethod.PUT; break; case "patch": Method = HttpMethod.PATCH; break; case "delete": Method = HttpMethod.DELETE; break; case "head": Method = HttpMethod.HEAD; break; default: Method = HttpMethod.Unknown; Log.WriteLine(LType.Warning, "Unknwon method {0}", words[0]); break; } ClientInfo = new Dictionary<string, string>(); for(int i = 1; i < lines.Length; i++) { int colon = lines[i].IndexOf(':'); if (colon >= 0) { string name = lines[i].Substring(0, colon); string value = lines[i].Substring(colon + 1); if (!ClientInfo.ContainsKey(name)) ClientInfo[name] = value; } } if(ClientInfo.ContainsKey("Cookie")) { Cookies = HttpParse.ParseArgumentLine(ClientInfo["Cookie"], ';'); } UserAgent = ClientInfo.ContainsKey("User-Agent") ? ClientInfo["User-Agent"] : ""; Path = words[1]; if (Path.Contains('?')) { int pos = Path.IndexOf('?'); string argline = Path.Substring(pos + 1); Path = Path.Substring(0, pos); Get = HttpParse.ParseArgumentLine(argline); } else { Get = new Dictionary<string, string>(); } }
public RequestHandler(HttpServer server, HttpRequestHead head) { string fName; string argLine; int pos = head.Path.IndexOf('?'); this.Head = head; this.Server = server; if (pos >= 0) { fName = head.Path.Substring(0, pos); argLine = head.Path.Substring(pos + 1); } else { fName = head.Path; argLine = ""; } Args = HttpParse.ParseArgumentLine(argLine); FileName = fName; FileInfo = new FileInfo(Path.Combine(server.WwwDir, fName.TrimStart('/'))); }