Go to the documentation of this file.
31 #ifndef _HTTP_CLIENT_H
32 #define _HTTP_CLIENT_H
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)
185 #if (HTTP_CLIENT_BASIC_AUTH_SUPPORT == ENABLED)
191 #if (HTTP_CLIENT_DIGEST_AUTH_SUPPORT == ENABLED)
198 #define HttpClientContext struct _HttpClientContext
220 #if (HTTP_CLIENT_TLS_SUPPORT == ENABLED)
249 #if (HTTP_CLIENT_DIGEST_AUTH_SUPPORT == ENABLED)
273 #if (HTTP_CLIENT_TLS_SUPPORT == ENABLED)
280 #if (HTTP_CLIENT_AUTH_SUPPORT == ENABLED)
283 #if (HTTP_CLIENT_DIGEST_AUTH_SUPPORT == ENABLED)
303 #if (HTTP_CLIENT_TLS_SUPPORT == ENABLED)
323 const IpAddr *serverIpAddr, uint16_t serverPort);
333 const char_t *queryString);
error_t httpClientGetNextHeaderField(HttpClientContext *context, const char_t **name, const char_t **value)
Iterate through the HTTP response header.
#define HTTP_CLIENT_MAX_PASSWORD_LEN
HttpClientState
HTTP client states.
NetInterface * interface
Underlying network interface.
error_t httpClientCloseBody(HttpClientContext *context)
Close HTTP request or response body.
error_t httpClientSetAuthInfo(HttpClientContext *context, const char_t *username, const char_t *password)
Set authentication information.
Socket * socket
Underlying socket.
HttpVersion
HTTP version numbers.
error_t httpClientWriteBody(HttpClientContext *context, const void *data, size_t length, size_t *written, uint_t flags)
Write HTTP request body.
HttpClientRandCallback randCallback
Random data generation callback function.
error_t(* HttpClientTlsInitCallback)(HttpClientContext *context, TlsContext *tlsContext)
TLS initialization callback function.
error_t httpClientWriteHeader(HttpClientContext *context)
Write HTTP request header.
HttpClientState state
HTTP client state.
error_t httpClientSetHost(HttpClientContext *context, const char_t *host, uint16_t port)
Set the hostname and port number of the resource being requested.
error_t httpClientSetVersion(HttpClientContext *context, HttpVersion version)
Set the HTTP protocol version to be used.
uint_t httpClientGetStatus(HttpClientContext *context)
Retrieve the HTTP status code of the response.
HttpClientTlsInitCallback tlsInitCallback
TLS initialization callback function.
size_t bufferLen
Length of the buffer, in bytes.
bool_t keepAlive
HTTP persistent connection.
void httpClientDeinit(HttpClientContext *context)
Release HTTP client context.
#define HTTP_CLIENT_MAX_METHOD_LEN
error_t httpClientSetContentLength(HttpClientContext *context, size_t length)
Set the length of the HTTP request body.
error_t httpClientAddQueryParam(HttpClientContext *context, const char_t *name, const char_t *value)
Add a key/value pair to the query string.
error_t httpClientClose(HttpClientContext *context)
Close the connection with the HTTP server.
HttpClientAuthParams authParams
HTTP authentication parameters.
error_t httpClientReadTrailer(HttpClientContext *context)
Read HTTP trailer.
TlsContext * tlsContext
TLS context.
uint16_t serverPort
TCP port number.
error_t httpClientWriteTrailer(HttpClientContext *context)
Write HTTP trailer.
IpAddr serverIpAddr
IP address of the HTTP server.
error_t httpClientSetQueryString(HttpClientContext *context, const char_t *queryString)
Set query string.
#define HttpClientContext
#define HTTP_CLIENT_MAX_OPAQUE_LEN
TlsSessionState tlsSession
TLS session state.
error_t httpClientConnect(HttpClientContext *context, const IpAddr *serverIpAddr, uint16_t serverPort)
Establish a connection with the specified HTTP server.
General definitions for cryptographic algorithms.
#define HTTP_CLIENT_MAX_NONCE_LEN
const char_t * httpClientGetHeaderField(HttpClientContext *context, const char_t *name)
Retrieve the value of the specified header field name.
error_t httpClientInit(HttpClientContext *context)
Initialize HTTP client context.
#define HTTP_CLIENT_MAX_REALM_LEN
@ HTTP_CLIENT_STATE_DISCONNECTING
error_t httpClientRegisterRandCallback(HttpClientContext *context, HttpClientRandCallback callback)
Register random data generation callback function.
char_t buffer[HTTP_CLIENT_BUFFER_SIZE+1]
Memory buffer for input/output operations.
HttpAuthQop
Quality of protection (digest authentication)
uint_t statusCode
HTTP status code.
error_t httpClientAddHeaderField(HttpClientContext *context, const char_t *name, const char_t *value)
Add a header field to the HTTP request.
error_t httpClientSetTimeout(HttpClientContext *context, systime_t timeout)
Set communication timeout.
Collection of hash algorithms.
error_t(* HttpClientRandCallback)(uint8_t *data, size_t length)
Random data generation callback function.
error_t httpClientDisconnect(HttpClientContext *context)
Gracefully disconnect from the HTTP server.
uint32_t systime_t
System time.
bool_t chunkedEncoding
Chunked transfer encoding.
Definitions common to HTTP client and server.
char_t method[HTTP_CLIENT_MAX_METHOD_LEN+1]
HTTP request method.
error_t httpClientBindToInterface(HttpClientContext *context, NetInterface *interface)
Bind the HTTP client to a particular network interface.
size_t bodyPos
Current position in the body.
error_t httpClientCreateRequest(HttpClientContext *context)
Create a new HTTP request.
HttpAuthQop qop
Quality of protection.
#define HTTP_CLIENT_MAX_USERNAME_LEN
systime_t timeout
Timeout value.
const HashAlgo * algorithm
Digest algorithm.
error_t httpClientReadHeader(HttpClientContext *context)
Read HTTP response header.
HTTP authentication parameters.
#define HTTP_CLIENT_CNONCE_SIZE
@ HTTP_CLIENT_STATE_DISCONNECTED
@ HTTP_CLIENT_STATE_CONNECTING
size_t bufferPos
Current position in the buffer.
TLS (Transport Layer Security)
systime_t timestamp
Timestamp to manage timeout.
#define HTTP_CLIENT_PRIVATE_CONTEXT
#define HTTP_CLIENT_BUFFER_SIZE
Common interface for hash algorithms.
size_t bodyLen
Length of the body, in bytes.
error_t httpClientRegisterTlsInitCallback(HttpClientContext *context, HttpClientTlsInitCallback callback)
Register TLS initialization callback function.
HttpVersion version
HTTP protocol version.
error_t httpClientReadBody(HttpClientContext *context, void *data, size_t size, size_t *received, uint_t flags)
Read HTTP response body.
HttpRequestState
HTTP request states.
@ HTTP_CLIENT_STATE_CONNECTED
HttpAuthMode
HTTP authentication schemes.
error_t httpClientSetMethod(HttpClientContext *context, const char_t *method)
Set HTTP request method.
error_t httpClientSetUri(HttpClientContext *context, const char_t *uri)
Set request URI.
HttpAuthMode mode
HTTP authentication mode.
HttpRequestState requestState
HTTP request state.
error_t httpClientFormatHeaderField(HttpClientContext *context, const char_t *name, const char_t *format,...)
Format an HTTP header field.