microsoft/teams.net

Public

mirrored fromhttps://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
5c4075027232b28388ab1e973b9d2407df669d63

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

Libraries/Microsoft.Teams.Common/Http/HttpRequestOptions.cs

57lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3
4namespace Microsoft.Teams.Common.Http;
5
6using IHttpHeaders = IDictionary<string, IList<string>>;
7
8public interface IHttpRequestOptions
9{
10 public IHttpHeaders Headers { get; set; }
11
12 public void AddUserAgent(IList<string> value);
13 public void AddUserAgent(params string[] value);
14 public void AddHeader(string key, IList<string> value);
15 public void AddHeader(string key, params string[] value);
16}
17
18public class HttpRequestOptions : IHttpRequestOptions
19{
20 public IHttpHeaders Headers { get; set; } = new Dictionary<string, IList<string>>();
21
22 public void AddUserAgent(IList<string> value)
23 {
24 AddHeader("User-Agent", value);
25 }
26
27 public void AddUserAgent(params string[] value)
28 {
29 AddHeader("User-Agent", value);
30 }
31
32 public void AddHeader(string key, IList<string> value)
33 {
34 Headers.TryGetValue(key, out IList<string>? values);
35 values ??= [];
36
37 foreach (var headerValue in value)
38 {
39 values.Add(headerValue);
40 }
41
42 Headers.Add(key, values);
43 }
44
45 public void AddHeader(string key, params string[] value)
46 {
47 Headers.TryGetValue(key, out IList<string>? values);
48 values ??= [];
49
50 foreach (var headerValue in value)
51 {
52 values.Add(headerValue);
53 }
54
55 Headers.Add(key, values);
56 }
57}