Actually put headers, content-length and status in response

This commit is contained in:
Alex Hultman
2018-06-24 01:27:40 +02:00
parent a2fe871e63
commit 0cbccaf08e
5 changed files with 77 additions and 50 deletions
+17 -15
View File
@@ -1,31 +1,33 @@
// this is roughly the interfaces I plan for (with changes and additional helpers added with time)
// much speaks for a header-only or header-mostly implementation now that uSockets is properly isolating its internal headers
#include "uWS.h"
#include "App.h"
#include "HttpRouter.h"
std::string buffer;
//#define USE_SSL
int main() {
std::cout << "HttpSocket size: " << sizeof(HttpSocket<true>::Data) << std::endl;
char *buffer = new char[512];
buffer = "Why hello there!";
uWS::SSLApp c(uWS::SSLOptions()
//uWS::init();
//uWS::Loop loop();
#ifdef USE_SSL
uWS::SSLApp app(uWS::SSLOptions()
.keyFileName("/home/alexhultman/uWebSockets/misc/ssl/key.pem")
.certFileName("/home/alexhultman/uWebSockets/misc/ssl/cert.pem")
.passphrase("1234"));
//uWS::App c;
#else
uWS::App app;
#endif
c.onGet("/", [buffer](auto *s, HttpRequest *req, auto *args) {
app.onGet("/", [](auto *s, auto *req, auto *args) {
s->writeStatus(200)->writeHeader("Hello", "World")->end(buffer, 512);
s->writeStatus("200 OK")->writeHeader("Hello", "World")->end(buffer);
}).onGet("/wrong", [buffer](auto *s, HttpRequest *req, auto *args) {
std::cout << "Wrong way!" << std::endl;
}).onWebSocket([]() {
}).onWebSocket("/wsApi", []() {
}).listen("localhost", 3000, 0);
uWS::run();
// loop.run();
}