Send a canned HTTP response.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4678 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
2f7697b7ec
commit
067f546580
15
src/http.c
15
src/http.c
@ -76,6 +76,11 @@ bool _http_find_handler(tf_http_t* http, const char* path, tf_http_callback_t**
|
||||
return false;
|
||||
}
|
||||
|
||||
static void _http_on_write(uv_write_t* write, int status)
|
||||
{
|
||||
tf_free(write);
|
||||
}
|
||||
|
||||
void _http_on_read(uv_stream_t* stream, ssize_t read_size, const uv_buf_t* buffer)
|
||||
{
|
||||
tf_http_connection_t* connection = stream->data;
|
||||
@ -116,6 +121,16 @@ void _http_on_read(uv_stream_t* stream, ssize_t read_size, const uv_buf_t* buffe
|
||||
.user_data = connection->user_data,
|
||||
};
|
||||
connection->callback(&request);
|
||||
|
||||
const char* payload = "HTTP/1.0 200 OK\r\nContent-Length: 13\r\n\r\nHello, world!";
|
||||
uv_write_t* write = tf_malloc(sizeof(uv_write_t) + strlen(payload));
|
||||
*write = (uv_write_t) { 0 };
|
||||
memcpy(write + 1, payload, strlen(payload));
|
||||
int r = uv_write(write, stream, &(uv_buf_t) { .base = (char*)(write + 1), .len = strlen(payload) }, 1, _http_on_write);
|
||||
if (r)
|
||||
{
|
||||
tf_printf("uv_write: %s\n", uv_strerror(r));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user