// 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
{
///
/// Options used to configure a instance.
///
public class HttpConnectionOptions
{
private IDictionary _headers;
private X509CertificateCollection _clientCertificates;
private CookieContainer _cookies;
///
/// Initializes a new instance of the class.
///
public HttpConnectionOptions()
{
_headers = new Dictionary();
_clientCertificates = new X509CertificateCollection();
_cookies = new CookieContainer();
Transports = HttpTransports.All;
}
///
/// Gets or sets a delegate for wrapping or replacing the
/// that will make HTTP requests.
///
public Func HttpMessageHandlerFactory { get; set; }
///
/// Gets or sets a collection of headers that will be sent with HTTP requests.
///
public IDictionary Headers
{
get => _headers;
set => _headers = value ?? throw new ArgumentNullException(nameof(value));
}
///
/// Gets or sets a collection of client certificates that will be sent with HTTP requests.
///
public X509CertificateCollection ClientCertificates
{
get => _clientCertificates;
set => _clientCertificates = value ?? throw new ArgumentNullException(nameof(value));
}
///
/// Gets or sets a collection of cookies that will be sent with HTTP requests.
///
public CookieContainer Cookies
{
get => _cookies;
set => _cookies = value ?? throw new ArgumentNullException(nameof(value));
}
///
/// Gets or sets the URL used to send HTTP requests.
///
public Uri Url { get; set; }
///
/// Gets or sets a bitmask comprised of one or more that specify what transports the client should use to send HTTP requests.
///
public HttpTransportType Transports { get; set; }
///
/// Gets or sets a value indicating whether negotiation is skipped when connecting to the server.
///
///
/// Negotiation can only be skipped when using the transport.
///
public bool SkipNegotiation { get; set; }
///
/// Gets or sets an access token provider that will be called to return a token for each HTTP request.
///
public Func> AccessTokenProvider { get; set; }
///
/// Gets or sets a close timeout.
///
public TimeSpan CloseTimeout { get; set; } = TimeSpan.FromSeconds(5);
///
/// Gets or sets the credentials used when making HTTP requests.
///
public ICredentials Credentials { get; set; }
///
/// Gets or sets the proxy used when making HTTP requests.
///
public IWebProxy Proxy { get; set; }
///
/// Gets or sets a value indicating whether default credentials are used when making HTTP requests.
///
public bool? UseDefaultCredentials { get; set; }
///
/// Gets or sets a delegate that will be invoked with the object used
/// to configure the WebSocket when using the WebSockets transport.
///
///
/// This delegate is invoked after headers from and the access token from
/// has been applied.
///
public Action WebSocketConfiguration { get; set; }
}
}