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