reckfellENGINE

HttpClient

A low-level HTTP client with manual state polling.

On this page
class HttpClientReckfellSharpInherits RefCounted

Manages HTTP connection and body reads. After ConnectToHost call Poll, wait for Connected, issue Request and read in Body state. Full URL, request path and TLS options are separate configuration concerns.

An empty chunk does not prove completion, and unknown length -1 does not mean an empty body. Check framing, state and failures. HttpClient does not automatically perform HttpRequest decompression or redirects. Do not block the main thread waiting for the network; define a deadline and assembled-data budget.

Working example.

Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.

Constructors1

HttpClientConstructor
# HttpClient
C#
public HttpClient();

Properties3

BlockingModeEnabledProperty
# BlockingModeEnabled
C#
public bool BlockingModeEnabled { get; set; }

If true, execution will block until all data is read from the response.

ConnectionProperty
# Connection
C#
public StreamPeer Connection { get; set; }

The connection to use for this client.

ReadChunkSizeProperty
# ReadChunkSize
C#
public int ReadChunkSize { get; set; }

Ordinary read size; not a guaranteed bound for every internal HTTP chunk buffer. Separately bound assembled and decompressed data.

Methods24

Closevoid
# Close
C#
public void Close();

Closes the connection and resets network state. Coordinate cancellation/completion and owner lifetime separately.

ConnectToHostError
# ConnectToHost
C#
public Error ConnectToHost(string host, int port = -1, TlsOptions tlsOptions = null);

Begins connecting to host/port. Continue Poll to the required state; Error.Ok does not establish completed TCP/TLS. HTTPS requires client TLS options or an https scheme.

Parameters
NameTypeDefault
hoststring—
portint-1
tlsOptionsTlsOptionsnull
Returns Error
GetConnectionStreamPeer
# GetConnection
C#
public StreamPeer GetConnection();
Returns StreamPeer
GetReadChunkSizeint
# GetReadChunkSize
C#
public int GetReadChunkSize();
Returns int
GetResponseBodyLengthlong
# GetResponseBodyLength
C#
public long GetResponseBodyLength();

Returns a known body length or -1 when not determined in advance. Interpret alongside chunked/EOF framing and received bytes.

Returns long
GetResponseCodeint
# GetResponseCode
C#
public int GetResponseCode();

Returns the response's HTTP status code.

Returns int
GetResponseHeadersstring[]
# GetResponseHeaders
C#
public string[] GetResponseHeaders();

Returns the response headers.

Returns string[]
GetResponseHeadersAsDictionaryReckfell.Collections.Dictionary
# GetResponseHeadersAsDictionary
C#
public Reckfell.Collections.Dictionary GetResponseHeadersAsDictionary();

Returns all response headers as a Reckfell.Collections.Dictionary. Each entry is composed by the header name, and a string containing the values separated by "; ". The casing is kept the same as the headers were received.

Text
{
    "content-length": 12,
    "Content-Type": "application/json; charset=UTF-8",
}
Returns Reckfell.Collections.Dictionary
GetStatusHttpClient.Status
# GetStatus
C#
public HttpClient.Status GetStatus();

Returns a HttpClient.Status constant. Need to call HttpClient.Poll in order to get status updates.

Returns HttpClient.Status
HasResponsebool
# HasResponse
C#
public bool HasResponse();

If true, this HttpClient has a response available.

Returns bool
IsBlockingModeEnabledbool
# IsBlockingModeEnabled
C#
public bool IsBlockingModeEnabled();
Returns bool
IsResponseChunkedbool
# IsResponseChunked
C#
public bool IsResponseChunked();

If true, this HttpClient has a response that is chunked.

Returns bool
PollError
# Poll
C#
public Error Poll();

Advances connection/exchange. Call regularly without blocking the main thread in a waiting loop. Inspect both Error and GetStatus.

Returns Error
QueryStringFromDictstring
# QueryStringFromDict
C#
public string QueryStringFromDict(Reckfell.Collections.Dictionary fields);

Encodes query keys/values. Build query separately from host/path; this is not authentication or business-data validation.

