Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
The HTTP(S) client library.

Detailed Description

The HttpClient library is the C side implementation for the Lua httpc library.

The library is also used internally by the NetIo network file system. See the Lua HTTP client for an introduction to this library.

This documentation is for the C++ API defined in the headers. See the introduction to object oriented code in C for an introduction to the C API's.

The HTTP client library can also be compiled into a standalone library. The HTTP client source code requires a few runtime files from the Barracuda Server such as the SoDisp, BufPrint, DynBuffer, HttpConnection, HttpServCon, and HttpSocket.

The HTTP client library can also be used standalone together with the SharkSSL SSL/TLS stack when secure HTTP (HTTPS) is required.

Classes

struct  HttpClientKeyVal
 A container for key/value pairs used when setting custom HTTP headers or URL encoded HTTP parameters. More...
 
struct  HttpClientHeader
 The response HTTP headers returned by HttpClient::getHeaders. More...
 
struct  HttpClient
 Blocking HTTP/1.1 client with optional SharkSSL HTTPS support. More...
 

Macros

#define HttpClientHeader_key(c, o)   ((c)->db.super.buf + (o)->key)
 C accessor: c is the required owning client and o its header entry. More...
 
#define HttpClientHeader_val(c, o)   ((c)->db.super.buf + (o)->val)
 C accessor: c is the required owning client and o its header entry. More...
 
#define HttpClient_setSSL(o, ssl)   (o)->sharkSslClient=ssl
 Select the TLS context for future HTTPS connections. More...
 
#define HttpClient_setReadTmo(o, timeout)   (o)->readTmo=timeout
 Set the timeout applied to individual blocking reads. More...
 
#define HttpClient_getError(o)   (o)->lastError
 Query the stored client error without performing I/O. More...
 
#define HttpClient_getSoDispCon(o)   ((SoDispCon*)(o))
 Access the embedded transport object. More...
 
#define HttpClient_setAcceptTrusted(o, t)   (o)->acceptTrusted=t
 C form of HttpClient::setAcceptTrusted. More...
 

Typedefs

typedef struct HttpClientKeyVal HttpClientKeyVal
 A container for key/value pairs used when setting custom HTTP headers or URL encoded HTTP parameters. More...
 
typedef HttpClient HttpClient
 Blocking HTTP/1.1 client with optional SharkSSL HTTPS support. More...
 

Functions

void HttpClient_constructor (HttpClient *o, SoDisp *disp, U8 mode)
 Construct an idle client; no connection is opened. More...
 
SharkSslCon * HttpClient_getSharkSslCon (HttpClient *o)
 Access the current SharkSSL connection. More...
 
void HttpClient_destructor (HttpClient *o)
 Close the connection and release client-owned storage. More...
 
int HttpClient_isURL (const char *url)
 Classify a URL scheme; this does not validate the complete URL. More...
 
int HttpClient_request (HttpClient *o, HttpMethod methodType, const char *url, const char *userPass, const HttpClientKeyVal *params, const HttpClientKeyVal *headers, BaFileSize size)
 C form of HttpClient::request, with the same return values and lifecycle. More...
 
int HttpClient_sendData (HttpClient *o, const void *data, int len)
 Send part or all of the request body after request(). More...
 
int HttpClient_getBufSize (HttpClient *o)
 Query bytes already buffered beyond the response headers. More...
 
int HttpClient_readData (HttpClient *o, void *buf, int bufSize)
 Read response body bytes, removing chunk framing when applicable. More...
 
const char * HttpClient_getHeaderValue (HttpClient *o, const char *name)
 Look up the first response header with this name, ignoring case. More...
 
HttpClientHeader * HttpClient_getHeaders (HttpClient *o, int *hlen)
 Obtain parsed response headers; may finish an upload and block for input. More...
 
void HttpClient_close (HttpClient *o)
 Shut down the connection and discard the current response state. More...
 
int HttpClient_getStatus (HttpClient *o)
 Obtain the HTTP status, reading response headers if no status is cached. More...
 
