diff --git a/documentation/dynamicpages.md b/documentation/dynamicpages.md index 6403106..4f7dbab 100644 --- a/documentation/dynamicpages.md +++ b/documentation/dynamicpages.md @@ -23,9 +23,26 @@ typedef struct { } 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 { long fieldCount; Field *fields; + char *path; + RequestType type; } Request; /*HTTP request, pretty self explanatory*/ diff --git a/example/library.c b/example/library.c index 050da51..f4e697a 100644 --- a/example/library.c +++ b/example/library.c @@ -5,9 +5,9 @@ #include int getResponse(Request *request, Response *response) { - char *str = "

Hello world!

"; + char *str = request->path; response->type = BUFFER; - response->response.buffer.data = malloc(30); + response->response.buffer.data = malloc(100); strcpy(response->response.buffer.data, str); response->response.buffer.len = strlen(str); return 200; diff --git a/src/responses.c b/src/responses.c index 5951f7e..a266b8d 100644 --- a/src/responses.c +++ b/src/responses.c @@ -160,6 +160,8 @@ static int linkedResponse(Connection *conn, request.fieldCount = conn->fieldCount; request.fields = conn->fields; + request.path = conn->path; + request.type = conn->type; code = getResponse(&request, &response); diff --git a/src/swebs/types.h b/src/swebs/types.h index c090a6c..124b771 100644 --- a/src/swebs/types.h +++ b/src/swebs/types.h @@ -49,6 +49,8 @@ typedef struct { typedef struct { long fieldCount; Field *fields; + char *path; + RequestType type; } Request; typedef enum {