private List<HeaderValue> ParseQuotedHeader(string str) { List<HeaderValue> result = new List<HeaderValue>(); if (str != null) { int idx = 0; // Read Type (Basic|Digest) string type = str.Read(ref idx, (ch) => !char.IsWhiteSpace(ch) && !char.IsControl(ch)).TrimAndLower(); result.Add(new HeaderValue(type)); // process the rest of the text while (idx < str.Length) { // Read key string key = str.Read(ref idx, '=').TrimAndLower(); HeaderValue qp = new HeaderValue(key); // Skip any white space str.SkipWhiteSpace(ref idx); qp.Value = str.ReadPossibleQuotedText(ref idx); result.Add(qp); } } return result; }
public bool TryGet(string value, out HeaderValue @param) { @param = null; for (int i = 0; i < Values.Count; ++i) if (string.CompareOrdinal(Values[i].Key, value) == 0) { @param = Values[i]; return true; } return false; }
public bool TryGet(string value, out HeaderValue @param) { @param = null; for (int i = 0; i < Values.Count; ++i) { if (string.CompareOrdinal(Values[i].Key, value) == 0) { @param = Values[i]; return(true); } } return(false); }
public bool TryGetOption(string key, out HeaderValue option) { option = null; if (Options == null || Options.Count == 0) return false; for (int i = 0; i < Options.Count; ++i) if (String.Equals(Options[i].Key, key, StringComparison.OrdinalIgnoreCase)) { option = Options[i]; return true; } return false; }
private void ParseImplementation(string headerStr, ref int pos, bool isOptionIsAnOption) { // According to https://tools.ietf.org/html/rfc7234#section-5.2.1.1 // Max-Age has a form "max-age=5", but some (imgur.com specifically) sends it as "max-age:5" string key = headerStr.Read(ref pos, (ch) => ch != ';' && ch != '=' && ch != ':' && ch != ',', true); this.Key = key; char?skippedChar = headerStr.Peek(pos - 1); bool isValue = skippedChar == '=' || skippedChar == ':'; bool isOption = isOptionIsAnOption && skippedChar == ';'; while ((skippedChar != null && isValue || isOption) && pos < headerStr.Length) { if (isValue) { string value = headerStr.ReadPossibleQuotedText(ref pos); this.Value = value; } else if (isOption) { HeaderValue option = new HeaderValue(); option.ParseImplementation(headerStr, ref pos, false); if (this.Options == null) { this.Options = new List <HeaderValue>(); } this.Options.Add(option); } if (!isOptionIsAnOption) { return; } skippedChar = headerStr.Peek(pos - 1); isValue = skippedChar == '='; isOption = isOptionIsAnOption && skippedChar == ';'; } }
public bool TryGetOption(string key, out HeaderValue option) { option = null; if (Options == null || Options.Count == 0) { return(false); } for (int i = 0; i < Options.Count; ++i) { if (String.Equals(Options[i].Key, key, StringComparison.OrdinalIgnoreCase)) { option = Options[i]; return(true); } } return(false); }
private List <HeaderValue> Parse(string headerStr) { List <HeaderValue> list = new List <HeaderValue>(); int pos = 0; try { while (pos < headerStr.Length) { HeaderValue item = new HeaderValue(); item.Parse(headerStr, ref pos); list.Add(item); } } catch (Exception exception) { HTTPManager.Logger.Exception("HeaderParser - Parse", headerStr, exception); } return(list); }
private void ParseImplementation(string headerStr, ref int pos, bool isOptionIsAnOption) { string key = headerStr.Read(ref pos, (ch) => ch != ';' && ch != '=' && ch != ',', true); this.Key = key; char?skippedChar = headerStr.Peek(pos - 1); bool isValue = skippedChar == '='; bool isOption = isOptionIsAnOption && skippedChar == ';'; while (skippedChar != null && isValue || isOption) { if (isValue) { string value = headerStr.ReadPossibleQuotedText(ref pos); this.Value = value; } else if (isOption) { HeaderValue option = new HeaderValue(); option.ParseImplementation(headerStr, ref pos, false); if (this.Options == null) { this.Options = new List <HeaderValue>(); } this.Options.Add(option); } if (!isOptionIsAnOption) { return; } skippedChar = headerStr.Peek(pos - 1); isValue = skippedChar == '='; isOption = isOptionIsAnOption && skippedChar == ';'; } }
private List <HeaderValue> Parse(string headerStr) { List <HeaderValue> result = new List <HeaderValue>(); int pos = 0; try { while (pos < headerStr.Length) { HeaderValue current = new HeaderValue(); current.Parse(headerStr, ref pos); result.Add(current); } } catch (System.Exception ex) { HTTPManager.Logger.Exception("HeaderParser - Parse", headerStr, ex); } return(result); }
private List<HeaderValue> Parse(string headerStr) { List<HeaderValue> result = new List<HeaderValue>(); int pos = 0; try { while (pos < headerStr.Length) { HeaderValue current = new HeaderValue(); current.Parse(headerStr, ref pos); result.Add(current); } } catch(System.Exception ex) { HTTPManager.Logger.Exception("HeaderParser - Parse", headerStr, ex); } return result; }
private void ParseImplementation(string headerStr, ref int pos, bool isOptionIsAnOption) { string key = headerStr.Read(ref pos, (ch) => ch != ';' && ch != '=' && ch != ',', true); this.Key = key; char? skippedChar = headerStr.Peek(pos - 1); bool isValue = skippedChar == '='; bool isOption = isOptionIsAnOption && skippedChar == ';'; while (skippedChar != null && isValue || isOption) { if (isValue) { string value = headerStr.ReadPossibleQuotedText(ref pos); this.Value = value; } else if (isOption) { HeaderValue option = new HeaderValue(); option.ParseImplementation(headerStr, ref pos, false); if (this.Options == null) this.Options = new List<HeaderValue>(); this.Options.Add(option); } if (!isOptionIsAnOption) return; skippedChar = headerStr.Peek(pos - 1); isValue = skippedChar == '='; isOption = isOptionIsAnOption && skippedChar == ';'; } }
//deflate, gzip, x-gzip, identity, *;q=0 internal static List<HeaderValue> ParseQualityParams(this string str) { List<HeaderValue> result = new List<HeaderValue>(); if (str == null) return result; int idx = 0; while (idx < str.Length) { string key = str.Read(ref idx, (ch) => ch != ',' && ch != ';').TrimAndLower(); HeaderValue qp = new HeaderValue(key); if (str[idx - 1] == ';') { str.Read(ref idx, '=', false); qp.Value = str.Read(ref idx, ','); } result.Add(qp); } return result; }
//public, max-age=2592000 internal static List<HeaderValue> ParseOptionalHeader(this string str) { List<HeaderValue> result = new List<HeaderValue>(); if (str == null) return result; int idx = 0; // process the rest of the text while (idx < str.Length) { // Read key string key = str.Read(ref idx, (ch) => ch != '=' && ch != ',').TrimAndLower(); HeaderValue qp = new HeaderValue(key); if (str[idx - 1] == '=') qp.Value = str.ReadPossibleQuotedText(ref idx); result.Add(qp); } return result; }