SharkSslConTrust HttpClient_trusted (HttpClient *o)
 Query the current connection's certificate trust result. More...
 
 HttpClient::HttpClient (SoDisp *disp, U8 mode=HttpClient_Persistent)
 Construct an idle client; no connection is opened. More...
 
 HttpClient::~HttpClient ()
 Close the connection and release client-owned storage. More...
 
void HttpClient::setSSL (SharkSsl *ssl)
 Select the TLS context for future HTTPS connections. More...
 
void HttpClient::setReadTmo (BaTime timeout)
 Set the timeout applied to individual blocking reads. More...
 
static int HttpClient::isURL (const char *url)
 Classify a URL scheme; this does not validate the complete URL. More...
 
SharkSslConTrust HttpClient::trusted (void)
 Query the current connection's certificate trust result. More...
 
void HttpClient::setAcceptTrusted (bool acceptTrusted)
 Choose whether new connections must pass the TLS trust check. More...
 
SharkSslCon * HttpClient::getSharkSslCon ()
 Access the current SharkSSL connection. More...
 
int HttpClient::request (HttpMethod methodType, const char *url, const char *userPass=0, const HttpClientKeyVal *query=0, const HttpClientKeyVal *headers=0, BaFileSize size=0)
 Send request headers, opening or reusing a connection. More...
 
int HttpClient::sendData (const void *data, int len)
 Send part or all of the request body after request(). More...
 
int HttpClient::getBufSize ()
 Query bytes already buffered beyond the response headers. More...
 
int HttpClient::readData (void *buf, int bufSize)
 Read response body bytes, removing chunk framing when applicable. More...
 
const char * HttpClient::getHeaderValue (const char *name)
 Look up the first response header with this name, ignoring case. More...
 
HttpClientHeader * HttpClient::getHeaders (int *hlen)
 Obtain parsed response headers; may finish an upload and block for input. More...
 
void HttpClient::close ()
 Shut down the connection and discard the current response state. More...
 
int HttpClient::getStatus ()
 Obtain the HTTP status, reading response headers if no status is cached. More...
 
int HttpClient::getError ()
 Query the stored client error without performing I/O. More...
 
SoDispCon * HttpClient::getSoDispCon ()
 Access the embedded transport object. More...
 
const char * HttpClientHeader::getKey (HttpClient *c)
 
const char * HttpClientHeader::getVal (HttpClient *c)
 

Macro Definition Documentation

◆ HttpClient_getError

#define HttpClient_getError (   o)    (o)->lastError

Query the stored client error without performing I/O.

Returns
Zero when no error is stored, or a BaErrorCodes.h error value. Check each operation's own return value first: not every returned error is stored here, and close() does not clear this field.
Parameters
oRequired initialized client.

◆ HttpClient_getSoDispCon

#define HttpClient_getSoDispCon (   o)    ((SoDispCon*)(o))

Access the embedded transport object.

Returns
Non-NULL borrowed pointer with this client's lifetime. This does not indicate that a socket is connected. Do not destroy it independently.
Parameters
oRequired initialized client.

◆ HttpClient_setAcceptTrusted

#define HttpClient_setAcceptTrusted (   o,
  t 
)    (o)->acceptTrusted=t

C form of HttpClient::setAcceptTrusted.

Parameters
oRequired initialized client.
tTRUE to require trusted new connections, FALSE to disable the check.

◆ HttpClient_setReadTmo

#define HttpClient_setReadTmo (   o,
  timeout 
)    (o)->readTmo=timeout

Set the timeout applied to individual blocking reads.

Parameters
timeoutMilliseconds, default 20000. Use values representable by SoDispCon::setReadTmo (50 through 3276750, in 50 ms steps for exact timing). Values are rounded down to that transport's 50 ms resolution.
Note
request() replaces zero with 100 ms. This is not a total request deadline; DNS lookup and separate reads do not share one time budget.
Parameters
oRequired initialized client.

◆ HttpClient_setSSL