Parameters
NameTypeDefault
fieldsReckfell.Collections.Dictionary—
Returns string
ReadResponseBodyChunkbyte[]
# ReadResponseBodyChunk
C#
public byte[] ReadResponseBodyChunk();

Reads part of a body in Body state. An empty array may mean waiting for more data. Do not decode each fragment as independent UTF-8 text.

Returns byte[]
Request2 overloads
# Request · 1/2
C#
public Error Request(HttpClient.Method method, string url, ReadOnlySpan<string> headers, string body);

Sends method and request path/query while connected. This is not the full URL. A string body is encoded as UTF-8.

Parameters
NameTypeDefault
methodHttpClient.Method—
urlstring—
headersReadOnlySpan<string>—
bodystring—
Returns Error
# Request · 2/2
C#
public Error Request(HttpClient.Method method, string url, string[] headers, string body = "");

Sends method and request path/query while connected. This is not the full URL. A string body is encoded as UTF-8.

Parameters
NameTypeDefault
methodHttpClient.Method—
urlstring—
headersstring[]—
bodystring""
Returns Error
RequestRaw2 overloads
# RequestRaw · 1/2
C#
public Error RequestRaw(HttpClient.Method method, string url, ReadOnlySpan<string> headers, ReadOnlySpan<byte> body);

Sends a raw HTTP request to the connected host with the given method. The URL parameter is usually just the part after the host, so for https://example.com/index.php, it is /index.php. When sending requests to an HTTP proxy server, it should be an absolute URL. For HttpClient.Method.Options requests, * is also allowed. For HttpClient.Method.Connect requests, it should be the authority component (host:port). headers are HTTP request headers. Sends the body data raw, as a byte array and does not encode it in any way.

Parameters
NameTypeDefault
methodHttpClient.Method—
urlstring—
headersReadOnlySpan<string>—
bodyReadOnlySpan<byte>—
Returns Error
# RequestRaw · 2/2
C#
public Error RequestRaw(HttpClient.Method method, string url, string[] headers, byte[] body);

Sends a raw HTTP request to the connected host with the given method. The URL parameter is usually just the part after the host, so for https://example.com/index.php, it is /index.php. When sending requests to an HTTP proxy server, it should be an absolute URL. For HttpClient.Method.Options requests, * is also allowed. For HttpClient.Method.Connect requests, it should be the authority component (host:port). headers are HTTP request headers. Sends the body data raw, as a byte array and does not encode it in any way.

Parameters
NameTypeDefault
methodHttpClient.Method—
urlstring—
headersstring[]—
bodybyte[]—
Returns Error
SetBlockingModevoid
# SetBlockingMode
C#
public void SetBlockingMode(bool enabled);
Parameters
NameTypeDefault
enabledbool—
SetConnectionvoid
# SetConnection
C#
public void SetConnection(StreamPeer connection);
Parameters
NameTypeDefault
connectionStreamPeer—
SetHttpProxyvoid
# SetHttpProxy
C#
public void SetHttpProxy(string host, int port);

Sets the proxy server for HTTP requests. The proxy server is unset if host is empty or port is -1.

Parameters
NameTypeDefault
hoststring—
portint—
SetHttpsProxyvoid
# SetHttpsProxy
C#
public void SetHttpsProxy(string host, int port);

Sets the proxy server for HTTPS requests. The proxy server is unset if host is empty or port is -1.

Parameters
NameTypeDefault
hoststring—
portint—
SetReadChunkSizevoid
# SetReadChunkSize
C#
public void SetReadChunkSize(int bytes);
Parameters
NameTypeDefault
bytesint—

HttpClient.Method

ValueDescription
Connect = 7

HTTP CONNECT method. The CONNECT method establishes a tunnel to the server identified by the target resource. Rarely used.

Delete = 4

HTTP DELETE method. The DELETE method requests to delete the specified resource.

Get = 0

HTTP GET method. The GET method requests a representation of the specified resource. Requests using GET should only retrieve data.

Head = 1

