Remove unused includes and added some comments
This commit is contained in:
4
main.cpp
4
main.cpp
@@ -1,15 +1,18 @@
|
||||
#include "request.hpp"
|
||||
#include "response.hpp"
|
||||
#include "router.hpp"
|
||||
|
||||
int main() {
|
||||
|
||||
Router router(8080);
|
||||
// Allow all Methods
|
||||
router.Handle("/helloWorld", [](Request req, Response res) -> Response {
|
||||
res.SetPayload("Hello World!");
|
||||
res.SetContentType("text/plain");
|
||||
return res;
|
||||
});
|
||||
|
||||
// Only allow GET
|
||||
router.Handle("GET /echo/{name}", [](Request req, Response res) -> Response {
|
||||
std::string name = req.path.Get("name").value_or("No Name given");
|
||||
res.SetPayload("Hello " + name);
|
||||
@@ -17,6 +20,7 @@ int main() {
|
||||
return res;
|
||||
});
|
||||
|
||||
// Only allow POST
|
||||
router.Handle("POST /echo/{name}", [](Request req, Response res) -> Response {
|
||||
std::string name = req.path.Get("name").value_or("No Name given");
|
||||
res.SetPayload("Hello with Post" + name);
|
||||
|
||||
@@ -24,7 +24,7 @@ bool Request::protocol(std::stringstream *ss, int *procPart, char c) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// This is shit
|
||||
// This is shit, meaning the path constructor
|
||||
Request::Request(std::vector<std::byte> buf) : path("") {
|
||||
std::string name;
|
||||
std::stringstream ss;
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
#include <iostream>
|
||||
#include <netinet/in.h>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
Response::Response(http::statusCode statusCode) { m_statusCode = statusCode; }
|
||||
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
#include "router.hpp"
|
||||
#include <algorithm> // std::equal
|
||||
#include <cctype> // std::tolower
|
||||
#include <csignal>
|
||||
#include <netinet/in.h>
|
||||
#include <string_view> // std::string_view
|
||||
#include <strings.h>
|
||||
#include <sys/socket.h>
|
||||
#include <vector>
|
||||
|
||||
Router::Router(int port) {
|
||||
m_socket = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
Reference in New Issue
Block a user