#define HttpClient_setSSL (   o,
  ssl 
)    (o)->sharkSslClient=ssl

Select the TLS context for future HTTPS connections.

Parameters
sslBorrowed, configured SharkSSL client context, or NULL to disable new HTTPS connections. Keep it alive until all connections using it close. Close an existing connection before replacing its TLS configuration. This setter does not configure certificates or enable trust enforcement; see setAcceptTrusted().
oRequired initialized client.

◆ HttpClientHeader_key

#define HttpClientHeader_key (   c,
  o 
)    ((c)->db.super.buf + (o)->key)

C accessor: c is the required owning client and o its header entry.

Returns
Borrowed NUL-terminated name, with the lifetime documented by getHeaders().

◆ HttpClientHeader_val

#define HttpClientHeader_val (   c,
  o 
)    ((c)->db.super.buf + (o)->val)

C accessor: c is the required owning client and o its header entry.

Returns
Borrowed NUL-terminated value, with the lifetime documented by getHeaders().

Typedef Documentation

◆ HttpClient

Blocking HTTP/1.1 client with optional SharkSSL HTTPS support.

Send a request, send its body if applicable, obtain response headers/status, and read the response body. Serialize access to each instance. When the dispatcher has a mutex, hold it when entering the API; blocking transport operations release and reacquire it internally.

This example streams a GET response without relying on a prior HEAD request or allocating storage for the complete response. The destination writer is owned by the caller and is not flushed here. An error can leave partial output.

int copyURL(HttpClient* http, const char* url, BufPrint* dest)
{
char buf[512];
int status = http->request(HttpMethod_Get, url);
if(status == 0)
{
int count;
// This example accepts only HTTP 200 responses.
status = http->getStatus();
if(status == 200)
{
status = 0;
while((count = http->readData(buf, sizeof(buf))) > 0)
{
status = dest->write(buf, count);
if(status < 0) break;
}
if(count < 0) status = count;
}
else if(status >= 0) status = -1;
}
http->close();
return status;
}
int write(const void *data, int len)
Append bytes, flushing or expanding through the callback as needed.
Definition: BufPrint.h:408
int readData(void *buf, int bufSize)
Read response body bytes, removing chunk framing when applicable.
Definition: HttpClient.h:565
void close()
Shut down the connection and discard the current response state.
Definition: HttpClient.h:577
int request(HttpMethod methodType, const char *url, const char *userPass=0, const HttpClientKeyVal *query=0, const HttpClientKeyVal *headers=0, BaFileSize size=0)
Send request headers, opening or reusing a connection.
Definition: HttpClient.h:547
int getStatus()
Obtain the HTTP status, reading response headers if no status is cached.
Definition: HttpClient.h:581
The BufPrint class, which implements a compact printf-style formatter, is a base class used by severa...
Definition: BufPrint.h:132
Blocking HTTP/1.1 client with optional SharkSSL HTTPS support.
Definition: HttpClient.h:187
Note
The parser accepts status codes 100 through 599. Informational responses are consumed until a final response, except 101 protocol switching. Chunked response trailers are validated and discarded, not exposed as headers. Chunk-size lines must be shorter than 256 bytes, excluding CRLF; the entire trailer section including its terminating CRLF is limited to 8192 bytes. Content-Encoding (for example gzip) is not decoded. Applications must check the HTTP status separately from transport success.

◆ HttpClientKeyVal

A container for key/value pairs used when setting custom HTTP headers or URL encoded HTTP parameters.

HttpClientKeyVal can be statically declared at compile time or be dynamically created during runtime. A dynamically created HttpClientKeyVal can be released as soon as HttpClient::request returns.

Example code:

HttpClientKeyVal myHeaders[]={
{"the-header-name","the header value"},
{"foo","bar"},
{0,0} // Terminator
};
A container for key/value pairs used when setting custom HTTP headers or URL encoded HTTP parameters.
Definition: HttpClient.h:90

Function Documentation

◆ close()

