Work on responses

master
Jonathan Hodgson 3 years ago
parent 8912994e1d
commit a3a48a841e
  1. 15
      src/response.c
  2. 2
      src/response.h
  3. 3
      tests/response.test.c

@ -36,3 +36,18 @@ void responseSetBody(Response *rsp, char *string, bool updateContentLength){
contentLengthHeader->value = strdup(value); 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;
}

@ -27,7 +27,7 @@ typedef struct {
Response* newResponse(); Response* newResponse();
char *responseToString(Response *rsp); char *responseToString(Response *rsp);
void responseSetBody(Response *rsp, char *string, bool updateContentLength); void responseSetBody(Response *rsp, char *string, bool updateContentLength);
//void* responseAddHeader(Response *req, char line[]); void responseAddHeader(Response *rsp, char header[]);

@ -4,7 +4,7 @@
#include "munit/munit.h" #include "munit/munit.h"
#ifndef REQUESTRESPONSE_C #ifndef REQUESTRESPONSE_C
#define REQUESTRESPONSE_C value #define REQUESTRESPONSE_C value
#include "requestresponse.test.c" #include "../src/requestresponse.c"
#endif /* ifndef REQUESTRESPONSE_C */ #endif /* ifndef REQUESTRESPONSE_C */
#include "../src/response.c" #include "../src/response.c"
@ -47,6 +47,7 @@ MunitResult testResponseToString(const MunitParameter params[],
return MUNIT_OK; return MUNIT_OK;
} }
static MunitTest response_tests[] = { static MunitTest response_tests[] = {
{ {
"/new/status", /* name */ "/new/status", /* name */

Loading…
Cancel
Save