|
|
|
@ -16,6 +16,8 @@
|
|
|
|
|
|
|
|
|
|
#include "worker_pool.h"
|
|
|
|
|
|
|
|
|
|
#include "collections/list.h"
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
recv_buffer_size = 512,
|
|
|
|
|
};
|
|
|
|
@ -75,8 +77,7 @@ struct http_request
|
|
|
|
|
struct header
|
|
|
|
|
{
|
|
|
|
|
struct header* next;
|
|
|
|
|
char* key;
|
|
|
|
|
char* value;
|
|
|
|
|
struct http_header data;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ssize_t getline_stripped( char** restrict lineptr, size_t* restrict n, FILE* restrict stream)
|
|
|
|
@ -132,13 +133,12 @@ static void request_fiber_entry()
|
|
|
|
|
while( *value == ' ' ) { ++value; }
|
|
|
|
|
|
|
|
|
|
struct header* h = (struct header*)malloc(sizeof(struct header));
|
|
|
|
|
h->next = req->request_headers;
|
|
|
|
|
h->key = key;
|
|
|
|
|
h->value = value;
|
|
|
|
|
h->data.key = key;
|
|
|
|
|
h->data.value = strdup(value);
|
|
|
|
|
if( req->debug ) {
|
|
|
|
|
printf( "Header: %s: %s\n", h->key, h->value );
|
|
|
|
|
printf( "Header: %s: %s\n", h->data.key, h->data.value );
|
|
|
|
|
}
|
|
|
|
|
req->request_headers = h;
|
|
|
|
|
list_add_front( &req->request_headers, h );
|
|
|
|
|
|
|
|
|
|
if( 0 == strcmp("Content-Length", key ) ) {
|
|
|
|
|
sscanf( value, "%u", &content_length );
|
|
|
|
@ -412,7 +412,8 @@ void http_request_release( struct http_request* req )
|
|
|
|
|
|
|
|
|
|
for( struct header* iter = req->request_headers; iter; ) {
|
|
|
|
|
struct header* next = iter->next;
|
|
|
|
|
free(iter->key);
|
|
|
|
|
free(iter->data.key);
|
|
|
|
|
free(iter->data.value);
|
|
|
|
|
free(iter);
|
|
|
|
|
iter = next;
|
|
|
|
|
}
|
|
|
|
@ -457,13 +458,22 @@ const char* http_request_get_remote_host_address( struct http_request* req )
|
|
|
|
|
const char* http_request_get_header( struct http_request* req, const char* header )
|
|
|
|
|
{
|
|
|
|
|
for( struct header* iter = req->request_headers; iter; iter = iter->next ) {
|
|
|
|
|
if( 0 == strcasecmp( header, iter->key ) ) {
|
|
|
|
|
return iter->value;
|
|
|
|
|
if( 0 == strcasecmp( header, iter->data.key ) ) {
|
|
|
|
|
return iter->data.value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
void http_request_copy_headers( struct http_request* req, struct collection dst )
|
|
|
|
|
{
|
|
|
|
|
struct collection src = {
|
|
|
|
|
.ptr = &req->request_headers,
|
|
|
|
|
.vtable = &list_vtable,
|
|
|
|
|
.itable = &http_header_itable,
|
|
|
|
|
};
|
|
|
|
|
list_copy_cc( src, dst );
|
|
|
|
|
}
|
|
|
|
|
const char* string_for_status( int status_code )
|
|
|
|
|
{
|
|
|
|
|
switch( status_code ) {
|
|
|
|
|