2023-12-13 18:59:11 -05:00
|
|
|
#pragma once
|
|
|
|
|
2024-01-02 10:02:47 -05:00
|
|
|
#include <stdbool.h>
|
2023-12-17 12:44:54 -05:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2023-12-13 18:59:11 -05:00
|
|
|
typedef struct _tf_http_connection_t tf_http_connection_t;
|
2023-12-25 18:39:16 -05:00
|
|
|
typedef struct _tf_http_request_t tf_http_request_t;
|
2023-12-30 13:59:02 -05:00
|
|
|
typedef struct _tf_http_t tf_http_t;
|
|
|
|
typedef struct _tf_tls_context_t tf_tls_context_t;
|
2024-01-02 21:14:17 -05:00
|
|
|
typedef struct _tf_trace_t tf_trace_t;
|
2023-12-30 13:59:02 -05:00
|
|
|
typedef struct uv_loop_s uv_loop_t;
|
2023-12-13 18:59:11 -05:00
|
|
|
|
2023-12-29 12:45:07 -05:00
|
|
|
typedef void (tf_http_message_callback)(tf_http_request_t* request, int op_code, const void* data, size_t size);
|
2024-01-26 21:36:08 -05:00
|
|
|
typedef void (tf_http_close_callback)(tf_http_request_t* request);
|
2023-12-25 18:39:16 -05:00
|
|
|
|
2023-12-13 18:59:11 -05:00
|
|
|
typedef struct _tf_http_request_t
|
|
|
|
{
|
2024-01-02 10:02:47 -05:00
|
|
|
tf_http_t* http;
|
2023-12-13 18:59:11 -05:00
|
|
|
tf_http_connection_t* connection;
|
2024-01-02 10:02:47 -05:00
|
|
|
bool is_tls;
|
2023-12-13 18:59:11 -05:00
|
|
|
const char* method;
|
|
|
|
const char* path;
|
2023-12-23 14:52:59 -05:00
|
|
|
const char* query;
|
|
|
|
void* body;
|
|
|
|
size_t content_length;
|
2023-12-13 18:59:11 -05:00
|
|
|
struct phr_header* headers;
|
|
|
|
int headers_count;
|
2023-12-25 18:39:16 -05:00
|
|
|
tf_http_message_callback* on_message;
|
2024-01-26 21:36:08 -05:00
|
|
|
tf_http_close_callback* on_close;
|
2023-12-25 18:39:16 -05:00
|
|
|
void* context;
|
2023-12-13 18:59:11 -05:00
|
|
|
void* user_data;
|
2023-12-21 12:45:06 -05:00
|
|
|
int ref_count;
|
2023-12-13 18:59:11 -05:00
|
|
|
} tf_http_request_t;
|
|
|
|
|
|
|
|
typedef void (tf_http_callback_t)(tf_http_request_t* request);
|
2024-01-02 10:02:47 -05:00
|
|
|
typedef void (tf_http_cleanup_t)(void* user_data);
|
2023-12-13 18:59:11 -05:00
|
|
|
|
|
|
|
tf_http_t* tf_http_create(uv_loop_t* loop);
|
2024-01-02 21:14:17 -05:00
|
|
|
void tf_http_set_trace(tf_http_t* http, tf_trace_t* trace);
|
2023-12-30 14:47:36 -05:00
|
|
|
int tf_http_listen(tf_http_t* http, int port, tf_tls_context_t* tls);
|
2024-01-27 12:11:24 -05:00
|
|
|
void tf_http_add_handler(tf_http_t* http, const char* pattern, tf_http_callback_t* callback, tf_http_cleanup_t* cleanup, void* user_data);
|
2023-12-18 12:51:15 -05:00
|
|
|
void tf_http_respond(tf_http_request_t* request, int status, const char** headers, int headers_count, const void* body, size_t content_length);
|
2023-12-20 18:58:28 -05:00
|
|
|
size_t tf_http_get_body(const tf_http_request_t* request, const void** out_data);
|
2023-12-13 18:59:11 -05:00
|
|
|
void tf_http_destroy(tf_http_t* http);
|
2023-12-21 12:45:06 -05:00
|
|
|
|
2024-01-02 10:02:47 -05:00
|
|
|
void tf_http_set_user_data(tf_http_t* http, void* user_data, tf_http_cleanup_t* cleanup);
|
|
|
|
void* tf_http_get_user_data(tf_http_t* http);
|
|
|
|
|
2023-12-21 12:45:06 -05:00
|
|
|
void tf_http_request_ref(tf_http_request_t* request);
|
2024-01-27 10:45:51 -05:00
|
|
|
void tf_http_request_unref(tf_http_request_t* request);
|
2023-12-24 12:43:33 -05:00
|
|
|
const char* tf_http_request_get_header(tf_http_request_t* request, const char* name);
|
2023-12-25 17:53:05 -05:00
|
|
|
void tf_http_request_send(tf_http_request_t* request, const void* data, size_t size);
|
2023-12-30 11:29:16 -05:00
|
|
|
void tf_http_request_websocket_upgrade(tf_http_request_t* request);
|