1 | // Copyright (c) Microsoft. All rights reserved.
|
---|
2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
---|
3 |
|
---|
4 | /** @file httpapiex.h
|
---|
5 | * @brief This is a utility module that provides HTTP requests with
|
---|
6 | * build-in retry capabilities.
|
---|
7 | *
|
---|
8 | * @details HTTAPIEX is a utility module that provides HTTP requests with build-in
|
---|
9 | * retry capability to an HTTP server. Features over "regular" HTTPAPI include:
|
---|
10 | * - Optional parameters
|
---|
11 | * - Implementation independent
|
---|
12 | * - Retry mechanism
|
---|
13 | * - Persistent options
|
---|
14 | */
|
---|
15 |
|
---|
16 | #ifndef HTTPAPIEX_H
|
---|
17 | #define HTTPAPIEX_H
|
---|
18 |
|
---|
19 | #include "azure_c_shared_utility/macro_utils.h"
|
---|
20 | #include "azure_c_shared_utility/httpapi.h"
|
---|
21 | #include "azure_c_shared_utility/umock_c_prod.h"
|
---|
22 |
|
---|
23 | #ifdef __cplusplus
|
---|
24 | #include <cstddef>
|
---|
25 | extern "C" {
|
---|
26 | #else
|
---|
27 | #include <stddef.h>
|
---|
28 | #endif
|
---|
29 |
|
---|
30 | typedef struct HTTPAPIEX_HANDLE_DATA_TAG* HTTPAPIEX_HANDLE;
|
---|
31 |
|
---|
32 | #define HTTPAPIEX_RESULT_VALUES \
|
---|
33 | HTTPAPIEX_OK, \
|
---|
34 | HTTPAPIEX_ERROR, \
|
---|
35 | HTTPAPIEX_INVALID_ARG, \
|
---|
36 | HTTPAPIEX_RECOVERYFAILED
|
---|
37 | /*to be continued*/
|
---|
38 |
|
---|
39 | /** @brief Enumeration specifying the status of calls to various APIs in this module.
|
---|
40 | */
|
---|
41 | MU_DEFINE_ENUM(HTTPAPIEX_RESULT, HTTPAPIEX_RESULT_VALUES);
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * @brief Creates an @c HTTPAPIEX_HANDLE that can be used in further calls.
|
---|
45 | *
|
---|
46 | * @param hostName Pointer to a null-terminated string that contains the host name
|
---|
47 | * of an HTTP server.
|
---|
48 | *
|
---|
49 | * If @p hostName is @c NULL then @c HTTPAPIEX_Create returns @c NULL. The @p
|
---|
50 | * hostName value is saved and associated with the returned handle. If creating
|
---|
51 | * the handle fails for any reason, then @c HTTAPIEX_Create returns @c NULL.
|
---|
52 | * Otherwise, @c HTTPAPIEX_Create returns an @c HTTAPIEX_HANDLE suitable for
|
---|
53 | * further calls to the module.
|
---|
54 | *
|
---|
55 | * @return An @c HTTAPIEX_HANDLE suitable for further calls to the module.
|
---|
56 | */
|
---|
57 | MOCKABLE_FUNCTION(, HTTPAPIEX_HANDLE, HTTPAPIEX_Create, const char*, hostName);
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * @brief Tries to execute an HTTP request.
|
---|
61 | *
|
---|
62 | * @param handle A valid @c HTTPAPIEX_HANDLE value.
|
---|
63 | * @param requestType A value from the ::HTTPAPI_REQUEST_TYPE enum.
|
---|
64 | * @param relativePath Relative path to send the request to on the server.
|
---|
65 | * @param requestHttpHeadersHandle Handle to the request HTTP headers.
|
---|
66 | * @param requestContent The request content.
|
---|
67 | * @param statusCode If non-null, the HTTP status code is written to this
|
---|
68 | * pointer.
|
---|
69 | * @param responseHttpHeadersHandle Handle to the response HTTP headers.
|
---|
70 | * @param responseContent The response content.
|
---|
71 | *
|
---|
72 | * @c HTTPAPIEX_ExecuteRequest tries to execute an HTTP request of type @p
|
---|
73 | * requestType, on the server's @p relativePath, pushing the request HTTP
|
---|
74 | * headers @p requestHttpHeadersHandle, having the content of the request
|
---|
75 | * as pointed to by @p requestContent. If successful, @c HTTAPIEX_ExecuteRequest
|
---|
76 | * writes in the out @p parameter statusCode the HTTP status, populates the @p
|
---|
77 | * responseHeadersHandle with the response headers and copies the response body
|
---|
78 | * to @p responseContent.
|
---|
79 | *
|
---|
80 | * @return An @c HTTAPIEX_HANDLE suitable for further calls to the module.
|
---|
81 | */
|
---|
82 | MOCKABLE_FUNCTION(, HTTPAPIEX_RESULT, HTTPAPIEX_ExecuteRequest, HTTPAPIEX_HANDLE, handle, HTTPAPI_REQUEST_TYPE, requestType, const char*, relativePath, HTTP_HEADERS_HANDLE, requestHttpHeadersHandle, BUFFER_HANDLE, requestContent, unsigned int*, statusCode, HTTP_HEADERS_HANDLE, responseHttpHeadersHandle, BUFFER_HANDLE, responseContent);
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * @brief Frees all resources used by the @c HTTPAPIEX_HANDLE object.
|
---|
86 | *
|
---|
87 | * @param handle The @c HTTPAPIEX_HANDLE object to be freed.
|
---|
88 | */
|
---|
89 | MOCKABLE_FUNCTION(, void, HTTPAPIEX_Destroy, HTTPAPIEX_HANDLE, handle);
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * @brief Sets the option @p optionName to the value pointed to by @p value.
|
---|
93 | *
|
---|
94 | * @param handle The @c HTTPAPIEX_HANDLE representing this session.
|
---|
95 | * @param optionName Name of the option.
|
---|
96 | * @param value The value to be set for the option.
|
---|
97 | *
|
---|
98 | * @return An @c HTTPAPIEX_RESULT indicating the status of the call.
|
---|
99 | */
|
---|
100 | MOCKABLE_FUNCTION(, HTTPAPIEX_RESULT, HTTPAPIEX_SetOption, HTTPAPIEX_HANDLE, handle, const char*, optionName, const void*, value);
|
---|
101 |
|
---|
102 | #ifdef __cplusplus
|
---|
103 | }
|
---|
104 | #endif
|
---|
105 |
|
---|
106 | #endif /* HTTPAPIEX_H */
|
---|