From a3a48a841e1aa3331d9d35cc7570383ab92ed993 Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Mon, 17 Jan 2022 14:04:30 +0000 Subject: [PATCH] Work on responses --- src/response.c | 15 +++++++++++++++ src/response.h | 2 +- tests/response.test.c | 3 ++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/response.c b/src/response.c index bacdf7a..7c23461 100644 --- a/src/response.c +++ b/src/response.c @@ -36,3 +36,18 @@ void responseSetBody(Response *rsp, char *string, bool updateContentLength){ contentLengthHeader->value = strdup(value); } } + +void responseAddHeader(Response *rsp, char header[]){ + if ( rsp->headers == NULL ){ + rsp->headers = malloc(sizeof( HeaderList )); + rsp->headers->header = newHeader( header ); + rsp->headers->next = NULL; + } else + addHeader( rsp->headers, header ); + +} + +Response* newResponseFromSocket(int socket){ + Response *rsp = newResponse(); + return rsp; +} diff --git a/src/response.h b/src/response.h index a18a667..a253961 100644 --- a/src/response.h +++ b/src/response.h @@ -27,7 +27,7 @@ typedef struct { Response* newResponse(); char *responseToString(Response *rsp); void responseSetBody(Response *rsp, char *string, bool updateContentLength); -//void* responseAddHeader(Response *req, char line[]); +void responseAddHeader(Response *rsp, char header[]); diff --git a/tests/response.test.c b/tests/response.test.c index ed0dc72..3b49831 100644 --- a/tests/response.test.c +++ b/tests/response.test.c @@ -4,7 +4,7 @@ #include "munit/munit.h" #ifndef REQUESTRESPONSE_C #define REQUESTRESPONSE_C value -#include "requestresponse.test.c" +#include "../src/requestresponse.c" #endif /* ifndef REQUESTRESPONSE_C */ #include "../src/response.c" @@ -47,6 +47,7 @@ MunitResult testResponseToString(const MunitParameter params[], return MUNIT_OK; } + static MunitTest response_tests[] = { { "/new/status", /* name */