HTTP HEAD method. The HEAD method asks for a response identical to that of a GET request, but without the response body. This is useful to request metadata like HTTP headers or to check if a resource exists.

Max = 9

Represents the size of the HttpClient.Method enum.

Options = 5

HTTP OPTIONS method. The OPTIONS method asks for a description of the communication options for the target resource. Rarely used.

Patch = 8

HTTP PATCH method. The PATCH method is used to apply partial modifications to a resource.

Post = 2

HTTP POST method. The POST method is used to submit an entity to the specified resource, often causing a change in state or side effects on the server. This is often used for forms and submitting data or uploading files.

Put = 3

HTTP PUT method. The PUT method asks to replace all current representations of the target resource with the request payload. (You can think of POST as "create or update" and PUT as "update", although many services tend to not make a clear distinction or change their meaning).

Trace = 6

HTTP TRACE method. The TRACE method performs a message loop-back test along the path to the target resource. Returns the entire HTTP request received in the response body. Rarely used.

HttpClient.ResponseCode

ValueDescription
Accepted = 202

HTTP status code 202 Accepted. The request has been received but not yet acted upon. It is non-committal, meaning that there is no way in HTTP to later send an asynchronous response indicating the outcome of processing the request. It is intended for cases where another process or server handles the request, or for batch processing.

AlreadyReported = 208

HTTP status code 208 Already Reported (WebDAV). Used inside a DAV: propstat response element to avoid enumerating the internal members of multiple bindings to the same collection repeatedly.

BadGateway = 502

HTTP status code 502 Bad Gateway. The server, while acting as a gateway or proxy, received an invalid response from an inbound server it accessed while attempting to fulfill the request. Usually returned by load balancers or proxies.

BadRequest = 400

HTTP status code 400 Bad Request. The request was invalid. The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, invalid request contents, or deceptive request routing).

Conflict = 409

HTTP status code 409 Conflict. The request could not be completed due to a conflict with the current state of the target resource. This code is used in situations where the user might be able to resolve the conflict and resubmit the request.

Continue = 100

HTTP status code 100 Continue. Interim response that indicates everything so far is OK and that the client should continue with the request (or ignore this status if already finished).

Created = 201

HTTP status code 201 Created. The request has succeeded and a new resource has been created as a result of it. This is typically the response sent after a PUT request.

ExpectationFailed = 417

HTTP status code 417 Expectation Failed. The expectation given in the request's Expect header field could not be met by at least one of the inbound servers.

FailedDependency = 424

HTTP status code 424 Failed Dependency (WebDAV). The method could not be performed on the resource because the requested action depended on another action and that action failed.

Forbidden = 403

HTTP status code 403 Forbidden. The client does not have access rights to the content, i.e. they are unauthorized, so server is rejecting to give proper response. Unlike 401, the client's identity is known to the server.

Found = 302

HTTP status code 302 Found. Temporary redirection. This response code means the URI of requested resource has been changed temporarily. New changes in the URI might be made in the future. Therefore, this same URI should be used by the client in future requests.

GatewayTimeout = 504

HTTP status code 504 Gateway Timeout. The server, while acting as a gateway or proxy, did not receive a timely response from an upstream server it needed to access in order to complete the request. Usually returned by load balancers or proxies.

Gone = 410

HTTP status code 410 Gone. The target resource is no longer available at the origin server and this condition is likely permanent.

HttpVersionNotSupported = 505

HTTP status code 505 HTTP Version Not Supported. The server does not support, or refuses to support, the major version of HTTP that was used in the request message.

ImATeapot = 418

HTTP status code 418 I'm A Teapot. Any attempt to brew coffee with a teapot should result in the error code "418 I'm a teapot". The resulting entity body MAY be short and stout.

ImUsed = 226

HTTP status code 226 IM Used (WebDAV). The server has fulfilled a GET request for the resource, and the response is a representation of the result of one or more instance-manipulations applied to the current instance.

InsufficientStorage = 507

HTTP status code 507 Insufficient Storage. The method could not be performed on the resource because the server is unable to store the representation needed to successfully complete the request.

