public static void AddPaginationHeaders <T>(this IHeaderDictionary headers, PagedListResponse <T> response) where T : class, IDto { headers.Add("Pagination-CurrentPage", response.CurrentPage.ToString()); headers.Add("Pagination-TotalPages", response.TotalPages.ToString()); headers.Add("Pagination-PageSize", response.PageSize.ToString()); headers.Add("Pagination-TotalCount", response.TotalCount.ToString()); }
public static async Task <FlushResult> RenderAsync(IHeaderDictionary headerDictionary, PipeWriter pipeWriter, ReadOnlyMemory <byte> utf8String) { headerDictionary.Add(_headerServer); headerDictionary.Add(_headerContentType); headerDictionary.Add(new KeyValuePair <string, StringValues>("Content-Length", utf8String.Length.ToString())); return(await pipeWriter.WriteAsync(utf8String)); }
/// <summary> /// Adds x-ms-retry-after-ms and Retry-After response headers. The former is used by Cosmos DB and is expressed in ms, the latter is the W3C standard header and expressed in /// seconds. The seconds will be >= 1 unless the timespan is really 0. /// </summary> /// <param name="responseHeaders">The response headers</param> /// <param name="retryAfterTimeSpan">The time</param> public static void AddRetryAfterHeaders(this IHeaderDictionary responseHeaders, TimeSpan retryAfterTimeSpan) { responseHeaders.Add( KnownHeaders.RetryAfterMilliseconds, ((int)retryAfterTimeSpan.TotalMilliseconds).ToString(CultureInfo.InvariantCulture)); int retryAfterSeconds = retryAfterTimeSpan == default ? 0 : Math.Max(1, (int)Math.Round(retryAfterTimeSpan.TotalSeconds)); responseHeaders.Add( KnownHeaders.RetryAfter, retryAfterSeconds.ToString(CultureInfo.InvariantCulture)); }
protected void AddToHeader(string header, string value, IHeaderDictionary headerList) { if (!headerList.ContainsKey(header)) { headerList.Add(header, value); } }
public static void AddPaging( this IHeaderDictionary header, CollectionQueryParameters queryParameters, int totalCount, int maxPages = 500) { var skip = queryParameters.Skip ?? 0; var pageSize = queryParameters.Top ?? maxPages; int currentPage = (skip / pageSize) + 1; int totalPages = totalCount > 0 ? (int)Math.Ceiling(totalCount / (double)pageSize) : 0; var paginationHeader = new { currentPage, pageSize, totalCount, totalPages }; header.Add("X-Pagination", JsonConvert.SerializeObject(paginationHeader)); }
public static void AddHeaderIfNotInDict(this IHeaderDictionary headerDict, string key, string value) { if (!headerDict.ContainsKey(key)) { headerDict.Add(key, value); } }
private static void SetHeaderIfNotAlreadyPresent(IHeaderDictionary headers, string headerName, string[] headerValues) { if (!headers.ContainsKey(headerName)) { headers.Add(headerName, headerValues); } }