11#include "asio.h"
22
3- /**
4- * Make a GET request, will pause current task, and
5- * continue other tasks until an response is received.
6- *
7- * @param path
8- * @param type defaults to `text/html; charset=utf-8`, if empty
9- * @param numof number of additional headers
10- *
11- * - `using:` header_types = `head_by, head_cookie, head_secure, head_conn, head_bearer, head_auth_basic`
12- *
13- * - `kv(header_types, "value")`
14- *
15- * - `or:` `kv_custom("key", "value")`
16- */
173string http_get (string path , string type , u32 numof , ...) {
184 uv_tls_t * this = (uv_tls_t * )coro_data ();
195 if (!is_type (this , (raii_type )ASIO_ASYNC_TLS ))
@@ -27,21 +13,6 @@ string http_get(string path, string type, u32 numof, ...) {
2713 return req ;
2814}
2915
30- /**
31- * Make a POST request, will pause current task, and
32- * continue other tasks until an response is received.
33- *
34- * @param path
35- * @param data
36- * @param type defaults to `text/html; charset=utf-8`, if empty
37- * @param numof number of additional headers
38- *
39- * - `using:` header_types = `head_by, head_cookie, head_secure, head_conn, head_bearer, head_auth_basic`
40- *
41- * - `kv(header_types, "value")`
42- *
43- * - `or:` `kv_custom("key", "value")`
44- */
4516string http_post (string path , string data , string type , u32 numof , ...) {
4617 uv_tls_t * this = (uv_tls_t * )coro_data ();
4718 if (!is_type (this , (raii_type )ASIO_ASYNC_TLS ))
@@ -55,21 +26,6 @@ string http_post(string path, string data, string type, u32 numof, ...) {
5526 return req ;
5627}
5728
58- /**
59- * Make a DELETE request, will pause current task, and
60- * continue other tasks until an response is received.
61- *
62- * @param path
63- * @param data
64- * @param type defaults to `text/html; charset=utf-8`, if empty
65- * @param numof number of additional headers
66- *
67- * - `using:` header_types = `head_by, head_cookie, head_secure, head_conn, head_bearer, head_auth_basic`
68- *
69- * - `kv(header_types, "value")`
70- *
71- * - `or:` `kv_custom("key", "value")`
72- */
7329string http_delete (string path , string data , u32 numof , ...) {
7430 uv_tls_t * this = (uv_tls_t * )coro_data ();
7531 if (!is_type (this , (raii_type )ASIO_ASYNC_TLS ))
@@ -83,20 +39,6 @@ string http_delete(string path, string data, u32 numof, ...) {
8339 return req ;
8440}
8541
86- /**
87- * Make a PATCH request, will pause current task, and
88- * continue other tasks until an response is received.
89- *
90- * @param path
91- * @param data
92- * @param numof number of additional headers
93- *
94- * - `using:` header_types = `head_by, head_cookie, head_secure, head_conn, head_bearer, head_auth_basic`
95- *
96- * - `kv(header_types, "value")`
97- *
98- * - `or:` `kv_custom("key", "value")`
99- */
10042string http_patch (string path , string data , u32 numof , ...) {
10143 uv_tls_t * this = (uv_tls_t * )coro_data ();
10244 if (!is_type (this , (raii_type )ASIO_ASYNC_TLS ))
@@ -110,20 +52,7 @@ string http_patch(string path, string data, u32 numof, ...) {
11052 return req ;
11153}
11254
113- /**
114- * Make a OPTIONS request, will pause current task, and
115- * continue other tasks until an response is received.
116- *
117- * @param path
118- * @param numof number of additional headers
119- *
120- * - `using:` header_types = `head_by, head_cookie, head_secure, head_conn, head_bearer, head_auth_basic`
121- *
122- * - `kv(header_types, "value")`
123- *
124- * - `or:` `kv_custom("key", "value")`
125- */
126- bool http_options (string path , u32 numof , ...) {
55+ string http_options (string path , u32 numof , ...) {
12756 uv_tls_t * this = (uv_tls_t * )coro_data ();
12857 if (!is_type (this , (raii_type )ASIO_ASYNC_TLS ))
12958 throw (logic_error );
@@ -133,22 +62,9 @@ bool http_options(string path, u32 numof, ...) {
13362 string req = http_request (this -> http , HTTP_OPTIONS , path , nullptr , nullptr , numof , headers );
13463 va_end (headers );
13564
136- return req != nullptr ;
65+ return req ;
13766}
13867
139- /**
140- * Make a HEAD request, will pause current task, and
141- * continue other tasks until an response is received.
142- *
143- * @param path
144- * @param numof number of additional headers
145- *
146- * - `using:` header_types = `head_by, head_cookie, head_secure, head_conn, head_bearer, head_auth_basic`
147- *
148- * - `kv(header_types, "value")`
149- *
150- * - `or:` `kv_custom("key", "value")`
151- */
15268string http_head (string path , u32 numof , ...) {
15369 uv_tls_t * this = (uv_tls_t * )coro_data ();
15470 if (!is_type (this , (raii_type )ASIO_ASYNC_TLS ))
@@ -162,11 +78,7 @@ string http_head(string path, u32 numof, ...) {
16278 return req ;
16379}
16480
165- /**
166- * Creates an `this` instance for `http_t`/`uv_tls_t`
167- * on current `coroutine` ~connected~ `stream`.
168- */
169- void http_this (uv_tls_t * socket ) {
81+ RAII_INLINE void http_this (uv_tls_t * socket ) {
17082 if (is_type (socket , (raii_type )ASIO_ASYNC_TLS ) && is_empty (coro_data ()))
17183 coro_data_set (coro_active (), (void_t )socket );
17284
0 commit comments