HTTP Client
HTTP client functions. More...
Modules |
|
Types | |
HTTP client data types.
|
|
Functions |
|
gos_result_t | gos_http_open_request (const gos_http_request_t *context, gos_handle_t *handle_ptr) |
Open a HTTP request stream.
More...
|
|
gos_result_t | gos_http_get (const gos_http_request_t *context, gos_handle_t *handle_ptr) |
HTTP GET request stream.
More...
|
|
gos_result_t | gos_http_post (const gos_http_request_t *context, gos_handle_t *handle_ptr) |
HTTP POST request stream.
More...
|
|
gos_result_t | gos_http_add_header ( gos_handle_t handle, const char *key, const char *value) |
Add HTTP header to request stream.
More...
|
|
gos_result_t | gos_http_write ( gos_handle_t handle, const void *data, uint32_t size, bool auto_flush) |
Write data to a HTTP POST request stream.
More...
|
|
gos_result_t | gos_http_read ( gos_handle_t handle, void *data, uint32_t max_size, uint32_t *bytes_read_ptr) |
Read HTTP GET/POST response stream.
More...
|
|
gos_result_t | gos_http_read_with_buffer ( gos_handle_t handle, gos_buffer_t *buffer) |
Read HTTP stream data into buffer.
More...
|
|
gos_result_t | gos_http_poll ( gos_handle_t handle, uint32_t *rx_available_ptr, uint32_t *tx_available_ptr) |
Poll HTTP stream for more response data.
More...
|
|
gos_result_t | gos_http_read_status ( gos_handle_t handle, uint32_t *status_ptr) |
Complete HTTP request stream and return HTTP status code.
More...
|
|
gos_result_t | gos_http_receive_response ( gos_handle_t handle, gos_http_response_t *response) |
Receive the HTTP response headers.
More...
|
|
gos_result_t | gos_http_receive_response_with_config ( gos_handle_t handle, gos_http_response_t *response, const gos_http_response_config_t *config) |
Receive the HTTP response header with specified configuration.
More...
|
|
void | gos_http_response_cleanup ( gos_http_response_t *response) |
Cleanup a HTTP response.
More...
|
|
gos_result_t | gos_http_close ( gos_handle_t handle) |
Close HTTP request stream.
More...
|
|
Detailed Description
HTTP client functions.
Function Documentation
◆ gos_http_add_header()
gos_result_t gos_http_add_header | ( | gos_handle_t |
handle,
|
const char * |
key,
|
||
const char * |
value
|
||
) |
Add HTTP header to request stream.
The HTTP request stream should have been previously opened with one of the following:
See Gecko OS Command API documentation: http_add_header .
- Note
- Stream handles start at 1, max handle value is GOS_MAX_STREAMS
- Parameters
-
[in] handle
Handle of opened HTTP request [in] key
HTTP request header key [in] value
HTTP request header value
- Returns
- gos_result_t return of API call
◆ gos_http_close()
gos_result_t gos_http_close | ( | gos_handle_t |
handle
|
) |
Close HTTP request stream.
This closes an opened HTTP stream.
See Gecko OS Command API documentation: stream_close .
- Note
- Stream handles start at 1, max handle value is GOS_MAX_STREAMS
- Parameters
-
[in] handle
Handle of opened HTTP stream to close
- Returns
- gos_result_t return of API call
◆ gos_http_get()
gos_result_t gos_http_get | ( | const gos_http_request_t * |
context,
|
gos_handle_t * |
handle_ptr
|
||
) |
HTTP GET request stream.
This has the same functionality as gos_http_open_request() except a GET request is opened.
After the GET request is opened, gos_http_add_header() may be used to append additional headers to the request.
To receive the request response, use one the following:
Once the response is received use gos_http_read() to ready the response body.
Use gos_http_close() to close the HTTP stream.
See Gecko OS Command API documentation for additionality info: http_get .
- Parameters
-
[in] context
gos_http_request_t Information about the HTTP GET request [out] handle_ptr
Stream handle of HTTP GET request
- Returns
- gos_result_t return of API call
◆ gos_http_open_request()
gos_result_t gos_http_open_request | ( | const gos_http_request_t * |
context,
|
gos_handle_t * |
handle_ptr
|
||
) |
Open a HTTP request stream.
This allows for opening a HTTP request specified in gos_http_request_t . Once opened a handle is returned. The handle may be used with any of the following APIs:
- gos_http_add_header()
- gos_http_write()
- gos_http_read_status()
- gos_http_receive_response()
- gos_http_receive_response_with_config()
- gos_http_close()
- Note
- This API only opens the HTTP request with the server. The one following APIs should be used to receive the response:
Once the response is received use gos_http_read() to ready the response body. If gos_http_receive_response() or gos_http_receive_response_with_config() is used, then 'content_length' of gos_http_response_t contains the amount of data to be read. gos_http_poll() can also be used to determine the amount of data to be read.
Use gos_http_close() to close the HTTP stream.
- Parameters
-
[in] context
gos_http_request_t Information about the HTTP request [out] handle_ptr
Stream handle of HTTP request
- Returns
- gos_result_t return of API call
◆ gos_http_poll()
gos_result_t gos_http_poll | ( | gos_handle_t |
handle,
|
uint32_t * |
rx_available_ptr,
|
||
uint32_t * |
tx_available_ptr
|
||
) |
Poll HTTP stream for more response data.
This read an open HTTP stream for more response body data.
The HTTP response should then have been previously received with one of the following:
- Note
- Stream handles start at 1, max handle value is GOS_MAX_STREAMS
- Parameters
-
[in] handle
Handle of opened HTTP request [out] rx_available_ptr
Pointer to hold number of bytes available to read [out] tx_available_ptr
Pointer to hold available TX buffer space
- Returns
- gos_result_t return of API call
◆ gos_http_post()
gos_result_t gos_http_post | ( | const gos_http_request_t * |
context,
|
gos_handle_t * |
handle_ptr
|
||
) |
HTTP POST request stream.
This has the same functionality as gos_http_open_request() except a POST request is opened.
After the POST request is opened, gos_http_add_header() may be used to append additional headers to the request.
gos_http_write() is then used to send the HTTP POST data.
- Note
- If the 'content_length' member of gos_http_request_t is set to '-1', chunked encoding is used. This allows for arbitrary amounts of data to be sent to the server. If 'content_length' is greater than 0 then gos_http_write() should be issued as many times a necessary to write that specified amount of data.
Once all POST data is written, receive the request response using one the following:
Once the response is received use gos_http_read() to ready the response body.
Use gos_http_close() to close the HTTP stream.
This API provides similar functionality to the Command API function http_post .
- Note
- A complete example showing how to send data using an HTTP POST request with the Command API is available: Sending a POST Request
- Parameters
-
[in] context
gos_http_request_t Information about the HTTP POST request [out] handle_ptr
A handle for the request
- Returns
- The result of the POST request
◆ gos_http_read()
gos_result_t gos_http_read | ( | gos_handle_t |
handle,
|
void * |
data,
|
||
uint32_t |
max_size,
|
||
uint32_t * |
bytes_read_ptr
|
||
) |
Read HTTP GET/POST response stream.
The HTTP request stream should have been previously opened with one of the following:
The HTTP response should then have been previously received with one of the following:
This reads the HTTP response body into the given buffer.
See Gecko OS Command API documentation: stream_read .
- Note
- Stream handles start at 1, max handle value is GOS_MAX_STREAMS
- Parameters
-
[in] handle
Handle of opened HTTP request [out] data
Buffer to hold read data [in] max_size
Maximum amount of bytes to read (i.e. size of given buffer) [out] bytes_read_ptr
Pointer to hold number of bytes actually read, use NULL if not used
- Returns
- gos_result_t return of API call
◆ gos_http_read_status()
gos_result_t gos_http_read_status | ( | gos_handle_t |
handle,
|
uint32_t * |
status_ptr
|
||
) |
Complete HTTP request stream and return HTTP status code.
The completes a HTTP request and returns the HTTP response status code.
Use gos_http_read() to read the HTTP response body.
- Note
- The HTTP response headers are discarded with this API, use gos_http_receive_response() to receive the response headers.
See Gecko OS Command API documentation: http_read_status .
- Note
- Stream handles start at 1, max handle value is GOS_MAX_STREAMS
- Parameters
-
[in] handle
Handle of opened HTTP request [out] status_ptr
Pointer to hold HTTP status code
- Returns
- gos_result_t return of API call
◆ gos_http_read_with_buffer()
gos_result_t gos_http_read_with_buffer | ( | gos_handle_t |
handle,
|
gos_buffer_t * |
buffer
|
||
) |
Read HTTP stream data into buffer.
See gos_read_with_buffer() for more information.
- Note
- Stream handles start at 1, max handle value is GOS_MAX_STREAMS
- Parameters
-
handle
Stream handle buffer
Buffer to specify how much data to read, then return how much data was read with pointer to data
- Returns
- gos_result_t result of api call
- Examples:
- demo/secure_element/main.c , and utility/profiler/main.c .
◆ gos_http_receive_response()
gos_result_t gos_http_receive_response | ( | gos_handle_t |
handle,
|
gos_http_response_t * |
response
|
||
) |
Receive the HTTP response headers.
This completes the HTTP request and returns the HTTP response gos_http_response_t .
- Note
- Only gos_http_basic_header_t headers are returned, use gos_http_receive_response_with_config() to return other headers.
- After calling this API use gos_http_read() to receive the HTTP response body.
- Stream handles start at 1, max handle value is GOS_MAX_STREAMS
- Parameters
-
[in] handle
Handle of opened HTTP request [out] response
gos_http_response_t To hold HTTP response
- Returns
- gos_result_t return of API call
◆ gos_http_receive_response_with_config()
gos_result_t gos_http_receive_response_with_config | ( | gos_handle_t |
handle,
|
gos_http_response_t * |
response,
|
||
const gos_http_response_config_t * |
config
|
||
) |
Receive the HTTP response header with specified configuration.
This completes the HTTP request and returns the HTTP response gos_http_response_t . How the response is returned is specified by the supplied gos_http_response_config_t
- Note
- After calling this API use gos_http_read() to receive the HTTP response body.
- Use gos_http_response_cleanup() to cleanup the HTTP response.
- Stream handles start at 1, max handle value is GOS_MAX_STREAMS
- Parameters
-
[in] handle
Handle of opened HTTP request [out] response
gos_http_response_t To hold HTTP response [in] config
gos_http_response_config_t Specifying how to return the response
- Returns
- gos_result_t return of API call
- Examples:
- demo/secure_element/main.c .
◆ gos_http_response_cleanup()
void gos_http_response_cleanup | ( | gos_http_response_t * |
response
|
) |
Cleanup a HTTP response.
This cleans up the gos_http_response_t returned by:
- Parameters
-
[in] response
gos_http_response_t to cleanup
◆ gos_http_write()
gos_result_t gos_http_write | ( | gos_handle_t |
handle,
|
const void * |
data,
|
||
uint32_t |
size,
|
||
bool |
auto_flush
|
||
) |
Write data to a HTTP POST request stream.
The HTTP request stream should have been previously opened with one of the following:
See Gecko OS Command API documentation: stream_write .
- Parameters
-
[in] handle
Handle of opened HTTP POST request [in] data
Data to send to server [in] size
Size in bytes of data to send [in] auto_flush
true to only flush when internal buffer is full, false to send data immediately to server
- Returns
- gos_result_t return of API call
- Examples:
- network/http_methods/http_post.c , and network/http_methods/http_put.c .