mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 18:25:10 +00:00
[ADD/WIP] Routerwerk!
This commit is contained in:
parent
25ed114d0f
commit
47c98cbbe3
8 changed files with 280 additions and 1 deletions
52
src/HttParsee.c
Normal file
52
src/HttParsee.c
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#include <Parsee.h>
|
||||
|
||||
#include <Cytoplasm/Memory.h>
|
||||
#include <Cytoplasm/Json.h>
|
||||
#include <Cytoplasm/Log.h>
|
||||
#include <Cytoplasm/Str.h>
|
||||
|
||||
#include <Routes.h>
|
||||
|
||||
void
|
||||
ParseeRequest(HttpServerContext *ctx, void *argp)
|
||||
{
|
||||
ParseeData *data = argp;
|
||||
char *path = HttpRequestPath(ctx);
|
||||
HashMap *response = NULL;
|
||||
Stream *stream = HttpServerStream(ctx);
|
||||
int encodedSize;
|
||||
char *encodedStr;
|
||||
ParseeHttpArg arg;
|
||||
|
||||
/* Basic headers */
|
||||
HttpResponseStatus(ctx, HTTP_OK);
|
||||
HttpResponseHeader(ctx, "Server", NAME "/v" VERSION);
|
||||
HttpResponseHeader(ctx, "Connection", "close");
|
||||
|
||||
arg.data = data;
|
||||
arg.ctx = ctx ;
|
||||
|
||||
arg.stream = stream;
|
||||
|
||||
if (!HttpRouterRoute(data->router, path, &arg, (void **) &response))
|
||||
{
|
||||
HttpResponseStatus(ctx, HTTP_NOT_FOUND);
|
||||
JsonFree(response);
|
||||
response = NULL;
|
||||
/* TODO: Set a thing */
|
||||
}
|
||||
|
||||
/* Whatever, we routed a thing. */
|
||||
if (response)
|
||||
{
|
||||
encodedSize = JsonEncode(response, NULL, JSON_DEFAULT);
|
||||
encodedStr = StrInt(encodedSize);
|
||||
HttpResponseHeader(ctx, "Content-Length", encodedStr);
|
||||
HttpResponseHeader(ctx, "Content-Type", "application/json");
|
||||
Free(encodedStr);
|
||||
|
||||
HttpSendHeaders(ctx);
|
||||
JsonEncode(response, stream, JSON_DEFAULT);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue