Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Modules | Data Structures | Macros | Typedefs | Enumerations | Functions

API to handle Hypertext Transfer Protocol (HTTP). More...

Modules

 HTTP Client
 API to perform HTTP(s) requests.
 
 HTTP Server
 API to make it possible to run an HTTP server to deliver and set values from other components.
 

Data Structures

struct  sol_http_content_type_priority
 Used to rank content type priorities. More...
 
struct  sol_http_param_value
 Used to define an HTTP parameter. More...
 
struct  sol_http_params
 Keep vector of HTTP parameters to be sent in a request. More...
 
struct  sol_http_response
 Handle for an HTTP response. More...
 
struct  sol_http_url
 Handle for an HTTP URL. More...
 

Macros

#define SOL_HTTP_PARAMS_CHECK_API_VERSION(params_,...)
 Macro used to check if a struct sol_http_params has the expected API version. More...
 
#define SOL_HTTP_PARAMS_CHECK_API_VERSION_GOTO(params_, label_)
 Macro used to check if a struct sol_http_params has the expected API version. More...
 
#define SOL_HTTP_PARAMS_FOREACH_IDX(param, itrvar, idx)
 Macro used to iterate over a vector of HTTP parameters. More...
 
#define SOL_HTTP_REQUEST_PARAM_ALLOW_REDIR(setting_)   SOL_HTTP_REQUEST_PARAM_BOOL(SOL_HTTP_PARAM_ALLOW_REDIR, setting_)
 Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_ALLOW_REDIR and true or false as value. More...
 
#define SOL_HTTP_REQUEST_PARAM_AUTH_BASIC(username_, password_)
 Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_AUTH_BASIC, username and password. More...
 
#define SOL_HTTP_REQUEST_PARAM_BOOL(type_, setting_)
 Macro to set a struct sol_http_param_value with a boolean and type passed as argument. More...
 
#define SOL_HTTP_REQUEST_PARAM_COOKIE(key_, value_)   SOL_HTTP_REQUEST_PARAM_KEY_VALUE(SOL_HTTP_PARAM_COOKIE, key_, value_)
 Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_COOKIE and key-value. More...
 
#define SOL_HTTP_REQUEST_PARAM_HEADER(header_, content_)   SOL_HTTP_REQUEST_PARAM_KEY_VALUE(SOL_HTTP_PARAM_HEADER, header_, content_)
 Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_HEADER, a header and content. More...
 
#define SOL_HTTP_REQUEST_PARAM_KEY_VALUE(type_, key_, value_)
 Macro to set a struct sol_http_param_value with key-value and type passed as argument. More...
 
#define SOL_HTTP_REQUEST_PARAM_POST_DATA_CONTENTS(key_, value_)
 Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_POST_DATA and the given value. More...
 
#define SOL_HTTP_REQUEST_PARAM_POST_DATA_FILE(key_, filename_)
 Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_POST_DATA and the contents of filename_. More...
 
#define SOL_HTTP_REQUEST_PARAM_POST_FIELD(key_, value_)   SOL_HTTP_REQUEST_PARAM_KEY_VALUE(SOL_HTTP_PARAM_POST_FIELD, key_, value_)
 Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_POST_FIELD and key-value. More...
 
#define SOL_HTTP_REQUEST_PARAM_QUERY(key_, value_)   SOL_HTTP_REQUEST_PARAM_KEY_VALUE(SOL_HTTP_PARAM_QUERY_PARAM, key_, value_)
 Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_QUERY_PARAM and key-value. More...
 
#define SOL_HTTP_REQUEST_PARAM_TIMEOUT(setting_)
 Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_TIMEOUT and timeout value. More...
 
#define SOL_HTTP_REQUEST_PARAM_VERBOSE(setting_)   SOL_HTTP_REQUEST_PARAM_BOOL(SOL_HTTP_PARAM_VERBOSE, setting_)
 Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_VERBOSE and true or false as value. More...
 
#define SOL_HTTP_REQUEST_PARAMS_INIT
 Macro used to initialize a struct sol_http_params with empty vector. More...
 
