Class HttpEndpointConnection
Connection class for dealing with requests received from a custom HTTP endpoint
Implements
Inherited Members
Namespace: DuetAPIClient
Assembly: DuetAPIClient.dll
Syntax
public sealed class HttpEndpointConnection : IDisposable
Constructors
HttpEndpointConnection(Socket, bool)
Constructor for a new connection dealing with a single HTTP endpoint request
Declaration
public HttpEndpointConnection(Socket socket, bool isWebSocket)
Parameters
Type | Name | Description |
---|---|---|
Socket | socket | Connection socket |
bool | isWebSocket | Indicates if the HTTP endpoint is a WebSocket |
Remarks
DCS may create new connections and close them immediately again to check if the UNIX socket is still active
Properties
IsConnected
Indicates if the socket is still connected
Declaration
public bool IsConnected { get; }
Property Value
Type | Description |
---|---|
bool |
Methods
Close()
Close this connection
Declaration
public void Close()
Dispose()
Disposes this instance
Declaration
public void Dispose()
ReadRequest(CancellationToken)
Read information about the last HTTP request. Note that a call to this method may fail!
Declaration
public Task<ReceivedHttpRequest> ReadRequest(CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | Optional cancellation token |
Returns
Type | Description |
---|---|
Task<ReceivedHttpRequest> | Received HTTP request data |
Exceptions
Type | Condition |
---|---|
OperationCanceledException | Operation has been cancelled |
SocketException | Connection has been closed |
SendResponse(int, string, HttpResponseType, CancellationToken)
Send a simple HTTP response to the client and dispose this connection unless it is a WebSocket
Declaration
public Task SendResponse(int statusCode = 204, string response = "", HttpResponseType responseType = HttpResponseType.StatusCode, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
int | statusCode | HTTP code to return |
string | response | Response data to return |
HttpResponseType | responseType | Type of data to return |
CancellationToken | cancellationToken | Optional cancellation token |
Returns
Type | Description |
---|---|
Task | Asynchronous task |
Remarks
If the underlying connection is a WebSocket, the user must close this connection manually
Exceptions
Type | Condition |
---|---|
OperationCanceledException | Operation has been cancelled |
SocketException | Connection has been closed |