forked from cat/WebBase
Removed pointless headers, added comments
This commit is contained in:
20
src/HTTP.cpp
20
src/HTTP.cpp
@@ -1,17 +1,6 @@
|
|||||||
#include "Helpers.hpp"
|
#include "Helpers.hpp"
|
||||||
#include "Main.hpp"
|
#include "Main.hpp"
|
||||||
#include <asio/buffer.hpp>
|
|
||||||
#include <asio/completion_condition.hpp>
|
|
||||||
#include <asio/impl/write.hpp>
|
|
||||||
#include <asio/registered_buffer.hpp>
|
|
||||||
#include <asio/socket_base.hpp>
|
|
||||||
#include <asio/streambuf.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
#include <ostream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
|
||||||
#include <system_error>
|
|
||||||
|
|
||||||
void HTTPrequest::start() {
|
void HTTPrequest::start() {
|
||||||
// Possible Logging here
|
// Possible Logging here
|
||||||
@@ -36,6 +25,8 @@ void HTTPrequest::sendResponse(std::string status, std::string mime,
|
|||||||
<< "\r\nConnection: close\r\n\r\n"
|
<< "\r\nConnection: close\r\n\r\n"
|
||||||
<< data;
|
<< data;
|
||||||
|
|
||||||
|
// Idea here is that in TCP oncee you sent a shutdown you should read until
|
||||||
|
// EOF. When that happens, you know that the package is fully recieved
|
||||||
responseText = output.str();
|
responseText = output.str();
|
||||||
asio::async_write(
|
asio::async_write(
|
||||||
sock, asio::buffer(responseText),
|
sock, asio::buffer(responseText),
|
||||||
@@ -47,14 +38,15 @@ void HTTPrequest::sendResponse(std::string status, std::string mime,
|
|||||||
|
|
||||||
// I'm not happy with this
|
// I'm not happy with this
|
||||||
void HTTPrequest::waitForClientClose() {
|
void HTTPrequest::waitForClientClose() {
|
||||||
auto buf = std::array<char, 1>();
|
auto buf = std::array<char, 1>(); // I don't think there is a smaller possible
|
||||||
|
// constructor :(
|
||||||
sock.async_read_some(asio::buffer(buf),
|
sock.async_read_some(asio::buffer(buf),
|
||||||
[this, self = shared_from_this()](
|
[this, self = shared_from_this()](
|
||||||
const std::error_code &error, std::size_t) {
|
const std::error_code &error, std::size_t) {
|
||||||
if (error) {
|
if (error) {
|
||||||
sock.close();
|
sock.close(); // This triggers when EOF
|
||||||
}
|
}
|
||||||
waitForClientClose();
|
waitForClientClose(); // Ew recursion. Must fix.
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// ================= CLASS HANDLING SPECIFIC =================
|
// ================= CLASS HANDLING SPECIFIC =================
|
||||||
|
Reference in New Issue
Block a user