void HttpClient::close ( )

Shut down the connection and discard the current response state.

The object can be reused by request(). This does not free the dispatcher or TLS context, report a close error, or reset cached status/error values.

◆ getBufSize()

int HttpClient::getBufSize ( )

Query bytes already buffered beyond the response headers.

Returns
Nonnegative buffered byte count, or zero when none are available. This does not read headers or report allocation capacity. For chunked responses, buffered bytes may include chunk framing.

◆ getError()

int HttpClient::getError ( )

Query the stored client error without performing I/O.

Returns
Zero when no error is stored, or a BaErrorCodes.h error value. Check each operation's own return value first: not every returned error is stored here, and close() does not clear this field.

◆ getHeaders()

HttpClientHeader * HttpClient::getHeaders ( int *  hlen)

Obtain parsed response headers; may finish an upload and block for input.

Parameters
hlenRequired output pointer receiving the number of array entries; receives zero on failure.
Returns
Borrowed array on success (possibly with zero entries), or NULL on failure. Entries and their strings belong to this client; copy anything needed beyond the next request, close(), or destruction. Use HttpClientHeader::getKey() and HttpClientHeader::getVal() with this client.

◆ getHeaderValue()

const char * HttpClient::getHeaderValue ( const char *  name)

Look up the first response header with this name, ignoring case.

May finish the outgoing request and block while reading response headers.

Parameters
nameRequired NUL-terminated header name.
Returns
Borrowed NUL-terminated value, or NULL if absent or response processing fails. Use getError() to inspect a stored failure. Copy a value needed beyond the next request, close(), or destruction of the client.

◆ getKey()

const char * HttpClientHeader::getKey ( HttpClient *  c)
Parameters
cRequired client that supplied this header.
Returns
Borrowed NUL-terminated header name; same lifetime as getHeaders().

◆ getSharkSslCon()

SharkSslCon * HttpClient::getSharkSslCon ( )

Access the current SharkSSL connection.

Returns
Borrowed connection pointer, or NULL when unavailable. Do not free it or keep it after the HTTP connection is closed or replaced.

◆ getSoDispCon()

SoDispCon * HttpClient::getSoDispCon ( )

Access the embedded transport object.

Returns
Non-NULL borrowed pointer with this client's lifetime. This does not indicate that a socket is connected. Do not destroy it independently.

◆ getStatus()

int HttpClient::getStatus ( )

Obtain the HTTP status, reading response headers if no status is cached.

Returns
Cached HTTP status, or a negative error from response processing. A cached status can include 100 Continue; getHeaders() completes response processing in that case. Check the actual status your application expects, rather than treating every positive result as success.

◆ getVal()

const char * HttpClientHeader::getVal ( HttpClient *  c)
Parameters
cRequired client that supplied this header.
Returns
Borrowed NUL-terminated header value; same lifetime as getHeaders().

◆ HttpClient()

HttpClient::HttpClient ( SoDisp *  disp,
U8  mode = HttpClient_Persistent 
)

Construct an idle client; no connection is opened.

Parameters
dispRequired borrowed dispatcher, which must outlive this client.
modeBitwise combination of HttpClient_Persistent (the C++ default), HttpClient_SocksProxy, and HttpClient_IPv6. Zero disables these options. Persistent mode permits connection reuse; IPv6 selects IPv6 resolution where supported. SOCKS selects SOCKS instead of an HTTP CONNECT proxy. Configure proxy, proxyPortNo, proxyUserPass, and intfName before connecting. Without a dispatcher mutex, use the client from a single thread. The initial read timeout is 20000 milliseconds. Trust enforcement is off.

◆ HttpClient_close()

void HttpClient_close ( HttpClient *  o)

Shut down the connection and discard the current response state.

The object can be reused by request(). This does not free the dispatcher or TLS context, report a close error, or reset cached status/error values.

Parameters
oRequired initialized client.

◆ HttpClient_constructor()

void HttpClient_constructor ( HttpClient *  o,
SoDisp *  disp,
U8  mode 
)

