forked from cat/WebBase
No need to do a while loop
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
#include "../Helpers.hpp"
|
#include "../Helpers.hpp"
|
||||||
#include "../Main.hpp"
|
#include "../Main.hpp"
|
||||||
|
#include <asio/impl/read.hpp>
|
||||||
|
#include <asio/impl/read_until.hpp>
|
||||||
#include <asio/socket_base.hpp>
|
#include <asio/socket_base.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <istream>
|
#include <istream>
|
||||||
@@ -9,6 +11,7 @@ void HTTPrequest::processHTTPHeader() {
|
|||||||
std::shared_ptr<HTTPrequest> self(shared_from_this());
|
std::shared_ptr<HTTPrequest> self(shared_from_this());
|
||||||
|
|
||||||
// HEADER read
|
// HEADER read
|
||||||
|
//
|
||||||
asio::async_read_until(
|
asio::async_read_until(
|
||||||
sock, buffer, "\r\n\r\n", // its not the other way bud
|
sock, buffer, "\r\n\r\n", // its not the other way bud
|
||||||
[this, self](std::error_code error, std::size_t packageSize) {
|
[this, self](std::error_code error, std::size_t packageSize) {
|
||||||
@@ -80,7 +83,7 @@ void inline HTTPrequest::processBody() {
|
|||||||
|
|
||||||
// This part needs to be sync since we want this specific instance
|
// This part needs to be sync since we want this specific instance
|
||||||
// execution to pause
|
// execution to pause
|
||||||
while (octetCount < uploadSize) {
|
if (octetCount < uploadSize) {
|
||||||
octetCount += asio::read(sock, buffer.prepare(uploadSize));
|
octetCount += asio::read(sock, buffer.prepare(uploadSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
#include "Helpers.hpp"
|
#include "Helpers.hpp"
|
||||||
#include "Main.hpp"
|
#include "Main.hpp"
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
// Idea is very simple this map has it so that stuff like
|
// Idea is very simple this map has it so that stuff like
|
||||||
// responseMethods["GET","/"] have a method inside them
|
// responseMethods["GET","/"] have a method inside them
|
||||||
@@ -21,8 +20,6 @@ void Webserver::initResponses() {
|
|||||||
responseMethods["POST"]["/upload"] = [](HTTPrequest *self) {
|
responseMethods["POST"]["/upload"] = [](HTTPrequest *self) {
|
||||||
auto result = Helpers::processFormData(self->bodyContent,
|
auto result = Helpers::processFormData(self->bodyContent,
|
||||||
self->headers["Content-Type"]);
|
self->headers["Content-Type"]);
|
||||||
std::stringstream resp;
|
self->sendResponse("200 OK", "text/text", self->bodyContent);
|
||||||
resp << self->bodyContent;
|
|
||||||
self->sendResponse("200 OK", "text/text", resp.str());
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user