This repository has been archived by the owner on Dec 18, 2018. It is now read-only.
/
HttpConnectionOptions.cs
121 lines (104 loc) · 4.58 KB
/
HttpConnectionOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.WebSockets;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
namespace Microsoft.AspNetCore.Http.Connections.Client
{
/// <summary>
/// Options used to configure a <see cref="HttpConnection"/> instance.
/// </summary>
public class HttpConnectionOptions
{
private IDictionary<string, string> _headers;
private X509CertificateCollection _clientCertificates;
private CookieContainer _cookies;
/// <summary>
/// Initializes a new instance of the <see cref="HttpConnectionOptions"/> class.
/// </summary>
public HttpConnectionOptions()
{
_headers = new Dictionary<string, string>();
_clientCertificates = new X509CertificateCollection();
_cookies = new CookieContainer();
Transports = HttpTransports.All;
}
/// <summary>
/// Gets or sets a delegate for wrapping or replacing the <see cref="HttpMessageHandlerFactory"/>
/// that will make HTTP requests.
/// </summary>
public Func<HttpMessageHandler, HttpMessageHandler> HttpMessageHandlerFactory { get; set; }
/// <summary>
/// Gets or sets a collection of headers that will be sent with HTTP requests.
/// </summary>
public IDictionary<string, string> Headers
{
get => _headers;
set => _headers = value ?? throw new ArgumentNullException(nameof(value));
}
/// <summary>
/// Gets or sets a collection of client certificates that will be sent with HTTP requests.
/// </summary>
public X509CertificateCollection ClientCertificates
{
get => _clientCertificates;
set => _clientCertificates = value ?? throw new ArgumentNullException(nameof(value));
}
/// <summary>
/// Gets or sets a collection of cookies that will be sent with HTTP requests.
/// </summary>
public CookieContainer Cookies
{
get => _cookies;
set => _cookies = value ?? throw new ArgumentNullException(nameof(value));
}
/// <summary>
/// Gets or sets the URL used to send HTTP requests.
/// </summary>
public Uri Url { get; set; }
/// <summary>
/// Gets or sets a bitmask comprised of one or more <see cref="HttpTransportType"/> that specify what transports the client should use to send HTTP requests.
/// </summary>
public HttpTransportType Transports { get; set; }
/// <summary>
/// Gets or sets a value indicating whether negotiation is skipped when connecting to the server.
/// </summary>
/// <remarks>
/// Negotiation can only be skipped when using the <see cref="HttpTransportType.WebSockets"/> transport.
/// </remarks>
public bool SkipNegotiation { get; set; }
/// <summary>
/// Gets or sets an access token provider that will be called to return a token for each HTTP request.
/// </summary>
public Func<Task<string>> AccessTokenProvider { get; set; }
/// <summary>
/// Gets or sets a close timeout.
/// </summary>
public TimeSpan CloseTimeout { get; set; } = TimeSpan.FromSeconds(5);
/// <summary>
/// Gets or sets the credentials used when making HTTP requests.
/// </summary>
public ICredentials Credentials { get; set; }
/// <summary>
/// Gets or sets the proxy used when making HTTP requests.
/// </summary>
public IWebProxy Proxy { get; set; }
/// <summary>
/// Gets or sets a value indicating whether default credentials are used when making HTTP requests.
/// </summary>
public bool? UseDefaultCredentials { get; set; }
/// <summary>
/// Gets or sets a delegate that will be invoked with the <see cref="ClientWebSocketOptions"/> object used
/// to configure the WebSocket when using the WebSockets transport.
/// </summary>
/// <remarks>
/// This delegate is invoked after headers from <see cref="Headers"/> and the access token from <see cref="AccessTokenProvider"/>
/// has been applied.
/// </remarks>
public Action<ClientWebSocketOptions> WebSocketConfiguration { get; set; }
}
}