private void AddIfMissing(HttpResponseHeaders headers, string header, string value) { if (!headers.Contains(header)) { headers.Add(header, value); } }
public static PagingInfo FindAndParsePagingInfo(HttpResponseHeaders responseHeaders) { // find the "X-Pagination" info in header if (responseHeaders.Contains("X-Pagination")) { var xPag = responseHeaders.First(ph => ph.Key == "X-Pagination").Value; // parse the value - this is a JSON-string. return JsonConvert.DeserializeObject<PagingInfo>(xPag.First()); } return null; }
public static PaginationInfo FindAndParsePaginationInfo(HttpResponseHeaders responseHeaders) { //find x-pagination if (responseHeaders.Contains("X-Pagination")) { var xPag = responseHeaders.First(rh => rh.Key == "X-Pagination").Value; return JsonConvert.DeserializeObject<PaginationInfo>(xPag.First()); } return null; }
public Pages(HttpResponseHeaders headers) { if (headers.Contains("Link")) { var links = headers.ParseLinkHeaders(new Uri("https://api.github.com/"), new LinkRegistry()); var nextLink = links.SingleOrDefault(link => link.Relation == "next"); var firstLink = links.SingleOrDefault(link => link.Relation == "first"); var lastLink = links.SingleOrDefault(link => link.Relation == "last"); var previousLink = links.SingleOrDefault(link => link.Relation == "prev"); if (nextLink != null) Next = Convert.ToInt32(nextLink.Target.ParseQueryString()["page"]); if (firstLink != null) First = Convert.ToInt32(firstLink.Target.ParseQueryString()["page"]); if (lastLink != null) Last = Convert.ToInt32(lastLink.Target.ParseQueryString()["page"]); if (previousLink != null) Previous = Convert.ToInt32(previousLink.Target.ParseQueryString()["page"]); } }
private void CheckResponseHeaders(HttpResponseHeaders headers) { var xHeader = ""; if (headers.Contains("X-Atmosphere-tracking-id")) { xHeader = headers.GetValues("X-Atmosphere-tracking-id").FirstOrDefault(); } if (!Equals(xHeader, X_Atmosphere_tracking_id)) { X_Atmosphere_tracking_id = xHeader; } }
public static int? ParseFirstValue(string header, HttpResponseHeaders headers) { IEnumerable<string> value = (headers.Contains(header) ? headers.GetValues(header) : null); return GetIntValue(value); }
public static string GetHeaderValue(string header, HttpResponseHeaders headers) { IEnumerable<string> value = (headers.Contains(header) ? headers.GetValues(header) : null); return GetStringValue(value); }