Table of Contents

Class HttpEndpointConnection

Namespace
DuetAPIClient
Assembly
DuetAPIClient.dll

Connection class for dealing with requests received from a custom HTTP endpoint

public sealed class HttpEndpointConnection : IDisposable
Inheritance
HttpEndpointConnection
Implements
Inherited Members

Remarks

Constructor for a new connection dealing with a single HTTP endpoint request

Constructors

HttpEndpointConnection(Socket, bool)

Connection class for dealing with requests received from a custom HTTP endpoint

public HttpEndpointConnection(Socket socket, bool isWebSocket)

Parameters

socket Socket

Connection socket

isWebSocket bool

Indicates if the HTTP endpoint is a WebSocket

Remarks

Constructor for a new connection dealing with a single HTTP endpoint request

Properties

IsConnected

Indicates if the socket is still connected

public bool IsConnected { get; }

Property Value

bool

Methods

Close()

Close this connection

public void Close()

Dispose()

Disposes this instance

public void Dispose()

ReadRequest()

Read information about the last HTTP request. Note that a call to this method may fail!

public ReceivedHttpRequest ReadRequest()

Returns

ReceivedHttpRequest

Received HTTP request data

Exceptions

SocketException

Connection has been closed

ReadRequestAsync(CancellationToken)

Read information about the last HTTP request asynchronously. Note that a call to this method may fail!

public Task<ReceivedHttpRequest> ReadRequestAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Optional cancellation token

Returns

Task<ReceivedHttpRequest>

Received HTTP request data

Exceptions

OperationCanceledException

Operation has been cancelled

SocketException

Connection has been closed

SendResponse(int, string, HttpResponseType)

Send a simple HTTP response to the client and dispose this connection unless it is a WebSocket

public void SendResponse(int statusCode = 204, string response = "", HttpResponseType responseType = HttpResponseType.StatusCode)

Parameters

statusCode int

HTTP code to return

response string

Response data to return

responseType HttpResponseType

Type of data to return

Remarks

If the underlying connection is a WebSocket, the user must close this connection manually

Exceptions

SocketException

Connection has been closed

SendResponseAsync(int, string, HttpResponseType, CancellationToken)

Send a simple HTTP response to the client asynchronously and dispose this connection unless it is a WebSocket

public Task SendResponseAsync(int statusCode = 204, string response = "", HttpResponseType responseType = HttpResponseType.StatusCode, CancellationToken cancellationToken = default)

Parameters

statusCode int

HTTP code to return

response string

Response data to return

responseType HttpResponseType

Type of data to return

cancellationToken CancellationToken

Optional cancellation token

Returns

Task

Asynchronous task

Remarks

If the underlying connection is a WebSocket, the user must close this connection manually

Exceptions

OperationCanceledException

Operation has been cancelled

SocketException

Connection has been closed