This commit is contained in:
NADAL Jean-Baptiste
2019-12-23 18:27:18 +01:00
parent 14d3faae8d
commit 798bea32ab
9 changed files with 206 additions and 37 deletions

View File

@@ -29,18 +29,13 @@
/*------------------------------- INCLUDES ----------------------------------*/
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <limits.h>
#include <assert.h>
#include <errno.h>
#include <event2/buffer.h>
#include <qlibc/qlibc.h>
#include "restd_server.h"
#include "restd_http_handler.h"
#include "macro.h"
@@ -100,6 +95,11 @@ int restd_http_handler(short event, restd_conn_t *conn, void *userdata)
{
restd_conn_set_method(conn, http->request.method);
}
DEBUG("==> HTTP PATH: %s METHOD: %s", http->request.path, http->request.method);
if (conn->server->request_handler != NULL)
{
status = conn->server->request_handler(event, conn, NULL);
}
return status;
}
else if (event & RESTD_EVENT_WRITE)
@@ -251,7 +251,7 @@ int restd_http_is_keepalive_request(restd_conn_t *conn)
* @return 0 on success, -1 if we already sent it out.
*/
int restd_http_set_response_header(restd_conn_t *conn, const char *name,
const char *value)
const char *value)
{
restd_http_t *http = (restd_http_t *)restd_conn_get_extra(conn);
if (http->response.frozen_header)
@@ -309,7 +309,7 @@ int restd_http_set_response_code(restd_conn_t *conn, int code, const char *reaso
* @return 0 on success, -1 if we already sent it out.
*/
int restd_http_set_response_content(restd_conn_t *conn, const char *contenttype,
off_t size)
off_t size)
{
restd_http_t *http = (restd_http_t *)restd_conn_get_extra(conn);
if (http->response.frozen_header)
@@ -341,7 +341,7 @@ int restd_http_set_response_content(restd_conn_t *conn, const char *contenttype,
* @return total bytes sent, 0 on error.
*/
size_t restd_http_response(restd_conn_t *conn, int code, const char *contenttype,
const void *data, off_t size)
const void *data, off_t size)
{
restd_http_t *http = (restd_http_t *)restd_conn_get_extra(conn);
if (http->response.frozen_header)
@@ -544,10 +544,9 @@ static restd_http_t *http_new(struct evbuffer *out)
// Allocate additional resources.
http->request.inbuf = evbuffer_new();
http->request.headers = qlisttbl(
QLISTTBL_UNIQUE | QLISTTBL_CASEINSENSITIVE);
http->response.headers = qlisttbl(
QLISTTBL_UNIQUE | QLISTTBL_CASEINSENSITIVE);
http->request.headers = qlisttbl(QLISTTBL_UNIQUE | QLISTTBL_CASEINSENSITIVE);
http->response.headers = qlisttbl(QLISTTBL_UNIQUE | QLISTTBL_CASEINSENSITIVE);
if (http->request.inbuf == NULL || http->request.headers == NULL || http->response.headers == NULL)
{
http_free(http);