internal void Init(HttpServer httpServer, IUserToken userToken) { this.HttpServer = httpServer; this.UserToken = userToken; }
internal void Init(HttpServer httpServer, IUserToken userToken, string requestStr) { this.HttpServer = httpServer; this.UserToken = userToken; var rows = Regex.Split(requestStr, Environment.NewLine); //Request URL & Method & Version var first = Regex.Split(rows[0], @"(\s+)") .Where(e => e.Trim() != string.Empty) .ToArray(); if (first.Length > 0) { this.Method = first[0]; } if (first.Length > 1) { this.Query = first[1]; if (this.Query.Contains("?")) { var qarr = this.Query.Split("?"); this.URL = qarr[0]; this.Params = GetRequestParameters(qarr[1]); } else { this.URL = this.Query; } var uarr = this.URL.Split("/"); if (long.TryParse(uarr[uarr.Length - 1], out long id)) { this.URL = this.URL.Substring(0, this.URL.LastIndexOf("/")); this.Params.Set("id", id.ToString()); } } if (first.Length > 2) { this.Protocols = first[2]; } //Request Headers this.Headers = GetRequestHeaders(rows); var bodyStr = GetRequestBody(rows); //Request "GET" if (this.Method == "GET") { if (!string.IsNullOrEmpty(bodyStr)) { this.Body = Encoding.UTF8.GetBytes(bodyStr); } } //Request "POST" if (this.Method == "POST") { if (!string.IsNullOrEmpty(bodyStr)) { this.Body = Encoding.UTF8.GetBytes(bodyStr); } var contentType = GetHeader(RequestHeaderType.ContentType); var isUrlencoded = contentType == @"application/x-www-form-urlencoded"; if (isUrlencoded) { this.Params = GetRequestParameters(bodyStr); } } }
internal void Init(HttpServer httpServer, IUserToken userToken, string htmlStr) { this.Request.Init(httpServer, userToken, htmlStr); this.Response.Init(httpServer, userToken); }