forked from cory/tildefriends
Reimplement http -> https redirects. Remove request phases. With just a little extra storage, it wasn't needed.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4723 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
27
src/http.c
27
src/http.c
@ -89,6 +89,9 @@ typedef struct _tf_http_t
|
||||
|
||||
int pending_closes;
|
||||
uv_loop_t* loop;
|
||||
|
||||
void* user_data;
|
||||
tf_http_cleanup_t* user_data_cleanup;
|
||||
} tf_http_t;
|
||||
|
||||
static const char* _http_connection_get_header(const tf_http_connection_t* connection, const char* name);
|
||||
@ -337,8 +340,9 @@ static void _http_add_body_bytes(tf_http_connection_t* connection, const void* d
|
||||
tf_http_request_t* request = tf_malloc(sizeof(tf_http_request_t));
|
||||
*request = (tf_http_request_t)
|
||||
{
|
||||
.http = connection->http,
|
||||
.connection = connection,
|
||||
.phase = k_http_callback_phase_headers_received,
|
||||
.is_tls = connection->tls != NULL,
|
||||
.method = connection->method,
|
||||
.path = connection->path,
|
||||
.query = connection->query,
|
||||
@ -671,6 +675,12 @@ void tf_http_destroy(tf_http_t* http)
|
||||
tf_free(http->connections);
|
||||
http->connections_count = 0;
|
||||
|
||||
if (http->user_data_cleanup)
|
||||
{
|
||||
http->user_data_cleanup(http->user_data);
|
||||
http->user_data = NULL;
|
||||
}
|
||||
|
||||
tf_free(http);
|
||||
}
|
||||
|
||||
@ -897,3 +907,18 @@ void tf_http_request_websocket_upgrade(tf_http_request_t* request)
|
||||
{
|
||||
request->connection->is_websocket = true;
|
||||
}
|
||||
|
||||
void tf_http_set_user_data(tf_http_t* http, void* user_data, tf_http_cleanup_t* cleanup)
|
||||
{
|
||||
if (http->user_data && http->user_data_cleanup)
|
||||
{
|
||||
http->user_data_cleanup(http->user_data);
|
||||
}
|
||||
http->user_data = user_data;
|
||||
http->user_data_cleanup = cleanup;
|
||||
}
|
||||
|
||||
void* tf_http_get_user_data(tf_http_t* http)
|
||||
{
|
||||
return http->user_data;
|
||||
}
|
||||
|
Reference in New Issue
Block a user