Skip to content

Commit

Permalink
fix(GetRequestHandler): added c_str() to resource_type for make_pair
Browse files Browse the repository at this point in the history
  • Loading branch information
Taanviir committed Apr 24, 2024
1 parent beb44d1 commit c856972
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions sources/http/handler/GetRequestHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "webserv.hpp"
#include "GetRequestHandler.hpp"
#include "debug.hpp"
#include "FileType.hpp"
#include "CachedPages.hpp"
#include "Cgi.hpp"
#include "FileType.hpp"
#include "debug.hpp"
#include "webserv.hpp"

GetRequestHandler::GetRequestHandler()
{
Expand Down Expand Up @@ -34,11 +34,11 @@ const vector<char> GetRequestHandler::get_resource(const Request& request,
{
vsp requestHeaders = request.get_headers();
string resource = request.get_resource();
string defaultPage = config.serverRoot + "/";
string defaultPage = config.serverRoot + "/";
vector<char> body;


add_header(make_pair<string, string>("Server", config.serverName));
add_header(make_pair<string, string>("Server", config.serverName.c_str()));


ifstream resource_file;
Expand All @@ -47,7 +47,7 @@ const vector<char> GetRequestHandler::get_resource(const Request& request,
if (resource == defaultPage) {
body = cachedPages->home.data;
add_header(make_pair<string, string>("Content-Type",
cachedPages->home.contentType));
cachedPages->home.contentType.c_str()));

add_header(make_pair<string, string>("Content-Length",
ws_itoa(cachedPages->home.contentLength)));
Expand All @@ -57,32 +57,33 @@ const vector<char> GetRequestHandler::get_resource(const Request& request,
if (resource_file.fail()) {
status = NOT_FOUND;
add_header(make_pair<string, string>("Content-Type",
cachedPages->notFound.contentType));
cachedPages->notFound.contentType.c_str()));
add_header(make_pair<string, string>("Content-Length",
ws_itoa(cachedPages->notFound.contentLength)));
body = cachedPages->notFound.data;
}
else {
string resource_type = find_resource_type(resource);
if (resource_type.length() != 0)
add_header(make_pair<string, string>("Content-Type", resource_type));
add_header(
make_pair<string, string>("Content-Type", resource_type.c_str()));

if (resource_type == "bash" || resource_type == "python") {
Cgi cgi(request);
string result;

result = cgi.execute();
body = vector<char>(result.begin(), result.end());
add_header(make_pair<string, string>("Content-Length",
ws_itoa(body.size())));
add_header(
make_pair<string, string>("Content-Length", ws_itoa(body.size())));
}
else {
body = vector<char>((std::istreambuf_iterator<char>(resource_file)),
std::istreambuf_iterator<char>());
resource_file.seekg(0, std::ios_base::end);
resource_size = resource_file.tellg();
add_header(make_pair<string, string>("Content-Length",
ws_itoa(resource_size)));
add_header(
make_pair<string, string>("Content-Length", ws_itoa(resource_size)));
resource_file.seekg(0, std::ios_base::beg);
}
// content type
Expand Down

0 comments on commit c856972

Please sign in to comment.