| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System.Globalization; |
| | 5 | |
|
| | 6 | | namespace Azure.Core |
| | 7 | | { |
| | 8 | | internal static class ConditionalRequestOptionsExtensions |
| | 9 | | { |
| | 10 | | public static void ApplyHeaders(Request request, MatchConditions options) |
| | 11 | | { |
| 156 | 12 | | if (options.IfMatch.HasValue) |
| | 13 | | { |
| 32 | 14 | | string value = options.IfMatch.Value == ETag.All ? |
| 32 | 15 | | options.IfMatch.Value.ToString() : $"\"{options.IfMatch.Value.ToString()}\""; |
| 32 | 16 | | request.Headers.Add(HttpHeader.Names.IfMatch, value); |
| | 17 | | } |
| | 18 | |
|
| 156 | 19 | | if (options.IfNoneMatch.HasValue) |
| | 20 | | { |
| 124 | 21 | | string value = options.IfNoneMatch.Value == ETag.All ? |
| 124 | 22 | | options.IfNoneMatch.Value.ToString() : $"\"{options.IfNoneMatch.Value.ToString()}\""; |
| 124 | 23 | | request.Headers.Add(HttpHeader.Names.IfNoneMatch, value); |
| | 24 | | } |
| | 25 | |
|
| 156 | 26 | | if (options is RequestConditions dateOptions) |
| | 27 | | { |
| 0 | 28 | | if (dateOptions.IfModifiedSince.HasValue) |
| | 29 | | { |
| 0 | 30 | | request.Headers.Add(HttpHeader.Names.IfModifiedSince, dateOptions.IfModifiedSince.Value.UtcDateTime. |
| | 31 | | } |
| | 32 | |
|
| 0 | 33 | | if (dateOptions.IfUnmodifiedSince.HasValue) |
| | 34 | | { |
| 0 | 35 | | request.Headers.Add(HttpHeader.Names.IfUnmodifiedSince, dateOptions.IfUnmodifiedSince.Value.UtcDateT |
| | 36 | | } |
| | 37 | | } |
| 156 | 38 | | } |
| | 39 | | } |
| | 40 | | } |