Construct an idle client; no connection is opened.

Parameters
dispRequired borrowed dispatcher, which must outlive this client.
modeBitwise combination of HttpClient_Persistent (the C++ default), HttpClient_SocksProxy, and HttpClient_IPv6. Zero disables these options. Persistent mode permits connection reuse; IPv6 selects IPv6 resolution where supported. SOCKS selects SOCKS instead of an HTTP CONNECT proxy. Configure proxy, proxyPortNo, proxyUserPass, and intfName before connecting. Without a dispatcher mutex, use the client from a single thread. The initial read timeout is 20000 milliseconds. Trust enforcement is off.
oRequired initialized client storage.

◆ HttpClient_destructor()

void HttpClient_destructor ( HttpClient *  o)

Close the connection and release client-owned storage.

Borrowed dispatcher, TLS context, and configuration strings are not destroyed. Stop all users first.

Parameters
oRequired initialized client.

◆ HttpClient_getBufSize()

int HttpClient_getBufSize ( HttpClient *  o)

Query bytes already buffered beyond the response headers.

Returns
Nonnegative buffered byte count, or zero when none are available. This does not read headers or report allocation capacity. For chunked responses, buffered bytes may include chunk framing.
Parameters
oRequired initialized client.

◆ HttpClient_getHeaders()

HttpClientHeader * HttpClient_getHeaders ( HttpClient *  o,
int *  hlen 
)

Obtain parsed response headers; may finish an upload and block for input.

Parameters
hlenRequired output pointer receiving the number of array entries; receives zero on failure.
Returns
Borrowed array on success (possibly with zero entries), or NULL on failure. Entries and their strings belong to this client; copy anything needed beyond the next request, close(), or destruction. Use HttpClientHeader::getKey() and HttpClientHeader::getVal() with this client.
Parameters
oRequired initialized client.

◆ HttpClient_getHeaderValue()

const char * HttpClient_getHeaderValue ( HttpClient *  o,
const char *  name 
)

Look up the first response header with this name, ignoring case.

May finish the outgoing request and block while reading response headers.

Parameters
nameRequired NUL-terminated header name.
Returns
Borrowed NUL-terminated value, or NULL if absent or response processing fails. Use getError() to inspect a stored failure. Copy a value needed beyond the next request, close(), or destruction of the client.
Parameters
oRequired initialized client.

◆ HttpClient_getSharkSslCon()

SharkSslCon * HttpClient_getSharkSslCon ( HttpClient *  o)

Access the current SharkSSL connection.

Returns
Borrowed connection pointer, or NULL when unavailable. Do not free it or keep it after the HTTP connection is closed or replaced.
Parameters
oRequired initialized client.

◆ HttpClient_getStatus()

int HttpClient_getStatus ( HttpClient *  o)

Obtain the HTTP status, reading response headers if no status is cached.

Returns
Cached HTTP status, or a negative error from response processing. A cached status can include 100 Continue; getHeaders() completes response processing in that case. Check the actual status your application expects, rather than treating every positive result as success.
Parameters
oRequired initialized client.

◆ HttpClient_isURL()

int HttpClient_isURL ( const char *  url)

Classify a URL scheme; this does not validate the complete URL.

Parameters
urlRequired NUL-terminated URL string.
Returns
1 for http://, 2 for https://, 3 for ws://, 4 for wss://, or E_INVALID_URL for an unrecognized prefix. Prefix matching is case-sensitive.

◆ HttpClient_readData()

int HttpClient_readData ( HttpClient *  o,
void *  buf,
int  bufSize 
)

Read response body bytes, removing chunk framing when applicable.

Completes the outgoing request and reads response headers if needed.

