Table of Contents

Class HttpsProxyServer

Namespace
VpnHood.Net.Proxies.HttpProxyServers
Assembly
VpnHood.Net.Proxies.dll

Represents an HTTPS proxy server: an HTTP proxy that clients reach over TLS, and that opens CONNECT tunnels.

public sealed class HttpsProxyServer : TcpProxyServerBase, IDisposable
Inheritance
HttpsProxyServer
Implements
Inherited Members

Examples

using var server = new HttpsProxyServer(new HttpProxyServerOptions {
    ListenEndPoint = new IPEndPoint(IPAddress.Loopback, 0), // 0: the system picks a free port
    ServerCertificate = certificate // an X509Certificate2 with its private key
});

server.Start();

Remarks

It speaks TLS 1.2 and 1.3 with ServerCertificate and asks for no client certificate. It serves only CONNECT: once the TLS handshake, the request's parsing and any configured authentication have passed, another method gets 405 Method Not Allowed. With authentication on, missing or wrong credentials get 407 Proxy Authentication Required; a request refused otherwise gets 400 Bad Request or a closed connection.

Constructors

HttpsProxyServer(HttpProxyServerOptions, ILogger<HttpsProxyServer>?)

Represents an HTTPS proxy server: an HTTP proxy that clients reach over TLS, and that opens CONNECT tunnels.

public HttpsProxyServer(HttpProxyServerOptions options, ILogger<HttpsProxyServer>? logger = null)

Parameters

options HttpProxyServerOptions

The server's settings, with its certificate.

logger ILogger<HttpsProxyServer>

The logger for the server's events, or null for none.

Examples

using var server = new HttpsProxyServer(new HttpProxyServerOptions {
    ListenEndPoint = new IPEndPoint(IPAddress.Loopback, 0), // 0: the system picks a free port
    ServerCertificate = certificate // an X509Certificate2 with its private key
});

server.Start();

Remarks

It speaks TLS 1.2 and 1.3 with ServerCertificate and asks for no client certificate. It serves only CONNECT: once the TLS handshake, the request's parsing and any configured authentication have passed, another method gets 405 Method Not Allowed. With authentication on, missing or wrong credentials get 407 Proxy Authentication Required; a request refused otherwise gets 400 Bad Request or a closed connection.

Exceptions

ArgumentNullException

ListenEndPoint is null.

ArgumentException

ServerCertificate is null.

ArgumentOutOfRangeException

Backlog or MaxConnections is zero or negative.

Methods

HandleClientAsync(TcpClient, CancellationToken)

Serves one client connection.

protected override Task HandleClientAsync(TcpClient client, CancellationToken serverCancellationToken)

Parameters

client TcpClient

The accepted connection.

serverCancellationToken CancellationToken

Returns

Task

A task that represents the asynchronous operation. It completes when the connection is done.

Remarks

It runs on its own task for each accepted connection. When the returned task completes, the base class disposes client, and it logs any exception the task throws.

Exceptions

ArgumentNullException

ListenEndPoint is null.

ArgumentException

ServerCertificate is null.

ArgumentOutOfRangeException

Backlog or MaxConnections is zero or negative.