InternalServerError = 500

HTTP status code 500 Internal Server Error. The server encountered an unexpected condition that prevented it from fulfilling the request.

LengthRequired = 411

HTTP status code 411 Length Required. The server refuses to accept the request without a defined Content-Length header.

Locked = 423

HTTP status code 423 Locked (WebDAV). The source or destination resource of a method is locked.

LoopDetected = 508

HTTP status code 508 Loop Detected. The server terminated an operation because it encountered an infinite loop while processing a request with "Depth: infinity". This status indicates that the entire operation failed.

MethodNotAllowed = 405

HTTP status code 405 Method Not Allowed. The request's HTTP method is known by the server but has been disabled and cannot be used. For example, an API may forbid DELETE-ing a resource. The two mandatory methods, GET and HEAD, must never be disabled and should not return this error code.

MisdirectedRequest = 421

HTTP status code 421 Misdirected Request. The request was directed at a server that is not able to produce a response. This can be sent by a server that is not configured to produce responses for the combination of scheme and authority that are included in the request URI.

MovedPermanently = 301

HTTP status code 301 Moved Permanently. Redirection. This response code means the URI of requested resource has been changed. The new URI is usually included in the response.

MultiStatus = 207

HTTP status code 207 Multi-Status (WebDAV). A Multi-Status response conveys information about multiple resources in situations where multiple status codes might be appropriate.

MultipleChoices = 300

HTTP status code 300 Multiple Choice. The request has more than one possible responses and there is no standardized way to choose one of the responses. User-agent or user should choose one of them.

NetworkAuthRequired = 511

HTTP status code 511 Network Authentication Required. The client needs to authenticate to gain network access.

NoContent = 204

HTTP status code 204 No Content. There is no content to send for this request, but the headers may be useful. The user-agent may update its cached headers for this resource with the new ones.

NonAuthoritativeInformation = 203

HTTP status code 203 Non-Authoritative Information. This response code means returned meta-information set is not exact set as available from the origin server, but collected from a local or a third party copy. Except this condition, 200 OK response should be preferred instead of this response.

NotAcceptable = 406

HTTP status code 406 Not Acceptable. The target resource does not have a current representation that would be acceptable to the user agent, according to the proactive negotiation header fields received in the request. Used when negotiation content.

NotExtended = 510

HTTP status code 510 Not Extended. The policy for accessing the resource has not been met in the request. The server should send back all the information necessary for the client to issue an extended request.

NotFound = 404

HTTP status code 404 Not Found. The server can not find requested resource. Either the URL is not recognized or the endpoint is valid but the resource itself does not exist. May also be sent instead of 403 to hide existence of a resource if the client is not authorized.

NotImplemented = 501

HTTP status code 501 Not Implemented. The server does not support the functionality required to fulfill the request.

NotModified = 304

HTTP status code 304 Not Modified. A conditional GET or HEAD request has been received and would have resulted in a 200 OK response if it were not for the fact that the condition evaluated to false.

Ok = 200

HTTP status code 200 OK. The request has succeeded. Default response for successful requests. Meaning varies depending on the request:

PartialContent = 206

HTTP status code 206 Partial Content. This response code is used because of a range header sent by the client to separate download into multiple streams.

PaymentRequired = 402

HTTP status code 402 Payment Required. This response code is reserved for future use. Initial aim for creating this code was using it for digital payment systems, however this is not currently used.

PermanentRedirect = 308

HTTP status code 308 Permanent Redirect. The target resource has been assigned a new permanent URI and any future references to this resource ought to use one of the enclosed URIs.

PreconditionFailed = 412

HTTP status code 412 Precondition Failed. One or more conditions given in the request header fields evaluated to false when tested on the server.

PreconditionRequired = 428

HTTP status code 428 Precondition Required. The origin server requires the request to be conditional.

Processing = 102

HTTP status code 102 Processing (WebDAV). Indicates that the server has received and is processing the request, but no response is available yet.

ProxyAuthenticationRequired = 407