#define SOL_HTTP_RESPONSE_CHECK_API(response_,...)
 Macro used to check if a struct sol_http_response is valid (different from NULL) and has the expected API version or return. More...
 
#define SOL_HTTP_RESPONSE_CHECK_API_GOTO(response_, label)
 Macro used to check if a struct sol_http_response is valid (different from NULL) and has the expected API version or goto a label. More...
 
#define SOL_HTTP_RESPONSE_CHECK_API_VERSION(response_,...)
 Macro used to check if a struct sol_http_response has the expected API version or return. More...
 
#define SOL_HTTP_RESPONSE_CHECK_API_VERSION_GOTO(response_, label)
 Macro used to check if a struct sol_http_response has the expected API version or goto a label. More...
 

Typedefs

typedef struct sol_http_param_value sol_http_param_value
 Used to define an HTTP parameter. More...
 
typedef struct sol_http_params sol_http_params
 Keep vector of HTTP parameters to be sent in a request. More...
 
typedef struct sol_http_response sol_http_response
 Handle for an HTTP response. More...
 
typedef struct sol_http_url sol_http_url
 Handle for an HTTP URL. More...
 

Enumerations

enum  sol_http_method {
  SOL_HTTP_METHOD_GET, SOL_HTTP_METHOD_POST, SOL_HTTP_METHOD_HEAD, SOL_HTTP_METHOD_DELETE,
  SOL_HTTP_METHOD_PUT, SOL_HTTP_METHOD_CONNECT, SOL_HTTP_METHOD_OPTIONS, SOL_HTTP_METHOD_TRACE,
  SOL_HTTP_METHOD_PATCH, SOL_HTTP_METHOD_INVALID
}
 Type of HTTP method. More...
 
enum  sol_http_param_type {
  SOL_HTTP_PARAM_QUERY_PARAM, SOL_HTTP_PARAM_COOKIE, SOL_HTTP_PARAM_POST_FIELD, SOL_HTTP_PARAM_POST_DATA,
  SOL_HTTP_PARAM_HEADER, SOL_HTTP_PARAM_AUTH_BASIC, SOL_HTTP_PARAM_ALLOW_REDIR, SOL_HTTP_PARAM_TIMEOUT,
  SOL_HTTP_PARAM_VERBOSE, SOL_HTTP_PARAM_FRAGMENT
}
 Type of HTTP parameter. More...
 
enum  sol_http_status_code {
  SOL_HTTP_STATUS_OK = 200, SOL_HTTP_STATUS_FOUND = 302, SOL_HTTP_STATUS_SEE_OTHER = 303, SOL_HTTP_STATUS_NOT_MODIFIED = 304,
  SOL_HTTP_STATUS_BAD_REQUEST = 400, SOL_HTTP_STATUS_FORBIDDEN = 403, SOL_HTTP_STATUS_NOT_FOUND = 404, SOL_HTTP_STATUS_METHOD_NOT_ALLOWED = 405,
  SOL_HTTP_STATUS_INTERNAL_SERVER_ERROR = 500, SOL_HTTP_STATUS_NOT_IMPLEMENTED = 501
}
 Status codes as defined by HTTP protocol. More...
 

Functions

void sol_http_content_type_priorities_array_clear (struct sol_vector *priorities)
 Clears the priorities array. More...
 
int sol_http_create_full_uri (struct sol_buffer *buf, const struct sol_http_url url, const struct sol_http_params *params)
 Creates an URI based on struct sol_http_url and its parameters. More...
 
int sol_http_create_uri (struct sol_buffer *buf, const struct sol_str_slice base_uri, const struct sol_http_params *params)
 A simpler version of sol_http_create_full_uri(). More...
 
static int sol_http_create_uri_from_str (struct sol_buffer *buf, const char *base_url, const struct sol_http_params *params)
 A wrapper on top of sol_http_create_uri() More...
 
int sol_http_decode_params (const struct sol_str_slice params_slice, enum sol_http_param_type type, struct sol_http_params *params)
 Decodes HTTP parameters of a given type. More...
 
