| | | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | | 2 | | // Licensed under the MIT License. |
| | | 3 | | |
| | | 4 | | #nullable enable |
| | | 5 | | |
| | | 6 | | using System; |
| | | 7 | | using System.Collections.Generic; |
| | | 8 | | using System.Globalization; |
| | | 9 | | |
| | | 10 | | namespace Azure.Core |
| | | 11 | | { |
| | | 12 | | internal static class RequestHeaderExtensions |
| | | 13 | | { |
| | | 14 | | public static void Add(this RequestHeaders headers, string name, bool value) |
| | | 15 | | { |
| | 0 | 16 | | headers.Add(name, TypeFormatters.ToString(value)); |
| | 0 | 17 | | } |
| | | 18 | | |
| | | 19 | | public static void Add(this RequestHeaders headers, string name, float value) |
| | | 20 | | { |
| | 0 | 21 | | headers.Add(name, value.ToString(TypeFormatters.DefaultNumberFormat, CultureInfo.InvariantCulture)); |
| | 0 | 22 | | } |
| | | 23 | | |
| | | 24 | | public static void Add(this RequestHeaders headers, string name, double value) |
| | | 25 | | { |
| | 0 | 26 | | headers.Add(name, value.ToString(TypeFormatters.DefaultNumberFormat, CultureInfo.InvariantCulture)); |
| | 0 | 27 | | } |
| | | 28 | | |
| | | 29 | | public static void Add(this RequestHeaders headers, string name, int value) |
| | | 30 | | { |
| | 0 | 31 | | headers.Add(name, value.ToString(TypeFormatters.DefaultNumberFormat, CultureInfo.InvariantCulture)); |
| | 0 | 32 | | } |
| | | 33 | | |
| | | 34 | | public static void Add(this RequestHeaders headers, string name, DateTimeOffset value, string format) |
| | | 35 | | { |
| | 0 | 36 | | headers.Add(name, TypeFormatters.ToString(value, format)); |
| | 0 | 37 | | } |
| | | 38 | | |
| | | 39 | | public static void Add(this RequestHeaders headers, string name, TimeSpan value, string format) |
| | | 40 | | { |
| | 0 | 41 | | headers.Add(name, TypeFormatters.ToString(value, format)); |
| | 0 | 42 | | } |
| | | 43 | | |
| | | 44 | | public static void Add(this RequestHeaders headers, string name, Guid value) |
| | | 45 | | { |
| | 0 | 46 | | headers.Add(name, value.ToString()); |
| | 0 | 47 | | } |
| | | 48 | | |
| | | 49 | | public static void Add(this RequestHeaders headers, string name, byte[] value) |
| | | 50 | | { |
| | 0 | 51 | | headers.Add(name, Convert.ToBase64String(value)); |
| | 0 | 52 | | } |
| | | 53 | | |
| | | 54 | | public static void AddDelimited<T>(this RequestHeaders headers, string name, IEnumerable<T> value, string delimi |
| | | 55 | | { |
| | 0 | 56 | | headers.Add(name, string.Join(delimiter, value)); |
| | 0 | 57 | | } |
| | | 58 | | } |
| | | 59 | | } |