HTTP status code 407 Proxy Authentication Required. Similar to 401 Unauthorized, but it indicates that the client needs to authenticate itself in order to use a proxy.

RequestEntityTooLarge = 413

HTTP status code 413 Entity Too Large. The server is refusing to process a request because the request payload is larger than the server is willing or able to process.

RequestHeaderFieldsTooLarge = 431

HTTP status code 431 Request Header Fields Too Large. The server is unwilling to process the request because its header fields are too large. The request MAY be resubmitted after reducing the size of the request header fields.

RequestTimeout = 408

HTTP status code 408 Request Timeout. The server did not receive a complete request message within the time that it was prepared to wait.

RequestUriTooLong = 414

HTTP status code 414 Request-URI Too Long. The server is refusing to service the request because the request-target is longer than the server is willing to interpret.

RequestedRangeNotSatisfiable = 416

HTTP status code 416 Requested Range Not Satisfiable. None of the ranges in the request's Range header field overlap the current extent of the selected resource or the set of ranges requested has been rejected due to invalid ranges or an excessive request of small or overlapping ranges.

ResetContent = 205

HTTP status code 205 Reset Content. The server has fulfilled the request and desires that the client resets the "document view" that caused the request to be sent to its original state as received from the origin server.

SeeOther = 303

HTTP status code 303 See Other. The server is redirecting the user agent to a different resource, as indicated by a URI in the Location header field, which is intended to provide an indirect response to the original request.

ServiceUnavailable = 503

HTTP status code 503 Service Unavailable. The server is currently unable to handle the request due to a temporary overload or scheduled maintenance, which will likely be alleviated after some delay. Try again later.

SwitchProxy = 306

HTTP status code 306 Switch Proxy.

SwitchingProtocols = 101

HTTP status code 101 Switching Protocol. Sent in response to an Upgrade request header by the client. Indicates the protocol the server is switching to.

TemporaryRedirect = 307

HTTP status code 307 Temporary Redirect. The target resource resides temporarily under a different URI and the user agent MUST NOT change the request method if it performs an automatic redirection to that URI.

TooManyRequests = 429

HTTP status code 429 Too Many Requests. The user has sent too many requests in a given amount of time (see "rate limiting"). Back off and increase time between requests or try again later.

Unauthorized = 401

HTTP status code 401 Unauthorized. Credentials required. The request has not been applied because it lacks valid authentication credentials for the target resource.

UnavailableForLegalReasons = 451

HTTP status code 451 Response Unavailable For Legal Reasons. The server is denying access to the resource as a consequence of a legal demand.

UnprocessableEntity = 422

HTTP status code 422 Unprocessable Entity (WebDAV). The server understands the content type of the request entity (hence a 415 Unsupported Media Type status code is inappropriate), and the syntax of the request entity is correct (thus a 400 Bad Request status code is inappropriate) but was unable to process the contained instructions.

UnsupportedMediaType = 415

HTTP status code 415 Unsupported Media Type. The origin server is refusing to service the request because the payload is in a format not supported by this method on the target resource.

UpgradeRequired = 426

HTTP status code 426 Upgrade Required. The server refuses to perform the request using the current protocol but might be willing to do so after the client upgrades to a different protocol.

UseProxy = 305

HTTP status code 305 Use Proxy.

VariantAlsoNegotiates = 506

HTTP status code 506 Variant Also Negotiates. The server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself, and is therefore not a proper end point in the negotiation process.

HttpClient.Status

ValueDescription
Body = 7

Status: HTTP body received.

CantConnect = 4

Status: Can't connect to the server.

CantResolve = 2

Status: DNS failure: Can't resolve the hostname for the given URL.

Connected = 5

Status: Connection established.

Connecting = 3

Status: Currently connecting to server.

ConnectionError = 8

Status: Error in HTTP connection.

Disconnected = 0

Status: Disconnected from the server.

Requesting = 6

Status: Currently sending request.

Resolving = 1

Status: Currently resolving the hostname for the given URL into an IP.

TlsHandshakeError = 9

Status: Error in TLS handshake.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.