Added more information to dynamic pages

This commit is contained in:
Nate Choe
2022-02-14 12:14:55 -06:00
parent 6825f12163
commit 92a000f474
4 changed files with 23 additions and 2 deletions

View File

@@ -23,9 +23,26 @@ typedef struct {
} Field; } Field;
/*HTTP field*/ /*HTTP field*/
typedef enum {
GET,
POST,
PUT,
HEAD,
DELETE,
PATCH,
OPTIONS,
INVALID
/*
* Indicates an invalid type of request, if you see this then
* something's gone terribly wrong.
* */
} RequestType;
typedef struct { typedef struct {
long fieldCount; long fieldCount;
Field *fields; Field *fields;
char *path;
RequestType type;
} Request; } Request;
/*HTTP request, pretty self explanatory*/ /*HTTP request, pretty self explanatory*/

View File

@@ -5,9 +5,9 @@
#include <swebs/swebs.h> #include <swebs/swebs.h>
int getResponse(Request *request, Response *response) { int getResponse(Request *request, Response *response) {
char *str = "<h1>Hello world!</h1>"; char *str = request->path;
response->type = BUFFER; response->type = BUFFER;
response->response.buffer.data = malloc(30); response->response.buffer.data = malloc(100);
strcpy(response->response.buffer.data, str); strcpy(response->response.buffer.data, str);
response->response.buffer.len = strlen(str); response->response.buffer.len = strlen(str);
return 200; return 200;

View File

@@ -160,6 +160,8 @@ static int linkedResponse(Connection *conn,
request.fieldCount = conn->fieldCount; request.fieldCount = conn->fieldCount;
request.fields = conn->fields; request.fields = conn->fields;
request.path = conn->path;
request.type = conn->type;
code = getResponse(&request, &response); code = getResponse(&request, &response);

View File

@@ -49,6 +49,8 @@ typedef struct {
typedef struct { typedef struct {
long fieldCount; long fieldCount;
Field *fields; Field *fields;
char *path;
RequestType type;
} Request; } Request;
typedef enum { typedef enum {