39#ifndef HTTP_CLIENT_SUPPORT
40 #define HTTP_CLIENT_SUPPORT ENABLED
41#elif (HTTP_CLIENT_SUPPORT != ENABLED && HTTP_CLIENT_SUPPORT != DISABLED)
42 #error HTTP_CLIENT_SUPPORT parameter is not valid
46#ifndef HTTP_CLIENT_TLS_SUPPORT
47 #define HTTP_CLIENT_TLS_SUPPORT DISABLED
48#elif (HTTP_CLIENT_TLS_SUPPORT != ENABLED && HTTP_CLIENT_TLS_SUPPORT != DISABLED)
49 #error HTTP_CLIENT_TLS_SUPPORT parameter is not valid
53#ifndef HTTP_CLIENT_BASIC_AUTH_SUPPORT
54 #define HTTP_CLIENT_BASIC_AUTH_SUPPORT DISABLED
55#elif (HTTP_CLIENT_BASIC_AUTH_SUPPORT != ENABLED && HTTP_CLIENT_BASIC_AUTH_SUPPORT != DISABLED)
56 #error HTTP_CLIENT_BASIC_AUTH_SUPPORT parameter is not valid
60#ifndef HTTP_CLIENT_DIGEST_AUTH_SUPPORT
61 #define HTTP_CLIENT_DIGEST_AUTH_SUPPORT DISABLED
62#elif (HTTP_CLIENT_DIGEST_AUTH_SUPPORT != ENABLED && HTTP_CLIENT_DIGEST_AUTH_SUPPORT != DISABLED)
63 #error HTTP_CLIENT_DIGEST_AUTH_SUPPORT parameter is not valid
67#ifndef HTTP_CLIENT_MD5_SUPPORT
68 #define HTTP_CLIENT_MD5_SUPPORT ENABLED
69#elif (HTTP_CLIENT_MD5_SUPPORT != ENABLED && HTTP_CLIENT_MD5_SUPPORT != DISABLED)
70 #error HTTP_CLIENT_MD5_SUPPORT parameter is not valid
74#ifndef HTTP_CLIENT_SHA256_SUPPORT
75 #define HTTP_CLIENT_SHA256_SUPPORT DISABLED
76#elif (HTTP_CLIENT_SHA256_SUPPORT != ENABLED && HTTP_CLIENT_SHA256_SUPPORT != DISABLED)
77 #error HTTP_CLIENT_SHA256_SUPPORT parameter is not valid
81#ifndef HTTP_CLIENT_SHA512_256_SUPPORT
82 #define HTTP_CLIENT_SHA512_256_SUPPORT DISABLED
83#elif (HTTP_CLIENT_SHA512_256_SUPPORT != ENABLED && HTTP_CLIENT_SHA512_256_SUPPORT != DISABLED)
84 #error HTTP_CLIENT_SHA512_256_SUPPORT parameter is not valid
88#ifndef HTTP_CLIENT_DEFAULT_TIMEOUT
89 #define HTTP_CLIENT_DEFAULT_TIMEOUT 20000
90#elif (HTTP_CLIENT_DEFAULT_TIMEOUT < 1000)
91 #error HTTP_CLIENT_DEFAULT_TIMEOUT parameter is not valid
95#ifndef HTTP_CLIENT_BUFFER_SIZE
96 #define HTTP_CLIENT_BUFFER_SIZE 2048
97#elif (HTTP_CLIENT_BUFFER_SIZE < 256)
98 #error HTTP_CLIENT_BUFFER_SIZE parameter is not valid
102#ifndef HTTP_CLIENT_TLS_TX_BUFFER_SIZE
103 #define HTTP_CLIENT_TLS_TX_BUFFER_SIZE 2048
104#elif (HTTP_CLIENT_TLS_TX_BUFFER_SIZE < 512)
105 #error HTTP_CLIENT_TLS_TX_BUFFER_SIZE parameter is not valid
109#ifndef HTTP_CLIENT_TLS_RX_BUFFER_SIZE
110 #define HTTP_CLIENT_TLS_RX_BUFFER_SIZE 16384
111#elif (HTTP_CLIENT_TLS_RX_BUFFER_SIZE < 512)
112 #error HTTP_CLIENT_TLS_RX_BUFFER_SIZE parameter is not valid
116#ifndef HTTP_CLIENT_MAX_METHOD_LEN
117 #define HTTP_CLIENT_MAX_METHOD_LEN 8
118#elif (HTTP_CLIENT_MAX_METHOD_LEN < 1)
119 #error HTTP_CLIENT_MAX_METHOD_LEN parameter is not valid
123#ifndef HTTP_CLIENT_MAX_USERNAME_LEN
124 #define HTTP_CLIENT_MAX_USERNAME_LEN 32
125#elif (HTTP_CLIENT_MAX_USERNAME_LEN < 0)
126 #error HTTP_CLIENT_MAX_USERNAME_LEN parameter is not valid
130#ifndef HTTP_CLIENT_MAX_PASSWORD_LEN
131 #define HTTP_CLIENT_MAX_PASSWORD_LEN 32
132#elif (HTTP_CLIENT_MAX_PASSWORD_LEN < 0)
133 #error HTTP_CLIENT_MAX_PASSWORD_LEN parameter is not valid
137#ifndef HTTP_CLIENT_MAX_REALM_LEN
138 #define HTTP_CLIENT_MAX_REALM_LEN 32
139#elif (HTTP_CLIENT_MAX_REALM_LEN < 1)
140 #error HTTP_CLIENT_MAX_REALM_LEN parameter is not valid
144#ifndef HTTP_CLIENT_MAX_NONCE_LEN
145 #define HTTP_CLIENT_MAX_NONCE_LEN 64
146#elif (HTTP_CLIENT_MAX_NONCE_LEN < 1)
147 #error HTTP_CLIENT_MAX_NONCE_LEN parameter is not valid
151#ifndef HTTP_CLIENT_CNONCE_SIZE
152 #define HTTP_CLIENT_CNONCE_SIZE 16
153#elif (HTTP_CLIENT_CNONCE_SIZE < 1)
154 #error HTTP_CLIENT_CNONCE_SIZE parameter is not valid
158#ifndef HTTP_CLIENT_MAX_OPAQUE_LEN
159 #define HTTP_CLIENT_MAX_OPAQUE_LEN 64
160#elif (HTTP_CLIENT_MAX_OPAQUE_LEN < 1)
161 #error HTTP_CLIENT_MAX_OPAQUE_LEN parameter is not valid
165#if (HTTP_CLIENT_BASIC_AUTH_SUPPORT == ENABLED)
166 #define HTTP_CLIENT_AUTH_SUPPORT ENABLED
167#elif (HTTP_CLIENT_DIGEST_AUTH_SUPPORT == ENABLED)
168 #define HTTP_CLIENT_AUTH_SUPPORT ENABLED
170 #define HTTP_CLIENT_AUTH_SUPPORT DISABLED
174#ifndef HTTP_CLIENT_PRIVATE_CONTEXT
175 #define HTTP_CLIENT_PRIVATE_CONTEXT
179#if (HTTP_CLIENT_TLS_SUPPORT == ENABLED)
180 #include "core/crypto.h"
185#if (HTTP_CLIENT_BASIC_AUTH_SUPPORT == ENABLED)
186 #include "core/crypto.h"
187 #include "encoding/base64.h"
191#if (HTTP_CLIENT_DIGEST_AUTH_SUPPORT == ENABLED)
192 #include "core/crypto.h"
193 #include "hash/hash_algorithms.h"
198#define HttpClientContext struct _HttpClientContext
212 HTTP_CLIENT_STATE_DISCONNECTED = 0,
213 HTTP_CLIENT_STATE_CONNECTING = 1,
214 HTTP_CLIENT_STATE_CONNECTED = 2,
215 HTTP_CLIENT_STATE_DISCONNECTING = 3
220#if (HTTP_CLIENT_TLS_SUPPORT == ENABLED)
246 char_t username[HTTP_CLIENT_MAX_USERNAME_LEN + 1];
247 char_t password[HTTP_CLIENT_MAX_PASSWORD_LEN + 1];
248 char_t realm[HTTP_CLIENT_MAX_REALM_LEN + 1];
249#if (HTTP_CLIENT_DIGEST_AUTH_SUPPORT == ENABLED)
253 char_t nonce[HTTP_CLIENT_MAX_NONCE_LEN + 1];
254 char_t cnonce[HTTP_CLIENT_CNONCE_SIZE * 2 + 1];
255 char_t opaque[HTTP_CLIENT_MAX_OPAQUE_LEN + 1];
273#if (HTTP_CLIENT_TLS_SUPPORT == ENABLED)
280#if (HTTP_CLIENT_AUTH_SUPPORT == ENABLED)
283#if (HTTP_CLIENT_DIGEST_AUTH_SUPPORT == ENABLED)
287 char_t
method[HTTP_CLIENT_MAX_METHOD_LEN + 1];
290 char_t
buffer[HTTP_CLIENT_BUFFER_SIZE + 1];
296 HTTP_CLIENT_PRIVATE_CONTEXT
301error_t httpClientInit(HttpClientContext *context);
303#if (HTTP_CLIENT_TLS_SUPPORT == ENABLED)
305error_t httpClientRegisterTlsInitCallback(HttpClientContext *context,
310error_t httpClientRegisterRandCallback(HttpClientContext *context,
316error_t httpClientSetAuthInfo(HttpClientContext *context,
317 const char_t *username,
const char_t *password);
319error_t httpClientBindToInterface(HttpClientContext *context,
320 NetInterface *interface);
322error_t httpClientConnect(HttpClientContext *context,
323 const IpAddr *serverIpAddr, uint16_t serverPort);
325error_t httpClientCreateRequest(HttpClientContext *context);
326error_t httpClientSetMethod(HttpClientContext *context,
const char_t *method);
327error_t httpClientSetUri(HttpClientContext *context,
const char_t *uri);
329error_t httpClientSetHost(HttpClientContext *context,
const char_t *host,
332error_t httpClientSetQueryString(HttpClientContext *context,
333 const char_t *queryString);
335error_t httpClientAddQueryParam(HttpClientContext *context,
336 const char_t *name,
const char_t *value);
338error_t httpClientAddHeaderField(HttpClientContext *context,
339 const char_t *name,
const char_t *value);
341error_t httpClientFormatHeaderField(HttpClientContext *context,
342 const char_t *name,
const char_t *format, ...);
344error_t httpClientSetContentLength(HttpClientContext *context,
size_t length);
345error_t httpClientWriteHeader(HttpClientContext *context);
347error_t httpClientWriteBody(HttpClientContext *context,
const void *data,
348 size_t length,
size_t *written, uint_t flags);
350error_t httpClientWriteTrailer(HttpClientContext *context);
352error_t httpClientReadHeader(HttpClientContext *context);
353uint_t httpClientGetStatus(HttpClientContext *context);
355const char_t *httpClientGetHeaderField(HttpClientContext *context,
358error_t httpClientGetNextHeaderField(HttpClientContext *context,
359 const char_t **name,
const char_t **value);
361error_t httpClientReadBody(HttpClientContext *context,
void *data,
362 size_t size,
size_t *received, uint_t flags);
364error_t httpClientReadTrailer(HttpClientContext *context);
365error_t httpClientCloseBody(HttpClientContext *context);
367error_t httpClientDisconnect(HttpClientContext *context);
368error_t httpClientClose(HttpClientContext *context);
370void httpClientDeinit(HttpClientContext *context);
error_t
Error codes.
Definition error.h:43
error_t(* HttpClientRandCallback)(uint8_t *data, size_t length)
Random data generation callback function.
Definition http_client.h:236
HttpClientState
HTTP client states.
Definition http_client.h:211
error_t(* HttpClientTlsInitCallback)(HttpClientContext *context, TlsContext *tlsContext)
TLS initialization callback function.
Definition http_client.h:226
Definitions common to HTTP client and server.
HttpRequestState
HTTP request states.
Definition http_common.h:110
HttpVersion
HTTP version numbers.
Definition http_common.h:60
HttpAuthMode
HTTP authentication schemes.
Definition http_common.h:72
HttpAuthQop
Quality of protection (digest authentication)
Definition http_common.h:84
uint32_t systime_t
System time.
Definition os_port_none.h:90
HTTP authentication parameters.
Definition http_client.h:244
const HashAlgo * algorithm
Digest algorithm.
Definition http_client.h:251
HttpAuthQop qop
Quality of protection.
Definition http_client.h:250
HttpAuthMode mode
HTTP authentication mode.
Definition http_client.h:245
bool_t stale
Stale flag.
Definition http_client.h:256
uint32_t nc
Nonce count.
Definition http_client.h:252
IP network address.
Definition ip.h:72
HTTP client context.
Definition http_client.h:266
uint16_t serverPort
TCP port number.
Definition http_client.h:279
size_t bufferLen
Length of the buffer, in bytes.
Definition http_client.h:291
char_t method[HTTP_CLIENT_MAX_METHOD_LEN+1]
HTTP request method.
Definition http_client.h:287
IpAddr serverIpAddr
IP address of the HTTP server.
Definition http_client.h:278
char_t buffer[HTTP_CLIENT_BUFFER_SIZE+1]
Memory buffer for input/output operations.
Definition http_client.h:290
size_t bodyLen
Length of the body, in bytes.
Definition http_client.h:293
bool_t keepAlive
HTTP persistent connection.
Definition http_client.h:288
NetInterface * interface
Underlying network interface.
Definition http_client.h:269
size_t bodyPos
Current position in the body.
Definition http_client.h:294
Socket * socket
Underlying socket.
Definition http_client.h:272
HttpRequestState requestState
HTTP request state.
Definition http_client.h:286
HttpVersion version
HTTP protocol version.
Definition http_client.h:268
systime_t timeout
Timeout value.
Definition http_client.h:270
uint_t statusCode
HTTP status code.
Definition http_client.h:295
bool_t chunkedEncoding
Chunked transfer encoding.
Definition http_client.h:289
HttpClientRandCallback randCallback
Random data generation callback function.
Definition http_client.h:284
systime_t timestamp
Timestamp to manage timeout.
Definition http_client.h:271
HttpClientAuthParams authParams
HTTP authentication parameters.
Definition http_client.h:281
HttpClientState state
HTTP client state.
Definition http_client.h:267
size_t bufferPos
Current position in the buffer.
Definition http_client.h:292
TlsSessionState tlsSession
TLS session state.
Definition http_client.h:275
HttpClientTlsInitCallback tlsInitCallback
TLS initialization callback function.
Definition http_client.h:276
TlsContext * tlsContext
TLS context.
Definition http_client.h:274