Parameters
bufWritable buffer; returned data is binary and not NUL-terminated. NULL only processes the response headers and returns zero without consuming the body, so that use cannot be interpreted as end-of-body.
bufSizePositive buffer capacity in bytes when buf is non-NULL.
Returns
Positive bytes stored, zero at end-of-body (including HEAD), or a negative error code. If a fixed-length read fails after copying buffered bytes, their count is returned and getError() records the failure; the next read returns that error. Other failures may modify the buffer without reporting a partial count. Reading before the request body is completely sent returns E_INCORRECT_USE.
Note
Closure or a read failure before Content-Length bytes arrive records E_INVALID_RESPONSE, even with Connection: close. The cached HTTP status is independent of this body error. For a body delimited by connection closure (without Content-Length), transport read failure is treated as end-of-body. This cannot distinguish every truncated response.
Parameters
oRequired initialized client.

◆ HttpClient_request()

int HttpClient_request ( HttpClient *  o,
HttpMethod  methodType,
const char *  url,
const char *  userPass,
const HttpClientKeyVal *  params,
const HttpClientKeyVal *  headers,
BaFileSize  size 
)

C form of HttpClient::request, with the same return values and lifecycle.

Parameters
oRequired initialized client.
methodTypeSupported HttpMethod value; see HttpClient::request.
urlRequired absolute URL string.
userPassOptional "user:password" string, or NULL.
paramsOptional decoded query array terminated by a NULL key.
headersOptional custom header array terminated by a NULL key.
sizeRequest-body byte count; zero selects chunked output for body methods.
Returns
Zero when headers are sent, or a negative error; see HttpClient::request.

◆ HttpClient_sendData()

int HttpClient_sendData ( HttpClient *  o,
const void *  data,
int  len 
)

Send part or all of the request body after request().

Parameters
dataRequired readable buffer when len is positive; borrowed for this call only. Binary bytes are sent unchanged.
lenNonnegative byte count. Zero is a no-op, not an end marker. For fixed-length requests, do not exceed the remaining declared length.
Returns
Zero on success, a negative error code, or a positive HTTP status if an early server response is available after a send failure. Stop on any nonzero result; no partial byte count is returned. To finish chunked output, obtain the response rather than sending zero bytes.
Parameters
oRequired initialized client.

◆ HttpClient_trusted()

SharkSslConTrust HttpClient_trusted ( HttpClient *  o)

Query the current connection's certificate trust result.

Returns
A SharkSslConTrust value, including SharkSslConTrust_NotSSL when no SharkSSL connection is available. Certificate, host-name, and date checks use the configured SharkSSL context and current host. See the SharkSSL reference.
Parameters
oRequired initialized client.

◆ isURL()

int HttpClient::isURL ( const char *  url)
static

Classify a URL scheme; this does not validate the complete URL.

Parameters
urlRequired NUL-terminated URL string.
Returns
1 for http://, 2 for https://, 3 for ws://, 4 for wss://, or E_INVALID_URL for an unrecognized prefix. Prefix matching is case-sensitive.

◆ readData()

int HttpClient::readData ( void *  buf,
int  bufSize 
)

Read response body bytes, removing chunk framing when applicable.

Completes the outgoing request and reads response headers if needed.

Parameters
bufWritable buffer; returned data is binary and not NUL-terminated. NULL only processes the response headers and returns zero without consuming the body, so that use cannot be interpreted as end-of-body.
bufSizePositive buffer capacity in bytes when buf is non-NULL.
Returns
Positive bytes stored, zero at end-of-body (including HEAD), or a negative error code. If a fixed-length read fails after copying buffered bytes, their count is returned and getError() records the failure; the next read returns that error. Other failures may modify the buffer without reporting a partial count. Reading before the request body is completely sent returns E_INCORRECT_USE.
Note
Closure or a read failure before Content-Length bytes arrive records E_INVALID_RESPONSE, even with Connection: close. The cached HTTP status is independent of this body error. For a body delimited by connection closure (without Content-Length), transport read failure is treated as end-of-body. This cannot distinguish every truncated response.

◆ request()

int HttpClient::request ( HttpMethod  methodType,
const char *  url,
const char *  userPass = 0,
const HttpClientKeyVal *  query = 0,
const HttpClientKeyVal *  headers = 0,
BaFileSize  size = 0 
)

