Begin prototyping the HttpServer API

This commit is contained in:
Jordan Bancino 2022-08-26 11:07:54 -04:00
parent 2b72dd0dba
commit 275d06c127
3 changed files with 43 additions and 7 deletions

View file

@ -58,6 +58,18 @@ struct HttpServer
Array *threadPool;
};
struct HttpServerContext
{
HashMap *requestHeaders;
HttpRequestMethod requestMethod;
char *requestPath;
HashMap *responseHeaders;
HttpStatus responseStatus;
FILE *stream;
};
static int
QueueConnection(HttpServer * server, int fd)
{

View file

@ -99,13 +99,13 @@ typedef enum HttpStatus
HTTP_NETWORK_AUTH_REQUIRED = 511
} HttpStatus;
extern char *
HttpGetStatusString(const HttpStatus httpStatus);
extern const char *
HttpStatusToString(const HttpStatus);
extern HttpRequestMethod
HttpRequestMethodFromString(const char *requestMethod);
HttpRequestMethodFromString(const char *);
typedef struct HttpRequest HttpRequest;
typedef struct HttpResponse HttpResponse;
extern const char *
HttpRequestMethodToString(const HttpRequestMethod);
#endif

View file

@ -26,9 +26,9 @@
#include <Http.h>
typedef struct HttpServer HttpServer;
#include <HashMap.h>
typedef void (HttpHandler) (HttpRequest *, HttpResponse *, void *);
typedef struct HttpServer HttpServer;
extern HttpServer *
HttpServerCreate(unsigned short, unsigned int, unsigned int, HttpHandler *, void *);
@ -45,4 +45,28 @@ extern void
extern void
HttpServerStop(HttpServer *);
typedef struct HttpServerContext HttpServerContext;
typedef void (HttpHandler) (HttpServerContext *, void *);
extern HashMap *
HttpRequestHeaders(HttpServerContext *);
extern HttpRequestMethod
HttpRequestMethod(HttpServerContext *);
extern char *
HttpRequestPath(HttpServerContext *);
extern void
HttpResponseHeader(HttpServerContext *, const char *, const char *);
extern void
HttpResponseStatus(HttpServerContext *, HttpStatus);
extern FILE *
HttpStream(HttpServerContext *);
extern void
HttpSendHeaders(HttpServerContext *);
#endif