Bunch of stuff
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
#ifndef HTTPCONTEXT_H
|
||||
#define HTTPCONTEXT_H
|
||||
|
||||
// a more Cish implementaion
|
||||
|
||||
#include <string_view>
|
||||
#include <functional>
|
||||
|
||||
// we depend on loop I guess
|
||||
// yes, the loop does not depend on us
|
||||
#include "Loop.h"
|
||||
|
||||
// we of course depend on our own data type
|
||||
#include "HttpContextData.h"
|
||||
|
||||
// we should opaqeuly depend on HttpResponse
|
||||
namespace uWS {
|
||||
template<bool>
|
||||
struct HttpResponse;
|
||||
}
|
||||
|
||||
// we parse everything only in the context?
|
||||
|
||||
// would it be okay to depend on the context?
|
||||
|
||||
// we depend on libusockets
|
||||
#include <libusockets.h>
|
||||
|
||||
template <bool SSL>
|
||||
struct HttpContext {
|
||||
|
||||
|
||||
private:
|
||||
HttpContext() = delete;
|
||||
|
||||
// helper to get the socket context
|
||||
us_socket_context *getSocketContext() {
|
||||
return (us_socket_context *) this;
|
||||
}
|
||||
|
||||
HttpContextData<SSL> *getSocketContextData() {
|
||||
return (HttpContextData<SSL> *) us_socket_context_ext(getSocketContext());
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
static HttpContext *create(us_loop *loop) {
|
||||
|
||||
// todo: inplace initialize the data struct!
|
||||
|
||||
return (HttpContext *) us_create_socket_context(loop, sizeof(HttpContextData<SSL>));
|
||||
}
|
||||
|
||||
void free() {
|
||||
us_socket_context_free((us_socket_context *) this);
|
||||
}
|
||||
|
||||
void onGet(std::string_view pattern, std::function<void(uWS::HttpResponse<SSL> *)> handler) {
|
||||
HttpContextData<SSL> *data = getSocketContextData();
|
||||
|
||||
// add things to the router
|
||||
|
||||
data->handler = handler;
|
||||
}
|
||||
|
||||
void listen() {
|
||||
// simulate routing and parsing a request
|
||||
|
||||
HttpContextData<SSL> *data = getSocketContextData();
|
||||
|
||||
// we need to pass an actual socket! not nullptr!
|
||||
|
||||
// simulare
|
||||
data->handler(nullptr);
|
||||
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // HTTPCONTEXT_H
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef HTTPCONTEXTDATA_H
|
||||
#define HTTPCONTEXTDATA_H
|
||||
|
||||
// this means we will depend on HttpRouter and HttpParser here!
|
||||
#include "../http/HttpParser.h"
|
||||
|
||||
#include "../http/HttpRouter.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace uWS {
|
||||
template<bool>
|
||||
struct HttpResponse;
|
||||
}
|
||||
|
||||
|
||||
template <bool SSL>
|
||||
struct HttpContextData {
|
||||
|
||||
private:
|
||||
|
||||
public:
|
||||
|
||||
struct HttpRouterUserData {
|
||||
|
||||
};
|
||||
|
||||
HttpRouter<HttpRouterUserData> httpRouter;
|
||||
|
||||
// placeholder handler for response
|
||||
std::function<void(uWS::HttpResponse<SSL> *)> handler;
|
||||
|
||||
};
|
||||
|
||||
#endif // HTTPCONTEXTDATA_H
|
||||
@@ -0,0 +1,38 @@
|
||||
#ifndef HTTPRESPONSE_H
|
||||
#define HTTPRESPONSE_H
|
||||
|
||||
#include "HttpResponseData.h"
|
||||
|
||||
// we will most probably depend on the LoopData to do corking and such
|
||||
|
||||
namespace uWS {
|
||||
|
||||
template <bool SSL>
|
||||
struct HttpResponse {
|
||||
private:
|
||||
|
||||
// helpers
|
||||
HttpResponseData<SSL> *getHttpResponseData() {
|
||||
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
void writeHeader() {
|
||||
|
||||
}
|
||||
|
||||
// this will probably not be this clean: it will most probably want to do some active pulling of data?
|
||||
void read(std::function<void(std::string_view)> handler) {
|
||||
HttpResponseData<SSL> *data = getHttpResponseData();
|
||||
|
||||
data->readHandler = handler;
|
||||
}
|
||||
|
||||
// read and write streams most definitely will be called by the context, thus the context absolutely depends on the httpresponse!
|
||||
// or, we both depend on each others data structures only?
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // HTTPRESPONSE_H
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef HTTPRESPONSEDATA_H
|
||||
#define HTTPRESPONSEDATA_H
|
||||
|
||||
// so what do we depend on?
|
||||
|
||||
#include <functional>
|
||||
|
||||
template <bool SSL>
|
||||
struct HttpResponseData {
|
||||
|
||||
std::function<void(std::string_view)> readHandler;
|
||||
|
||||
};
|
||||
|
||||
#endif // HTTPRESPONSEDATA_H
|
||||
Reference in New Issue
Block a user