int sol_http_decode_slice (struct sol_buffer *buf, const struct sol_str_slice value)
 Decodes an URL string. More...
 
int sol_http_encode_params (struct sol_buffer *buf, enum sol_http_param_type type, const struct sol_http_params *params)
 Encodes HTTP parameters of a given type. More...
 
int sol_http_encode_slice (struct sol_buffer *buf, const struct sol_str_slice value)
 Encodes an URL string. More...
 
int sol_http_params_add (struct sol_http_params *params, struct sol_http_param_value value)
 Add a new parameter to HTTP parameters vector. More...
 
int sol_http_params_add_copy (struct sol_http_params *params, struct sol_http_param_value value)
 Add a new parameter to HTTP parameters vector copying strings. More...
 
void sol_http_params_clear (struct sol_http_params *params)
 Clear vector of HTTP parameters. More...
 
static void sol_http_params_init (struct sol_http_params *params)
 Initialize HTTP parameters struct with an empty vector. More...
 
int sol_http_parse_content_type_priorities (const struct sol_str_slice content_type, struct sol_vector *priorities)
 Sort the content type slice based on its priorities. More...
 
int sol_http_split_post_field (const char *query, struct sol_http_params *params)
 Split post/field string into parameters. More...
 
int sol_http_split_query (const char *query, struct sol_http_params *params)
 Split query into parameters. More...
 
int sol_http_split_uri (const struct sol_str_slice full_uri, struct sol_http_url *url)
 Split an URI. More...
 

Detailed Description

API to handle Hypertext Transfer Protocol (HTTP).

Macro Definition Documentation

#define SOL_HTTP_PARAMS_CHECK_API_VERSION (   params_,
  ... 
)
Value:
if (SOL_UNLIKELY((params_)->api_version != \
SOL_ERR("Unexpected API version (response is %" PRIu16 ", expected %" PRIu16 ")", \
(params_)->api_version, SOL_HTTP_PARAM_API_VERSION); \
return __VA_ARGS__; \
}
#define SOL_HTTP_PARAM_API_VERSION
Definition: sol-http.h:180
#define SOL_UNLIKELY(x)
Convenience macro for unlikely branch annotation.
Definition: sol-macros.h:201
#define SOL_ERR(fmt,...)
Logs a message with error level.
Definition: sol-log.h:632

Macro used to check if a struct sol_http_params has the expected API version.

In case it's a wrong version, it'll return extra arguments passed to the macro.

#define SOL_HTTP_PARAMS_CHECK_API_VERSION_GOTO (   params_,
  label_ 
)
Value:
if (SOL_UNLIKELY((params_)->api_version != \
SOL_ERR("Unexpected API version (params is %" PRIu16 ", expected %" PRIu16 ")", \
(params_)->api_version, SOL_HTTP_PARAM_API_VERSION); \
goto label_; \
}
#define SOL_HTTP_PARAM_API_VERSION
Definition: sol-http.h:180
#define SOL_UNLIKELY(x)
Convenience macro for unlikely branch annotation.
Definition: sol-macros.h:201
#define SOL_ERR(fmt,...)
Logs a message with error level.
Definition: sol-log.h:632

Macro used to check if a struct sol_http_params has the expected API version.

In case it's a wrong version, it'll go to label.

#define SOL_HTTP_PARAMS_FOREACH_IDX (   param,
  itrvar,
  idx 
)
Value:
for (idx = 0; \
param && idx < (param)->params.len && (itrvar = (struct sol_http_param_value *)sol_vector_get(&(param)->params, idx), true); \
idx++)
Used to define an HTTP parameter.
Definition: sol-http.h:215
static void * sol_vector_get(const struct sol_vector *v, uint16_t i)
Return the element of the vector at the given index.
Definition: sol-vector.h:146

Macro used to iterate over a vector of HTTP parameters.

struct sol_http_request *request = X;
uint16_t idx;
value, idx) {
// do something with value
}
Examples:
/src/samples/http/client.c.

Referenced by response_cb().

