From b46a4563931d660b1c3b3cf39f81cf5b24c462ce Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Mon, 2 May 2022 23:32:55 +0200 Subject: [PATCH] Add some Http3 skeleton --- Makefile | 2 +- examples/Http3Server.cpp | 20 ++++++++++++++++++++ src/Http3App.h | 33 +++++++++++++++++++++++++++++++++ src/Http3Context.h | 17 +++++++++++++++++ src/Http3ContextData.h | 0 src/Http3Request.h | 6 ++++++ src/Http3Response.h | 11 +++++++++++ 7 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 examples/Http3Server.cpp create mode 100644 src/Http3App.h create mode 100644 src/Http3Context.h create mode 100644 src/Http3ContextData.h create mode 100644 src/Http3Request.h create mode 100644 src/Http3Response.h diff --git a/Makefile b/Makefile index c0a2a46..c8e6233 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -EXAMPLE_FILES := Broadcast HelloWorld ServerName EchoServer BroadcastingEchoServer UpgradeSync UpgradeAsync +EXAMPLE_FILES := Http3Server Broadcast HelloWorld ServerName EchoServer BroadcastingEchoServer UpgradeSync UpgradeAsync THREADED_EXAMPLE_FILES := HelloWorldThreaded EchoServerThreaded override CXXFLAGS += -lpthread -Wpedantic -Wall -Wextra -Wsign-conversion -Wconversion -std=c++2a -Isrc -IuSockets/src override LDFLAGS += uSockets/*.o -lz diff --git a/examples/Http3Server.cpp b/examples/Http3Server.cpp new file mode 100644 index 0000000..540cfd5 --- /dev/null +++ b/examples/Http3Server.cpp @@ -0,0 +1,20 @@ +/* Do not rely on this API, it will change */ +#include "Http3App.h" +#include + +/* Tentative example of simple Http3 server */ +int main() { + uWS::QuicApp({ + .key_file_name = "../misc/key.pem", + .cert_file_name = "../misc/cert.pem", + .passphrase = "1234" + }).get("/*", [](auto *res, auto */*req*/) { + res->end("Hello quic!"); + }).listen(3000, [](auto *listen_socket) { + if (listen_socket) { + std::cout << "Listening on port " << 3000 << std::endl; + } + }).run(); + + std::cout << "Failed to listen on port 3000" << std::endl; +} diff --git a/src/Http3App.h b/src/Http3App.h new file mode 100644 index 0000000..46368e8 --- /dev/null +++ b/src/Http3App.h @@ -0,0 +1,33 @@ +#include "App.h" + +#include "Http3Response.h" +#include "Http3Request.h" +#include "Http3Context.h" + +namespace uWS { + + struct QuicApp { + Http3Context *http3Context; + + QuicApp(SocketContextOptions options = {}) { + /* Create the http3 context */ + http3Context = Http3Context::create((us_loop_t *)Loop::get(), options); + } + + QuicApp &listen(int port, std::function cb) { + return *this; + } + + QuicApp &get(std::string path, std::function cb) { + // http3Context->onHttp, internally using httprouter + + return *this; + } + + void run() { + + } + }; + + +} \ No newline at end of file diff --git a/src/Http3Context.h b/src/Http3Context.h new file mode 100644 index 0000000..093fa3b --- /dev/null +++ b/src/Http3Context.h @@ -0,0 +1,17 @@ +namespace uWS { + struct Http3Context { + static Http3Context *create(us_loop_t *loop, us_socket_context_options_t options) { + return nullptr; + + // call init here after setting the ext to Http3ContextData + } + + void init() { + // set all callbacks here + } + + void onHttp() { + // modifies the router we own as part of Http3ContextData, used in callbacks set in init + } + }; +} \ No newline at end of file diff --git a/src/Http3ContextData.h b/src/Http3ContextData.h new file mode 100644 index 0000000..e69de29 diff --git a/src/Http3Request.h b/src/Http3Request.h new file mode 100644 index 0000000..9139931 --- /dev/null +++ b/src/Http3Request.h @@ -0,0 +1,6 @@ +namespace uWS { + + struct Http3Request { + // really the same thing as HttpRequest with same rules + }; +} \ No newline at end of file diff --git a/src/Http3Response.h b/src/Http3Response.h new file mode 100644 index 0000000..50f9463 --- /dev/null +++ b/src/Http3Response.h @@ -0,0 +1,11 @@ +namespace uWS { + + struct Http3Response { + // has a quic stream + + void end(std::string_view data) { + + } + }; + +} \ No newline at end of file