mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 16:45:10 +00:00
[ADD/WIP] Add some HTTP request code
We can now *register* users!
This commit is contained in:
parent
47c98cbbe3
commit
0fa95c2d14
12 changed files with 320 additions and 11 deletions
|
|
@ -5,6 +5,7 @@
|
|||
#include <Cytoplasm/Log.h>
|
||||
#include <Cytoplasm/Str.h>
|
||||
|
||||
#include <Matrix.h>
|
||||
#include <Routes.h>
|
||||
|
||||
void
|
||||
|
|
@ -27,12 +28,19 @@ ParseeRequest(HttpServerContext *ctx, void *argp)
|
|||
arg.ctx = ctx ;
|
||||
|
||||
arg.stream = stream;
|
||||
|
||||
Log(LOG_NOTICE, "%s %s",
|
||||
HttpRequestMethodToString(HttpRequestMethodGet(ctx)),
|
||||
path
|
||||
);
|
||||
|
||||
if (!HttpRouterRoute(data->router, path, &arg, (void **) &response))
|
||||
{
|
||||
Log(LOG_NOTICE, "Couldn't route %s", path);
|
||||
HttpResponseStatus(ctx, HTTP_NOT_FOUND);
|
||||
JsonFree(response);
|
||||
response = NULL;
|
||||
|
||||
response = MatrixCreateError("M_NOT_FOUND", "Route not found.");
|
||||
/* TODO: Set a thing */
|
||||
}
|
||||
|
||||
|
|
@ -50,3 +58,43 @@ ParseeRequest(HttpServerContext *ctx, void *argp)
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
HttpClientContext *
|
||||
ParseeCreateRequest(ParseeConfig *conf, HttpRequestMethod meth, char *path)
|
||||
{
|
||||
HttpClientContext *ctx;
|
||||
if (!conf || !path)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ctx = HttpRequest(
|
||||
meth,
|
||||
HTTP_FLAG_TLS,
|
||||
conf->homeserver_port, conf->homeserver_host,
|
||||
path
|
||||
);
|
||||
|
||||
return ctx;
|
||||
}
|
||||
HttpStatus
|
||||
ParseeSetRequestJSON(HttpClientContext *ctx, HashMap *json)
|
||||
{
|
||||
Stream *stream;
|
||||
int size;
|
||||
char *sizestr;
|
||||
if (!ctx || !json)
|
||||
{
|
||||
return HTTP_STATUS_UNKNOWN;
|
||||
}
|
||||
|
||||
size = JsonEncode(json, NULL, JSON_DEFAULT);
|
||||
sizestr = StrInt(size);
|
||||
HttpRequestHeader(ctx, "Content-Length", sizestr);
|
||||
Free(sizestr);
|
||||
|
||||
stream = HttpClientStream(ctx);
|
||||
HttpRequestSendHeaders(ctx);
|
||||
JsonEncode(json, stream, JSON_DEFAULT);
|
||||
return HttpRequestSend(ctx);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue