43#include <SharkSslEx.h>
119#define HttpClientHeader_key(c,o) ((c)->db.super.buf + (o)->key)
122#define HttpClientHeader_val(c,o) ((c)->db.super.buf + (o)->val)
125#define HTTP_CLIENT_MAX_HEADERS 64
127#define HttpClient_SocksProxy 1
128#define HttpClient_ProxyConnect 2
129#define HttpClient_Persistent 4
130#define HttpClient_IPv6 8
132#define HttpClient_NoHostHeader 16
133#define HttpClient_NotUsed2 32
135#define HttpClient_UserDef1 64
136#define HttpClient_UserDef2 128
212 void setSSL(SharkSsl* ssl);
228 static int isURL(
const char* url);
236 SharkSslConTrust
trusted(
void);
274 const char* userPass=0,
289 int sendData(
const void* data,
int len);
316 int readData(
void* buf,
int bufSize);
376 struct SharkSsl* sharkSslClient;
423#define HttpClient_setSSL(o, ssl) (o)->sharkSslClient=ssl
427#define HttpClient_setReadTmo(o, timeout) (o)->readTmo=timeout
455 const char* userPass,
468int HttpClient_readDataBuffered(
HttpClient* o,
void* buf,
int bufSize);
492#define HttpClient_getError(o) (o)->lastError
496#define HttpClient_getSoDispCon(o) ((SoDispCon*)(o))
507#define HttpClient_setAcceptTrusted(o, t) (o)->acceptTrusted=t
549 const char* userPass,
595 return c->db.buf + key;
598 return c->db.buf + val;
static int isURL(const char *url)
Classify a URL scheme; this does not validate the complete URL.
Definition: HttpClient.h:528
int readData(void *buf, int bufSize)
Read response body bytes, removing chunk framing when applicable.
Definition: HttpClient.h:565
void setSSL(SharkSsl *ssl)
Select the TLS context for future HTTPS connections.
Definition: HttpClient.h:520
SoDispCon * getSoDispCon()
Access the embedded transport object.
Definition: HttpClient.h:590
#define HttpClient_setReadTmo(o, timeout)
Set the timeout applied to individual blocking reads.
Definition: HttpClient.h:427
~HttpClient()
Close the connection and release client-owned storage.
Definition: HttpClient.h:516
int HttpClient_sendData(HttpClient *o, const void *data, int len)
Send part or all of the request body after request().
void close()
Shut down the connection and discard the current response state.
Definition: HttpClient.h:577
HttpClientHeader * getHeaders(int *hlen)
Obtain parsed response headers; may finish an upload and block for input.
Definition: HttpClient.h:573
int sendData(const void *data, int len)
Send part or all of the request body after request().
Definition: HttpClient.h:557
#define HttpClient_getSoDispCon(o)
Access the embedded transport object.
Definition: HttpClient.h:496
int getBufSize()
Query bytes already buffered beyond the response headers.
Definition: HttpClient.h:561
#define HttpClient_setSSL(o, ssl)
Select the TLS context for future HTTPS connections.
Definition: HttpClient.h:423
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.
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
const char * getHeaderValue(const char *name)
Look up the first response header with this name, ignoring case.
Definition: HttpClient.h:569
void HttpClient_destructor(HttpClient *o)
Close the connection and release client-owned storage.
int HttpClient_getBufSize(HttpClient *o)
Query bytes already buffered beyond the response headers.
SharkSslCon * getSharkSslCon()
Access the current SharkSSL connection.
Definition: HttpClient.h:542
int getError()
Query the stored client error without performing I/O.
Definition: HttpClient.h:586
const char * getVal(HttpClient *c)
Definition: HttpClient.h:597
HttpClientHeader * HttpClient_getHeaders(HttpClient *o, int *hlen)
Obtain parsed response headers; may finish an upload and block for input.
void HttpClient_close(HttpClient *o)
Shut down the connection and discard the current response state.
int HttpClient_getStatus(HttpClient *o)
Obtain the HTTP status, reading response headers if no status is cached.
SharkSslCon * HttpClient_getSharkSslCon(HttpClient *o)
Access the current SharkSSL connection.
int getStatus()
Obtain the HTTP status, reading response headers if no status is cached.
Definition: HttpClient.h:581
SharkSslConTrust HttpClient_trusted(HttpClient *o)
Query the current connection's certificate trust result.
#define HttpClient_getError(o)
Query the stored client error without performing I/O.
Definition: HttpClient.h:492
int HttpClient_isURL(const char *url)
Classify a URL scheme; this does not validate the complete URL.
const char * HttpClient_getHeaderValue(HttpClient *o, const char *name)
Look up the first response header with this name, ignoring case.
void setReadTmo(BaTime timeout)
Set the timeout applied to individual blocking reads.
Definition: HttpClient.h:524
const char * getKey(HttpClient *c)
Definition: HttpClient.h:594
int HttpClient_readData(HttpClient *o, void *buf, int bufSize)
Read response body bytes, removing chunk framing when applicable.
SharkSslConTrust trusted(void)
Query the current connection's certificate trust result.
Definition: HttpClient.h:533
void HttpClient_constructor(HttpClient *o, SoDisp *disp, U8 mode)
Construct an idle client; no connection is opened.
struct HttpClientKeyVal HttpClientKeyVal
A container for key/value pairs used when setting custom HTTP headers or URL encoded HTTP parameters.
#define HttpClient_setAcceptTrusted(o, t)
C form of HttpClient::setAcceptTrusted.
Definition: HttpClient.h:507
void setAcceptTrusted(bool acceptTrusted)
Choose whether new connections must pass the TLS trust check.
Definition: HttpClient.h:537
HttpClient(SoDisp *disp, U8 mode=HttpClient_Persistent)
Construct an idle client; no connection is opened.
Definition: HttpClient.h:512
HttpMethod
HTTP method types.
Definition: HttpServer.h:910
uint16_t U16
Unsigned 16-bit integer.
Definition: GenPrimT.h:91
S64 BaTime
An arithmetic type representing calendar time with epoch of 1970-01-01 00:00:00 UTC,...
Definition: GenPrimT.h:103
int16_t S16
Signed 16-bit integer.
Definition: GenPrimT.h:83
uint8_t U8
Unsigned 8-bit integer.
Definition: GenPrimT.h:89
U8 BaBool
Boolean stored in an unsigned byte; FALSE is zero and TRUE is one.
Definition: GenPrimT.h:118
U32 BaFileSize
Unsigned file size or position in bytes; 32 bits without BA_FILESIZE64.
Definition: GenPrimT.h:136
A dynamic buffer.
Definition: DynBuffer.h:68
A container for key/value pairs used when setting custom HTTP headers or URL encoded HTTP parameters.
Definition: HttpClient.h:90
const char * val
Required NUL-terminated value for a non-NULL key.
Definition: HttpClient.h:94
const char * key
NUL-terminated name; NULL terminates an input array.
Definition: HttpClient.h:92
Blocking HTTP/1.1 client with optional SharkSSL HTTPS support.
Definition: HttpClient.h:187
U16 proxyPortNo
Proxy TCP port, 1 through 65535 when proxy is configured.
Definition: HttpClient.h:396
const char * intfName
Borrowed local interface name/address, or NULL for the default binding.
Definition: HttpClient.h:386
const char * proxyUserPass
Borrowed proxy credentials "user:password", or NULL.
Definition: HttpClient.h:384
const char * proxy
Borrowed proxy host string, or NULL for a direct connection.
Definition: HttpClient.h:382
Contains information about the physical socket connection.
Definition: SoDispCon.h:120
The SoDisp dispatches any socket connection that contains data by calling the SoDispCon::execute memb...
Definition: SoDisp.h:91