/// <summary>Parses elements with the given parser.</summary> /// <remarks>Parses elements with the given parser.</remarks> /// <param name="value">the header value to parse</param> /// <param name="parser">the parser to use, or <code>null</code> for default</param> /// <returns>array holding the header elements, never <code>null</code></returns> /// <exception cref="Org.Apache.Http.ParseException"></exception> public static HeaderElement[] ParseElements(string value, HeaderValueParser parser ) { Args.NotNull(value, "Value"); CharArrayBuffer buffer = new CharArrayBuffer(value.Length); buffer.Append(value); ParserCursor cursor = new ParserCursor(0, value.Length); return((parser != null ? parser : Org.Apache.Http.Message.BasicHeaderValueParser. Instance).ParseElements(buffer, cursor)); }
/// <exception cref="Apache.Http.Auth.MalformedChallengeException"></exception> protected internal override void ParseChallenge(CharArrayBuffer buffer, int pos, int len) { HeaderValueParser parser = BasicHeaderValueParser.Instance; ParserCursor cursor = new ParserCursor(pos, buffer.Length()); HeaderElement[] elements = parser.ParseElements(buffer, cursor); if (elements.Length == 0) { throw new MalformedChallengeException("Authentication challenge is empty"); } [email protected](); foreach (HeaderElement element in elements) { [email protected](element.GetName(), element.GetValue()); } }
// Gets the number of comments for a repo. private int GetCommentCount(ListParameters p, Task <HttpWebResponse> responseTask) { string linkHeader; using (HttpWebResponse response = responseTask.Result) { if (response.StatusCode == HttpStatusCode.NotFound) { SetResult(HttpNotFound()); return(0); } else if (response.StatusCode != HttpStatusCode.OK) { throw new ApplicationException("GitHub server returned " + response.StatusCode); } linkHeader = response.Headers["Link"]; } int commentCount = 0; if (!string.IsNullOrWhiteSpace(linkHeader)) { foreach (HeaderElement element in HeaderValueParser.ParseHeaderElements(linkHeader)) { string rel; if (element.TryGetParameterByName("rel", out rel) && rel == "last") { // HACK: parse the page number out of the URL that links to the last page; this will be the total number of comments Match match = Regex.Match(element.Name, @"[?&]page=(\d+)"); Debug.Assert(match.Success, "match.Success", "Page number could not be parsed from URL."); commentCount = int.Parse(match.Groups[1].Value); } } } return(commentCount); }
/// <summary>Creates a new instance of BasicHeaderElementIterator</summary> public BasicHeaderElementIterator(HeaderIterator headerIterator, HeaderValueParser parser) { this.headerIt = Args.NotNull(headerIterator, "Header iterator"); this.parser = Args.NotNull(parser, "Parser"); }