Skip to content

Commit abb276b

Browse files
committed
update/stage direct http handling
1 parent e99d00e commit abb276b

5 files changed

Lines changed: 122 additions & 94 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ if(NOT opentls_FOUND)
6060
endif()
6161

6262
set(lib_files
63-
${CMAKE_CURRENT_SOURCE_DIR}/src/uv_tls.c
6463
${CMAKE_CURRENT_SOURCE_DIR}/src/asio.c
6564
${CMAKE_CURRENT_SOURCE_DIR}/src/ssl.c
65+
${CMAKE_CURRENT_SOURCE_DIR}/src/uv_http.c
66+
${CMAKE_CURRENT_SOURCE_DIR}/src/uv_tls.c
6667
)
6768

6869
add_library(${PROJECT_NAME} STATIC ${lib_files})

include/asio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#define INTERRUPT_MODE UV_RUN_NOWAIT
99

10-
#include "uv_tls.h"
10+
#include "uv_http.h"
1111
#include <reflection.h>
1212

1313
#ifdef _WIN32

include/uv_http.h

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#ifndef _UV_HTTP_H
2+
#define _UV_HTTP_H
3+
4+
#include "uv_tls.h"
5+
6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif
9+
10+
/**
11+
* Make a GET request, will pause current task, and
12+
* continue other tasks until an response is received.
13+
*
14+
* @param path
15+
* @param type defaults to `text/html; charset=utf-8`, if empty
16+
* @param numof number of additional headers
17+
*
18+
* - `using:` header_types = `head_by, head_cookie, head_secure, head_conn, head_bearer, head_auth_basic`
19+
*
20+
* - `kv(header_types, "value")`
21+
*
22+
* - `or:` `kv_custom("key", "value")`
23+
*/
24+
C_API string http_get(string path, string type, u32 numof, ...);
25+
26+
/**
27+
* Make a POST request, will pause current task, and
28+
* continue other tasks until an response is received.
29+
*
30+
* @param path
31+
* @param data
32+
* @param type defaults to `text/html; charset=utf-8`, if empty
33+
* @param numof number of additional headers
34+
*
35+
* - `using:` header_types = `head_by, head_cookie, head_secure, head_conn, head_bearer, head_auth_basic`
36+
*
37+
* - `kv(header_types, "value")`
38+
*
39+
* - `or:` `kv_custom("key", "value")`
40+
*/
41+
C_API string http_post(string path, string data, string type, u32 numof, ...);
42+
43+
/**
44+
* Make a DELETE request, will pause current task, and
45+
* continue other tasks until an response is received.
46+
*
47+
* @param path
48+
* @param data
49+
* @param type defaults to `text/html; charset=utf-8`, if empty
50+
* @param numof number of additional headers
51+
*
52+
* - `using:` header_types = `head_by, head_cookie, head_secure, head_conn, head_bearer, head_auth_basic`
53+
*
54+
* - `kv(header_types, "value")`
55+
*
56+
* - `or:` `kv_custom("key", "value")`
57+
*/
58+
C_API string http_delete(string path, string data, u32 numof, ...);
59+
60+
/**
61+
* Make a PATCH request, will pause current task, and
62+
* continue other tasks until an response is received.
63+
*
64+
* @param path
65+
* @param data
66+
* @param numof number of additional headers
67+
*
68+
* - `using:` header_types = `head_by, head_cookie, head_secure, head_conn, head_bearer, head_auth_basic`
69+
*
70+
* - `kv(header_types, "value")`
71+
*
72+
* - `or:` `kv_custom("key", "value")`
73+
*/
74+
C_API string http_patch(string path, string data, u32 numof, ...);
75+
76+
/**
77+
* Make a OPTIONS request, will pause current task, and
78+
* continue other tasks until an response is received.
79+
*
80+
* @param path
81+
* @param numof number of additional headers
82+
*
83+
* - `using:` header_types = `head_by, head_cookie, head_secure, head_conn, head_bearer, head_auth_basic`
84+
*
85+
* - `kv(header_types, "value")`
86+
*
87+
* - `or:` `kv_custom("key", "value")`
88+
*/
89+
C_API string http_options(string path, u32 numof, ...);
90+
91+
/**
92+
* Make a HEAD request, will pause current task, and
93+
* continue other tasks until an response is received.
94+
*
95+
* @param path
96+
* @param numof number of additional headers
97+
*
98+
* - `using:` header_types = `head_by, head_cookie, head_secure, head_conn, head_bearer, head_auth_basic`
99+
*
100+
* - `kv(header_types, "value")`
101+
*
102+
* - `or:` `kv_custom("key", "value")`
103+
*/
104+
C_API string http_head(string path, u32 numof, ...);
105+
106+
/**
107+
* Creates an `this` instance for `http_t`/`uv_tls_t`
108+
* on current `coroutine` ~connected~ `stream`.
109+
*/
110+
C_API void http_this(uv_tls_t *socket);
111+
112+
#ifdef __cplusplus
113+
}
114+
#endif
115+
116+
#endif /* _UV_HTTP_H */

include/uv_tls.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ extern "C" {
1717

1818
typedef struct tls_config tls_config_t;
1919
typedef struct tls tls_s;
20-
typedef struct uv_tls_s uv_tls_t;
2120
typedef struct uv_tls_s {
2221
raii_type type;
2322
int err;

src/uv_http.c

Lines changed: 3 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
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-
*/
173
string 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-
*/
4516
string 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-
*/
7329
string 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-
*/
10042
string 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-
*/
15268
string 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

Comments
 (0)