/// <summary> /// Contains information about all fields in an HTTP header. /// </summary> /// <param name="Header">HTTP Header.</param> /// <param name="VanityResources">Registered vanity resources.</param> public HttpHeader(string Header, VanityResources VanityResources) { HttpField Field; string Key; string KeyLower; string Value; int i; bool First = true; foreach (string Row in Header.Replace("\r\n", "\n").Replace("\r", "\n").Split('\n')) { if (First) { First = false; this.ParseFirstRow(Row, VanityResources); } else { i = Row.IndexOf(':'); if (i < 0) { continue; } Key = Row.Substring(0, i).Trim(); Value = Row.Substring(i + 1).Trim(); Field = this.ParseField(KeyLower = Key.ToLower(), Key, Value); this.fields[KeyLower] = Field; } } }
/// <summary> /// Contains information about all fields in an HTTP header. /// </summary> /// <param name="FirstRow">First row.</param> /// <param name="VanityResources">Registered vanity resources.</param> /// <param name="Headers">Headers.</param> public HttpHeader(string FirstRow, VanityResources VanityResources, params KeyValuePair <string, string>[] Headers) { HttpField Field; string KeyLower; this.ParseFirstRow(FirstRow, VanityResources); foreach (KeyValuePair <string, string> P in Headers) { Field = this.ParseField(KeyLower = P.Key.ToLower(), P.Key, P.Value); this.fields[KeyLower] = Field; } }
/// <summary> /// Parses the first row of an HTTP header. /// </summary> /// <param name="Row">First row.</param> /// <param name="VanityResources">Registered vanity resources.</param> protected override void ParseFirstRow(string Row, VanityResources VanityResources) { int i = Row.IndexOf(' '); if (i > 0) { this.method = Row.Substring(0, i).ToUpper(); int j = Row.LastIndexOf(' '); if (j > 0 && j < Row.Length - 5 && Row.Substring(j + 1, 5) == "HTTP/") { this.resourcePart = Row.Substring(i + 1, j - i - 1).Trim(); VanityResources?.CheckVanityResource(ref this.resourcePart); this.resource = this.resourcePart; if (CommonTypes.TryParse(Row.Substring(j + 6), out this.httpVersion)) { i = this.resource.IndexOf('?'); if (i >= 0) { this.queryString = this.resource.Substring(i + 1); this.resource = this.resource.Substring(0, i); i = this.queryString.IndexOf('#'); if (i >= 0) { this.fragment = this.queryString.Substring(i + 1); this.queryString = this.queryString.Substring(0, i); } this.query = new Dictionary <string, string>(StringComparer.CurrentCultureIgnoreCase); foreach (string Part in this.queryString.Split('&')) { i = Part.IndexOf('='); if (i < 0) { this.query[Part] = string.Empty; } else { this.query[Part.Substring(0, i)] = Part.Substring(i + 1); } } } else { i = this.resource.IndexOf('#'); if (i >= 0) { this.fragment = this.resource.Substring(i + 1); this.resource = this.resource.Substring(0, i); } } } else { this.httpVersion = -1; } } } }
/// <summary> /// Contains information about all fields in an HTTP request header. /// </summary> /// <param name="Method">HTTP Method.</param> /// <param name="Resource">Resource.</param> /// <param name="Version">HTTP Version.</param> /// <param name="UriScheme">URI scheme.</param> /// <param name="VanityResources">Registered vanity resource.</param> /// <param name="Headers">HTTP Header fields.</param> public HttpRequestHeader(string Method, string Resource, string Version, string UriScheme, VanityResources VanityResources, params KeyValuePair <string, string>[] Headers) : base(Method + " " + Resource + " HTTP/" + Version, VanityResources, Headers) { this.uriScheme = UriScheme; }
/// <summary> /// Contains information about all fields in an HTTP request header. /// </summary> /// <param name="Header">HTTP Header.</param> /// <param name="VanityResources">Registered vanity resources.</param> /// <param name="UriScheme">URI Scheme.</param> public HttpRequestHeader(string Header, VanityResources VanityResources, string UriScheme) : base(Header, VanityResources) { this.uriScheme = UriScheme; }
/// <summary> /// Parses the first row of an HTTP header. /// </summary> /// <param name="Row">First row.</param> /// <param name="VanityResources">Registered vanity resources.</param> protected abstract void ParseFirstRow(string Row, VanityResources VanityResources);