#define SOL_HTTP_REQUEST_PARAM_ALLOW_REDIR (   setting_)    SOL_HTTP_REQUEST_PARAM_BOOL(SOL_HTTP_PARAM_ALLOW_REDIR, setting_)

Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_ALLOW_REDIR and true or false as value.

#define SOL_HTTP_REQUEST_PARAM_AUTH_BASIC (   username_,
  password_ 
)
Value:
.value = { \
.auth = { \
.user = sol_str_slice_from_str((username_ ? : "")), \
.password = sol_str_slice_from_str((password_ ? : "")) \
} \
} \
}
Definition: sol-http.h:111
static struct sol_str_slice sol_str_slice_from_str(const char *s)
Populates a slice from a string.
Definition: sol-str-slice.h:238
Used to define an HTTP parameter.
Definition: sol-http.h:215

Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_AUTH_BASIC, username and password.

#define SOL_HTTP_REQUEST_PARAM_BOOL (   type_,
  setting_ 
)
Value:
.type = type_, \
.value = { .boolean = { .value = (setting_) } } \
}
Used to define an HTTP parameter.
Definition: sol-http.h:215

Macro to set a struct sol_http_param_value with a boolean and type passed as argument.

#define SOL_HTTP_REQUEST_PARAM_COOKIE (   key_,
  value_ 
)    SOL_HTTP_REQUEST_PARAM_KEY_VALUE(SOL_HTTP_PARAM_COOKIE, key_, value_)

Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_COOKIE and key-value.

#define SOL_HTTP_REQUEST_PARAM_HEADER (   header_,
  content_ 
)    SOL_HTTP_REQUEST_PARAM_KEY_VALUE(SOL_HTTP_PARAM_HEADER, header_, content_)

Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_HEADER, a header and content.

Examples:
/src/samples/http/server.c.

Referenced by request_cb(), and sol_http_response_set_sse_headers().

#define SOL_HTTP_REQUEST_PARAM_KEY_VALUE (   type_,
  key_,
  value_ 
)
Value:
.type = type_, \
.value = { \
.key_value = { \
.key = sol_str_slice_from_str((key_ ? : "")), \
.value = sol_str_slice_from_str((value_ ? : "")) \
} \
} \
}
static struct sol_str_slice sol_str_slice_from_str(const char *s)
Populates a slice from a string.
Definition: sol-str-slice.h:238
Used to define an HTTP parameter.
Definition: sol-http.h:215

Macro to set a struct sol_http_param_value with key-value and type passed as argument.

#define SOL_HTTP_REQUEST_PARAM_POST_DATA_CONTENTS (   key_,
  value_ 
)
Value:
.value = { \
.data = { \
.key = sol_str_slice_from_str((key_ ? : "")), \
.value = (value_), \
} \
} \
}
struct sol_str_slice filename
Definition: sol-http.h:235
Definition: sol-http.h:109
static struct sol_str_slice sol_str_slice_from_str(const char *s)
Populates a slice from a string.
Definition: sol-str-slice.h:238
Used to define an HTTP parameter.
Definition: sol-http.h:215
#define SOL_STR_SLICE_EMPTY
Helper macro to make easier to declare an empty string slice.
Definition: sol-str-slice.h:72

Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_POST_DATA and the given value.

#define SOL_HTTP_REQUEST_PARAM_POST_DATA_FILE (   key_,
  filename_ 
)
Value:
.value = { \
.data = { \
.key = sol_str_slice_from_str((key_ ? : "")), \
.value = SOL_STR_SLICE_EMPTY, \
.filename = sol_str_slice_from_str((filename_ ? : "")) \
} \
} \
}
Definition: sol-http.h:109
static struct sol_str_slice sol_str_slice_from_str(const char *s)
Populates a slice from a string.
Definition: sol-str-slice.h:238
Used to define an HTTP parameter.
Definition: sol-http.h:215
#define SOL_STR_SLICE_EMPTY
Helper macro to make easier to declare an empty string slice.
Definition: sol-str-slice.h:72

Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_POST_DATA and the contents of filename_.

#define SOL_HTTP_REQUEST_PARAM_POST_FIELD (   key_,
  value_ 
)    SOL_HTTP_REQUEST_PARAM_KEY_VALUE(SOL_HTTP_PARAM_POST_FIELD, key_, value_)

Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_POST_FIELD and key-value.

