HttpClient
A low-level HTTP client with manual state polling.
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.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
HttpClientConstructor
public HttpClient();Properties3
BlockingModeEnabledProperty
public bool BlockingModeEnabled { get; set; }If true, execution will block until all data is read from the response.
ConnectionProperty
public StreamPeer Connection { get; set; }The connection to use for this client.
ReadChunkSizeProperty
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
public void Close();Closes the connection and resets network state. Coordinate cancellation/completion and owner lifetime separately.
ConnectToHostError
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.
| Name | Type | Default |
|---|---|---|
host | string | — |
port | int | -1 |
tlsOptions | TlsOptions | null |
ErrorGetConnectionStreamPeer
public StreamPeer GetConnection();StreamPeerGetReadChunkSizeint
public int GetReadChunkSize();intGetResponseBodyLengthlong
public long GetResponseBodyLength();Returns a known body length or -1 when not determined in advance. Interpret alongside chunked/EOF framing and received bytes.
longGetResponseCodeint
public int GetResponseCode();Returns the response's HTTP status code.
intGetResponseHeadersstring[]
public string[] GetResponseHeaders();Returns the response headers.
string[]GetResponseHeadersAsDictionaryReckfell.Collections.Dictionary
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.
{
"content-length": 12,
"Content-Type": "application/json; charset=UTF-8",
}Reckfell.Collections.DictionaryGetStatusHttpClient.Status
public HttpClient.Status GetStatus();Returns a HttpClient.Status constant. Need to call HttpClient.Poll in order to get status updates.
HttpClient.StatusHasResponsebool
public bool HasResponse();If true, this HttpClient has a response available.
boolIsBlockingModeEnabledbool
public bool IsBlockingModeEnabled();boolIsResponseChunkedbool
public bool IsResponseChunked();If true, this HttpClient has a response that is chunked.
boolPollError
public Error Poll();Advances connection/exchange. Call regularly without blocking the main thread in a waiting loop. Inspect both Error and GetStatus.
ErrorQueryStringFromDictstring
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.
| Name | Type | Default |
|---|---|---|
fields | Reckfell.Collections.Dictionary | — |
stringReadResponseBodyChunkbyte[]
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.
byte[]Request2 overloads
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.
| Name | Type | Default |
|---|---|---|
method | HttpClient.Method | — |
url | string | — |
headers | ReadOnlySpan<string> | — |
body | string | — |
Errorpublic 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.
| Name | Type | Default |
|---|---|---|
method | HttpClient.Method | — |
url | string | — |
headers | string[] | — |
body | string | "" |
ErrorRequestRaw2 overloads
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.
| Name | Type | Default |
|---|---|---|
method | HttpClient.Method | — |
url | string | — |
headers | ReadOnlySpan<string> | — |
body | ReadOnlySpan<byte> | — |
Errorpublic 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.
| Name | Type | Default |
|---|---|---|
method | HttpClient.Method | — |
url | string | — |
headers | string[] | — |
body | byte[] | — |
ErrorSetBlockingModevoid
public void SetBlockingMode(bool enabled);| Name | Type | Default |
|---|---|---|
enabled | bool | — |
SetConnectionvoid
public void SetConnection(StreamPeer connection);| Name | Type | Default |
|---|---|---|
connection | StreamPeer | — |
SetHttpProxyvoid
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.
| Name | Type | Default |
|---|---|---|
host | string | — |
port | int | — |
SetHttpsProxyvoid
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.
| Name | Type | Default |
|---|---|---|
host | string | — |
port | int | — |
SetReadChunkSizevoid
public void SetReadChunkSize(int bytes);| Name | Type | Default |
|---|---|---|
bytes | int | — |
HttpClient.Method
| Value | Description |
|---|---|
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 |
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
| Value | Description |
|---|---|
Accepted = 202 | HTTP status code |
AlreadyReported = 208 | HTTP status code |
BadGateway = 502 | HTTP status code |
BadRequest = 400 | HTTP status code |
Conflict = 409 | HTTP status code |
Continue = 100 | HTTP status code |
Created = 201 | HTTP status code |
ExpectationFailed = 417 | HTTP status code |
FailedDependency = 424 | HTTP status code |
Forbidden = 403 | HTTP status code |
Found = 302 | HTTP status code |
GatewayTimeout = 504 | HTTP status code |
Gone = 410 | HTTP status code |
HttpVersionNotSupported = 505 | HTTP status code |
ImATeapot = 418 | HTTP status code |
ImUsed = 226 | HTTP status code |
InsufficientStorage = 507 | HTTP status code |
InternalServerError = 500 | HTTP status code |
LengthRequired = 411 | HTTP status code |
Locked = 423 | HTTP status code |
LoopDetected = 508 | HTTP status code |
MethodNotAllowed = 405 | HTTP status code |
MisdirectedRequest = 421 | HTTP status code |
MovedPermanently = 301 | HTTP status code |
MultiStatus = 207 | HTTP status code |
MultipleChoices = 300 | HTTP status code |
NetworkAuthRequired = 511 | HTTP status code |
NoContent = 204 | HTTP status code |
NonAuthoritativeInformation = 203 | HTTP status code |
NotAcceptable = 406 | HTTP status code |
NotExtended = 510 | HTTP status code |
NotFound = 404 | HTTP status code |
NotImplemented = 501 | HTTP status code |
NotModified = 304 | HTTP status code |
Ok = 200 | HTTP status code
|
PartialContent = 206 | HTTP status code |
PaymentRequired = 402 | HTTP status code |
PermanentRedirect = 308 | HTTP status code |
PreconditionFailed = 412 | HTTP status code |
PreconditionRequired = 428 | HTTP status code |
Processing = 102 | HTTP status code |
ProxyAuthenticationRequired = 407 | HTTP status code |
RequestEntityTooLarge = 413 | HTTP status code |
RequestHeaderFieldsTooLarge = 431 | HTTP status code |
RequestTimeout = 408 | HTTP status code |
RequestUriTooLong = 414 | HTTP status code |
RequestedRangeNotSatisfiable = 416 | HTTP status code |
ResetContent = 205 | HTTP status code |
SeeOther = 303 | HTTP status code |
ServiceUnavailable = 503 | HTTP status code |
SwitchProxy = 306 | HTTP status code |
SwitchingProtocols = 101 | HTTP status code |
TemporaryRedirect = 307 | HTTP status code |
TooManyRequests = 429 | HTTP status code |
Unauthorized = 401 | HTTP status code |
UnavailableForLegalReasons = 451 | HTTP status code |
UnprocessableEntity = 422 | HTTP status code |
UnsupportedMediaType = 415 | HTTP status code |
UpgradeRequired = 426 | HTTP status code |
UseProxy = 305 | HTTP status code |
VariantAlsoNegotiates = 506 | HTTP status code |
HttpClient.Status
| Value | Description |
|---|---|
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. |