| | | 1 | | /******************************************************************************** |
| | | 2 | | * HttpRequestMessageExtensions.cs * |
| | | 3 | | * * |
| | | 4 | | * Author: Denes Solti * |
| | | 5 | | ********************************************************************************/ |
| | | 6 | | using System; |
| | | 7 | | using System.Collections.Frozen; |
| | | 8 | | using System.Collections.Generic; |
| | | 9 | | using System.Diagnostics; |
| | | 10 | | using System.Net.Http; |
| | | 11 | | |
| | | 12 | | namespace NanoRoute |
| | | 13 | | { |
| | | 14 | | /// <summary> |
| | | 15 | | /// <see cref="HttpResponseMessage"/> extensions. |
| | | 16 | | /// </summary> |
| | | 17 | | /// <example> |
| | | 18 | | /// <code> |
| | | 19 | | /// bool isContentHeader = HttpRequestMessage.ContentHeaders.Contains("Content-Type"); |
| | | 20 | | /// </code> |
| | | 21 | | /// </example> |
| | | 22 | | public static class HttpRequestMessageExtensions |
| | | 23 | | { |
| | | 24 | | [DebuggerBrowsable(DebuggerBrowsableState.Never)] |
| | 2 | 25 | | private static readonly FrozenSet<string> s_contentHeaders = new List<string> |
| | 2 | 26 | | { |
| | 2 | 27 | | "Allow", |
| | 2 | 28 | | "Content-Disposition", |
| | 2 | 29 | | "Content-Encoding", |
| | 2 | 30 | | "Content-Language", |
| | 2 | 31 | | "Content-Length", |
| | 2 | 32 | | "Content-Location", |
| | 2 | 33 | | "Content-MD5", |
| | 2 | 34 | | "Content-Range", |
| | 2 | 35 | | "Content-Type", |
| | 2 | 36 | | "Expires", |
| | 2 | 37 | | "Last-Modified" |
| | 2 | 38 | | }.ToFrozenSet(StringComparer.OrdinalIgnoreCase); |
| | | 39 | | |
| | | 40 | | extension(HttpRequestMessage) |
| | | 41 | | { |
| | | 42 | | /// <summary> |
| | | 43 | | /// Content header names. |
| | | 44 | | /// </summary> |
| | | 45 | | /// <example> |
| | | 46 | | /// <code> |
| | | 47 | | /// if (HttpRequestMessage.ContentHeaders.Contains(headerName)) |
| | | 48 | | /// request.Content!.Headers.TryAddWithoutValidation(headerName, values); |
| | | 49 | | /// </code> |
| | | 50 | | /// </example> |
| | 2 | 51 | | public static FrozenSet<string> ContentHeaders => s_contentHeaders; |
| | | 52 | | } |
| | | 53 | | } |
| | | 54 | | } |