Send request headers, opening or reusing a connection.

Parameters
methodTypeHttpMethod_Delete, HttpMethod_Get, HttpMethod_Head, HttpMethod_Patch, HttpMethod_Post, or HttpMethod_Put.
urlRequired NUL-terminated absolute URL, including host and path. HTTPS requires setSSL(). The ws/wss schemes are also recognized, but this call alone does not complete a WebSocket upgrade.
userPassOptional NUL-terminated "user:password" for Basic authentication; NULL omits it.
queryOptional array of decoded query names and values. Both are URL-encoded. Terminate the array with a NULL key; each other value must be a non-NULL NUL-terminated string.
headersOptional custom header array with the same terminator. Supply valid HTTP names/values without embedded CR or LF.
sizeBody length in bytes for POST, PUT, PATCH, or DELETE. Zero selects chunked encoding. GET and HEAD ignore this argument. All argument strings/arrays need remain valid only during this call.
Returns
Zero when request headers have been sent, or a negative error code (BaErrorCodes.h). Zero does not indicate an HTTP success response. Finish any fixed-length body with sendData() before reading the response. Calling getHeaders(), getHeaderValue(), or readData() finishes a chunked upload and reads the response headers. getStatus() does so when no status is already cached. Calling request() again before managing the prior response returns E_INCORRECT_USE; use close() to abandon it.
Note
Advanced HttpClient_ProxyConnect mode returns E_PROXY_READY when its proxy tunnel is ready, before sending an ordinary HTTP request.

◆ sendData()

int HttpClient::sendData ( const void *  data,
int  len 
)

Send part or all of the request body after request().

Parameters
dataRequired readable buffer when len is positive; borrowed for this call only. Binary bytes are sent unchanged.
lenNonnegative byte count. Zero is a no-op, not an end marker. For fixed-length requests, do not exceed the remaining declared length.
Returns
Zero on success, a negative error code, or a positive HTTP status if an early server response is available after a send failure. Stop on any nonzero result; no partial byte count is returned. To finish chunked output, obtain the response rather than sending zero bytes.

◆ setAcceptTrusted()

void HttpClient::setAcceptTrusted ( bool  acceptTrusted)

Choose whether new connections must pass the TLS trust check.

Parameters
acceptTrustedTrue requires SharkSslConTrust_CertCnDate before sending the HTTP request; failure returns E_NOT_TRUSTED. False (default) disables this requirement. Plain HTTP is rejected when enabled. Set this before connecting. Changing it does not recheck a reused connection.

◆ setReadTmo()

void HttpClient::setReadTmo ( BaTime  timeout)

Set the timeout applied to individual blocking reads.

Parameters
timeoutMilliseconds, default 20000. Use values representable by SoDispCon::setReadTmo (50 through 3276750, in 50 ms steps for exact timing). Values are rounded down to that transport's 50 ms resolution.
Note
request() replaces zero with 100 ms. This is not a total request deadline; DNS lookup and separate reads do not share one time budget.

◆ setSSL()

void HttpClient::setSSL ( SharkSsl *  ssl)

Select the TLS context for future HTTPS connections.

Parameters
sslBorrowed, configured SharkSSL client context, or NULL to disable new HTTPS connections. Keep it alive until all connections using it close. Close an existing connection before replacing its TLS configuration. This setter does not configure certificates or enable trust enforcement; see setAcceptTrusted().

◆ trusted()

SharkSslConTrust HttpClient::trusted ( void  )

Query the current connection's certificate trust result.

Returns
A SharkSslConTrust value, including SharkSslConTrust_NotSSL when no SharkSSL connection is available. Certificate, host-name, and date checks use the configured SharkSSL context and current host. See the SharkSSL reference.

◆ ~HttpClient()

HttpClient::~HttpClient ( )

Close the connection and release client-owned storage.

Borrowed dispatcher, TLS context, and configuration strings are not destroyed. Stop all users first.