public void SetProperties(HttpResponseHeaders headers) { var properties = this.GetType().GetTypeInfo().DeclaredProperties; foreach (var prop in properties.Where(prop => headers.Any(h => h.Key == prop.Name))) { var value = headers.First(h => NetNamingMapper.GetPropertyName(h.Key) == prop.Name).Value; if (value == null) { continue; } if (value.Count() == 1) { prop.SetValue(this, value.FirstOrDefault()); } else { try { prop.SetValue(this, value.FirstOrDefault()); } catch (Exception) { // do nothing } } } }
private Guid GetEntityIdFromResponse(string fullUrl, HttpResponseMessage response) { HttpResponseHeaders headers = response.Headers; string headerValue = headers.First(h => h.Key.Contains("OData-EntityId")).Value.First(); return(new Guid(headerValue.Split('(').Last().Split(')')[0])); }
private static string ParseXsrfTokenFromHeaders(HttpResponseHeaders headers) { var xsrfHeader = headers.First(h => h.Key.Equals("Set-Cookie")).Value.First(v => v.Contains("XSRF-TOKEN")); var regex = new Regex("(XSRF-TOKEN=|;)"); var cookieStrings = regex.Split(xsrfHeader.Trim()); return(cookieStrings[2]); }
public void SetProperties(HttpResponseHeaders headers) { var properties = this.GetType().GetProperties().Where(p => p.GetValue(this) != null); foreach (var prop in properties.Where(prop => headers.Any(h => h.Key == prop.Name))) { prop.SetValue(this, headers.First(h => NetNamingMapper.GetPropertyName(h.Key) == prop.Name)); } }
public static string GetSingleHeaderValue(HttpResponseHeaders responseHeaders, string keyName) { if (responseHeaders.Contains(keyName)) { return(responseHeaders.First(ph => ph.Key == keyName).Value.First()); } return(null); }
public static PagingInfo FindAndParsePagingInfo(HttpResponseHeaders respHeader) { //find x-pagination info form http header if (respHeader.Contains("x-pagination")) { var xPageInfo = respHeader.First(ph => ph.Key == "x-pagination").Value; return(JsonConvert.DeserializeObject <PagingInfo>(xPageInfo.First())); } return(null); }
public static PagingInfo FindAndParsePagingInfo(HttpResponseHeaders responseHeaders) { //added in controller if (responseHeaders.Contains("X-Pagination")) { var xPag = responseHeaders.First(ph => ph.Key == "X-Pagination").Value; return(JsonConvert.DeserializeObject <PagingInfo>(xPag.First())); } return(null); }
private string ReadETagHeader(HttpResponseHeaders responseHeaders) { if (responseHeaders.Contains("ETag")) { var etagHeaderValue = responseHeaders.First(h => h.Key == "ETag").Value; return(etagHeaderValue.First()); } return(null); }
private PageInfo ReadPageInfroFromHeader(HttpResponseHeaders responseHeaders) { if (responseHeaders.Contains("X-PageInfo")) { var pageHeaderValue = responseHeaders.First(h => h.Key == "X-PageInfo").Value; return(JsonConvert.DeserializeObject <PageInfo>(pageHeaderValue.First())); } return(null); }
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 PagingInfoDto FindAndParsePagingInfo(this 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(JsonSerializer.Deserialize <PagingInfoDto>(xPag.First(), new JsonSerializerOptions() { WriteIndented = true, PropertyNameCaseInsensitive = true, PropertyNamingPolicy = JsonNamingPolicy.CamelCase, DictionaryKeyPolicy = JsonNamingPolicy.CamelCase })); } return(null); }
/// <summary> /// Tries the get session token. /// </summary> /// <param name="headers">The headers from the server response.</param> /// <param name="value">The value of the session token.</param> /// <returns><see langword="true" /> if a token was found, <see langword="false" /> otherwise.</returns> private bool TryGetSessionToken(HttpResponseHeaders headers, out string value) { value = null; if (headers.Any(x => x.Key == "Set-Cookie")) { var sessionId = headers .First(x => x.Key == "Set-Cookie").Value .ToList() .FirstOrDefault(x => x.Contains("JSESSION")); if (sessionId != null) { value = sessionId.Split(';')[0]; return(true); } } return(false); }
public static string GetFirstValue(this HttpResponseHeaders headers, string key) { return(headers.First(x => x.Key.ToLower() == key.ToLower()).Value.First()); }