#define SOL_HTTP_REQUEST_PARAM_QUERY (   key_,
  value_ 
)    SOL_HTTP_REQUEST_PARAM_KEY_VALUE(SOL_HTTP_PARAM_QUERY_PARAM, key_, value_)

Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_QUERY_PARAM and key-value.

#define SOL_HTTP_REQUEST_PARAM_TIMEOUT (   setting_)
Value:
.value = { \
.integer = { .value = (setting_) } \
} \
}
Definition: sol-http.h:113
Used to define an HTTP parameter.
Definition: sol-http.h:215

Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_TIMEOUT and timeout value.

#define SOL_HTTP_REQUEST_PARAM_VERBOSE (   setting_)    SOL_HTTP_REQUEST_PARAM_BOOL(SOL_HTTP_PARAM_VERBOSE, setting_)

Macro to set a struct sol_http_param_value with type SOL_HTTP_PARAM_VERBOSE and true or false as value.

#define SOL_HTTP_REQUEST_PARAMS_INIT
Value:
(struct sol_http_params) { \
.arena = NULL \
}
#define SOL_HTTP_PARAM_API_VERSION
Definition: sol-http.h:180
uint16_t api_version
Definition: sol-http.h:181
#define SOL_VECTOR_INIT(TYPE)
Helper macro to initialize a sol_vector structure to hold elements of type TYPE.
Definition: sol-vector.h:70
Used to define an HTTP parameter.
Definition: sol-http.h:215
Keep vector of HTTP parameters to be sent in a request.
Definition: sol-http.h:178
#define SOL_SET_API_VERSION(expression)
This macro will cope with SOL_NO_API_VERSION and allows easy declaration of api_version fields...
Definition: sol-mainloop.h:660

Macro used to initialize a struct sol_http_params with empty vector.

See Also
sol_http_params_init()
Examples:
/src/samples/http/client.c, /src/samples/http/server-https.c, /src/samples/http/server-sse.c, and /src/samples/http/server.c.

Referenced by request_cb(), request_events_cb(), and startup().

#define SOL_HTTP_RESPONSE_CHECK_API (   response_,
  ... 
)
Value:
do { \
if (SOL_UNLIKELY(!(response_))) { \
SOL_WRN("Error while reaching service."); \
return __VA_ARGS__; \
} \
SOL_HTTP_RESPONSE_CHECK_API_VERSION((response_), __VA_ARGS__) \
} while (0)
#define SOL_HTTP_RESPONSE_CHECK_API_VERSION(response_,...)
Macro used to check if a struct sol_http_response has the expected API version or return...
Definition: sol-http.h:287
#define SOL_WRN(fmt,...)
Logs a message with warning level.
Definition: sol-log.h:645
#define SOL_UNLIKELY(x)
Convenience macro for unlikely branch annotation.
Definition: sol-macros.h:201

Macro used to check if a struct sol_http_response is valid (different from NULL) and has the expected API version or return.

In case it's NULL or a wrong version, it'll return extra arguments passed to the macro.

#define SOL_HTTP_RESPONSE_CHECK_API_GOTO (   response_,
  label 
)
Value:
do { \
if (SOL_UNLIKELY(!(response_))) { \
SOL_WRN("Error while reaching service."); \
goto label; \
} \
} while (0)
#define SOL_WRN(fmt,...)
Logs a message with warning level.
Definition: sol-log.h:645
#define SOL_UNLIKELY(x)
Convenience macro for unlikely branch annotation.
Definition: sol-macros.h:201
#define SOL_HTTP_RESPONSE_CHECK_API_VERSION_GOTO(response_, label)
Macro used to check if a struct sol_http_response has the expected API version or goto a label...
Definition: sol-http.h:321

Macro used to check if a struct sol_http_response is valid (different from NULL) and has the expected API version or goto a label.

In case it's NULL or a wrong version, it'll go to label.

