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; Array *threadPool;
}; };
struct HttpServerContext
{
HashMap *requestHeaders;
HttpRequestMethod requestMethod;
char *requestPath;
HashMap *responseHeaders;
HttpStatus responseStatus;
FILE *stream;
};
static int static int
QueueConnection(HttpServer * server, int fd) QueueConnection(HttpServer * server, int fd)
{ {

View file

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

View file

@ -26,9 +26,9 @@
#include <Http.h> #include <Http.h>
typedef struct HttpServer HttpServer; #include <HashMap.h>
typedef void (HttpHandler) (HttpRequest *, HttpResponse *, void *); typedef struct HttpServer HttpServer;
extern HttpServer * extern HttpServer *
HttpServerCreate(unsigned short, unsigned int, unsigned int, HttpHandler *, void *); HttpServerCreate(unsigned short, unsigned int, unsigned int, HttpHandler *, void *);
@ -45,4 +45,28 @@ extern void
extern void extern void
HttpServerStop(HttpServer *); 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 #endif