#define SOL_HTTP_RESPONSE_CHECK_API_VERSION (   response_,
  ... 
)
Value:
if (SOL_UNLIKELY((response_)->api_version != \
SOL_ERR("Unexpected API version (response is %" PRIu16 ", expected %" PRIu16 ")", \
return __VA_ARGS__; \
}
uint16_t api_version
Definition: sol-http.h:181
#define SOL_UNLIKELY(x)
Convenience macro for unlikely branch annotation.
Definition: sol-macros.h:201
#define SOL_ERR(fmt,...)
Logs a message with error level.
Definition: sol-log.h:632
#define SOL_HTTP_RESPONSE_API_VERSION
Definition: sol-http.h:250

Macro used to check if a struct sol_http_response has the expected API version or return.

In case it's a wrong version, it'll return extra arguments passed to the macro.

#define SOL_HTTP_RESPONSE_CHECK_API_VERSION_GOTO (   response_,
  label 
)
Value:
if (SOL_UNLIKELY((response_)->api_version != \
SOL_ERR("Unexpected API version (response is %" PRIu16 ", expected %" PRIu16 ")", \
goto label; \
}
uint16_t api_version
Definition: sol-http.h:181
#define SOL_UNLIKELY(x)
Convenience macro for unlikely branch annotation.
Definition: sol-macros.h:201
#define SOL_ERR(fmt,...)
Logs a message with error level.
Definition: sol-log.h:632
#define SOL_HTTP_RESPONSE_API_VERSION
Definition: sol-http.h:250

Macro used to check if a struct sol_http_response has the expected API version or goto a label.

In case it's a wrong version, it'll go to label.

Typedef Documentation

Used to define an HTTP parameter.

A parameter is defined by its type (one of enum sol_http_param_type) and its value. It may be a key-value parameter, authentication (user-password), or data.

Keep vector of HTTP parameters to be sent in a request.

It's required to make requests, with sol_http_client_request() or sol_http_client_request_with_interface() or to create URIs, with sol_http_create_uri() and variants.

Handle for an HTTP response.

A response is composed by a response code, that may be one of enum sol_http_status_code, a vector of parameters, URL, definition of content type, like "text" or "application/json", and the response content itself.

typedef struct sol_http_url sol_http_url

Handle for an HTTP URL.

Uniform Resource Locator conforms to the following syntax:

scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]

Enumeration Type Documentation

Type of HTTP method.

One of these must be chosen to make a request, with sol_http_client_request() or sol_http_client_request_with_interface()

Enumerator
SOL_HTTP_METHOD_GET 

Requests data from a specified resource.

SOL_HTTP_METHOD_POST 

Submits data to be processed to a specified resource.

SOL_HTTP_METHOD_HEAD 

Same as GET, but transfers the status line and header section only.

SOL_HTTP_METHOD_DELETE 

Removes all current representations of the target resource given by a URI.

SOL_HTTP_METHOD_PUT 

Replaces all current representations of the target resource with the uploaded content.

SOL_HTTP_METHOD_CONNECT 

Establishes a tunnel to the server identified by a given URI.

SOL_HTTP_METHOD_OPTIONS 

Describes the communication options for the target resource.

SOL_HTTP_METHOD_TRACE 

Performs a message loop-back test along the path to the target resource.

SOL_HTTP_METHOD_PATCH 

Used to update partial resources.

SOL_HTTP_METHOD_INVALID 

client makes an HTTP request by using an HTTP method that does not comply with the HTTP specifications

Type of HTTP parameter.

It should be used to encode and decode parameters, with sol_http_encode_params() and sol_http_decode_params().

Note
SOL_HTTP_PARAM_POST_FIELD and SOL_HTTP_PARAM_POST_DATA are both used for setting the data of a POST request, but only one can be used per request.
Enumerator
SOL_HTTP_PARAM_QUERY_PARAM 
SOL_HTTP_PARAM_COOKIE 
SOL_HTTP_PARAM_POST_FIELD 
SOL_HTTP_PARAM_POST_DATA 
SOL_HTTP_PARAM_HEADER 
SOL_HTTP_PARAM_AUTH_BASIC 
SOL_HTTP_PARAM_ALLOW_REDIR 
SOL_HTTP_PARAM_TIMEOUT 
SOL_HTTP_PARAM_VERBOSE 
SOL_HTTP_PARAM_FRAGMENT 

Status codes as defined by HTTP protocol.

Most frequently used status are supported.

Enumerator
SOL_HTTP_STATUS_OK 

The request has been accepted for processing.

SOL_HTTP_STATUS_FOUND 

Provides an URL in the location header field.

SOL_HTTP_STATUS_SEE_OTHER 

The response to the request can be found under another URI using a GET method.

SOL_HTTP_STATUS_NOT_MODIFIED 

Indicates that the resource has not been modified since the version specified by the request headers.

SOL_HTTP_STATUS_BAD_REQUEST 

The server cannot or will not process the request due to an apparent client error.

SOL_HTTP_STATUS_FORBIDDEN 

The request was a valid request, but the server is refusing to respond to it.

SOL_HTTP_STATUS_NOT_FOUND 

The requested resource could not be found.

SOL_HTTP_STATUS_METHOD_NOT_ALLOWED 

A request method is not supported for the requested resource.

SOL_HTTP_STATUS_INTERNAL_SERVER_ERROR 

A generic error message.

SOL_HTTP_STATUS_NOT_IMPLEMENTED 

The server either does not recognize the request method, or it lacks the ability to fulfill the request.

Function Documentation

void sol_http_content_type_priorities_array_clear ( struct sol_vector priorities)

Clears the priorities array.

Parameters
prioritiesAn array of sol_http_content_type_priority.
See Also
sol_http_parse_content_type_priorities()
int sol_http_create_full_uri ( struct sol_buffer buf,
const struct sol_http_url  url,
const struct sol_http_params params 
)

Creates an URI based on struct sol_http_url and its parameters.

Parameters
bufWhere the created URI should be appended (the buffer must be already initialized)
urlThe URL parameters.
paramsThe query and cookies params.
Returns
0 on success, negative number on error.
int sol_http_create_uri ( struct sol_buffer buf,
const struct sol_str_slice  base_uri,
const struct sol_http_params params 
)

A simpler version of sol_http_create_full_uri().

Parameters
bufWhere the created URI should be appended (the buffer must be already initialized)
base_uriThe base URI to be used.
paramsThe query and cookies params.
Returns
0 on success, negative number on error.

Referenced by sol_http_create_uri_from_str().

static int sol_http_create_uri_from_str ( struct sol_buffer buf,
const char *  base_url,
const struct sol_http_params params 
)
inlinestatic

A wrapper on top of sol_http_create_uri()

Parameters
bufWhere the created URI should be appended (the buffer must be already initialized)
base_urlThe base URI to be used.
paramsThe query and cookies params.
Returns
0 on success, negative number on error.

References sol_http_create_uri(), and sol_str_slice_from_str().

int sol_http_decode_params ( const struct sol_str_slice  params_slice,
enum sol_http_param_type  type,
struct sol_http_params params 
)

Decodes HTTP parameters of a given type.

Parameters
params_sliceWhere the decoded parameters will be stored as string.
typeThe parameter that should be decoded.
paramsThe parameters to be decoded.
Returns
0 on success, negative number on error.
Note
params_slice and params must be valid pointers.
int sol_http_decode_slice ( struct sol_buffer buf,
const struct sol_str_slice  value 
)

Decodes an URL string.

If the string was not decoded this function will simply copy the slice's contents to the buffer and set SOL_BUFFER_FLAGS_MEMORY_NOT_OWNED on the buffer's flags.

Parameters
bufThe buffer that will hold the decoded string (it will be initialized by this function)
valueA slice to be decoded.
Note
if it's required to keep or change the buffer contents sol_buffer_steal_or_copy() should be used.
Returns
0 on success, negative number on error.
int sol_http_encode_params ( struct sol_buffer buf,
enum sol_http_param_type  type,
const struct sol_http_params params 
)

Encodes HTTP parameters of a given type.

Parameters
bufWhere the encoded parameters will be stored as string.
typeThe parameter that should be encoded.
paramsThe parameters to be encoded.
Returns
0 on success, negative number on error.
Note
The buf must be initialized in order to use this function.
int sol_http_encode_slice ( struct sol_buffer buf,
const struct sol_str_slice  value 
)

Encodes an URL string.

If the string was not encoded this function will simply copy the slice's content to the buffer and set SOL_BUFFER_FLAGS_MEMORY_NOT_OWNED on the buffer's flags.

Parameters
bufThe buffer that will hold the encoded string (it will be initialized by this function)
valueA slice to be encoded.
Note
if it's required to keep or change the buffer contents sol_buffer_steal_or_copy() should be used.
Returns
0 on success, negative number on error.
int sol_http_params_add ( struct sol_http_params params,
struct sol_http_param_value  value 
)

Add a new parameter to HTTP parameters vector.

Parameters
paramsParameters handle.
valueParameter to be added to the vector.
Note
Difference between sol_http_params_add_copy() and sol_http_params_add() is that the first will keep a copy of any string slices.
Returns
true on success and false on error.
Examples:
/src/samples/http/server.c.

Referenced by request_cb(), and sol_http_response_set_sse_headers().

int sol_http_params_add_copy ( struct sol_http_params params,
struct sol_http_param_value  value 
)

Add a new parameter to HTTP parameters vector copying strings.

Parameters
paramsParameters handle.
valueParameter to be added to the vector.
Note
Difference between sol_http_params_add_copy() and sol_http_params_add() is that the first will keep a copy of any string slices.
Returns
0 on success and -errno on error.
Examples:
/src/samples/http/client.c.

Referenced by create_header_params(), and create_post_data_params().

void sol_http_params_clear ( struct sol_http_params params)

Clear vector of HTTP parameters.

It clear parameters vector and also any eventual copy of slices done with sol_http_params_add_copy()

Returns
0 on success and -errno on error.
Parameters
paramsParameters handle.
Examples:
/src/samples/http/client.c, /src/samples/http/server-sse.c, and /src/samples/http/server.c.

Referenced by request_cb(), request_events_cb(), and startup().

static void sol_http_params_init ( struct sol_http_params params)
inlinestatic

Initialize HTTP parameters struct with an empty vector.

Parameters
paramsParameters handle to be initialized.
See Also
SOL_HTTP_REQUEST_PARAMS_INIT

References sol_http_params::api_version, sol_http_params::arena, sol_http_params::params, SOL_HTTP_PARAM_API_VERSION, SOL_SET_API_VERSION, and sol_vector_init().

int sol_http_parse_content_type_priorities ( const struct sol_str_slice  content_type,
struct sol_vector priorities 
)

Sort the content type slice based on its priorities.

For more information about how the content type is sorted check: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1

Parameters
content_typeA content type slice. Example: "text/html, application/json;q=0.5"
prioritiesAn array to store the content type prioriries (it will be initialized by this function)
See Also
sol_http_content_type_priorities_array_clear()
sol_http_content_type_priority
int sol_http_split_post_field ( const char *  query,
struct sol_http_params params 
)

Split post/field string into parameters.

This function will receive a string and split and store its values in the sol_http_params.

Parameters
queryA string to be splitted.
paramsWhere the post/field parameters will be stored.
Returns
0 on success, negative number on error.
Examples:
/src/samples/http/client.c.

Referenced by create_post_field_params().

int sol_http_split_query ( const char *  query,
struct sol_http_params params 
)

Split query into parameters.

This function will receive a query and split and store its values in the sol_http_params struct.

Parameters
queryA query to be splitted.
paramsWhere the query parameters will be stored.
Returns
0 on success, negative number on error.
int sol_http_split_uri ( const struct sol_str_slice  full_uri,
struct sol_http_url url 
)

Split an URI.

This function will receive a complete URI and split and store its values in the sol_http_url struct.

Parameters
full_uriAn URI to be splitted.
urlWhere the URL parts will be stored.
Returns
0 on success, negative number on error.
Note
This function will not decoded the URI.