Skip to content

Commit

Permalink
Merge pull request #44 from saladuit/mergeFix
Browse files Browse the repository at this point in the history
Merge fix
  • Loading branch information
lucienvb authored May 16, 2024
2 parents 112624b + fad8044 commit 6bba31b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 30 deletions.
47 changes: 23 additions & 24 deletions config/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,31 @@ server {
allowed_methods GET POST;
autoindex on;
}
# location /png/ {
# alias /data/images/png/;
# allowed_methods GET POST;
# autoindex off;
# }
#
# location /images/jpg/ {
# alias /data/upload/images/jpg/;
# allowed_methods GET POST;
# autoindex off;
# }
#
# location /upload/ {
# alias /data/upload/;
# allowed_methods POST DELETE;
# }
#
# location /removed_folder/ {
# alias /data/www/;
# allowed_methods GET;
# return /images/coffee-resized.jpeg ; # [1 - O] Reroute a directory to another URL; URL ; Default: []
# }

location /images/png/ {
alias /data/images/png/;
allowed_methods GET POST;
autoindex off;
}
location /images/jpg/ {
alias /data/images/jpg/;
allowed_methods GET POST;
autoindex off;
}
location /upload/ {
alias /data/upload/;
allowed_methods POST DELETE;
}
location /removed_folder/ {
allowed_methods GET;
return /images/coffee-resized.jpeg; # [1 - O] Reroute a directory to another URL; URL ; Default: []
}
}

#TODO: all Settings still need implementation into the Webserver
# [x] ServerBlock:
# [x] ServerBlock:
# [x] listen; //
# [x] server_name; // should go over the Clients/HTTPServers after
# // the request is recieved and see which serverSettings block is relevant to the request;
Expand Down
11 changes: 8 additions & 3 deletions src/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void Client::resolveServerSetting()
{
Logger &logger = Logger::getInstance();
const std::string &hp = _request.getHeader("Host");

std::string host = hp.substr(0, hp.find_first_of(":"));
for (const ServerSettings &block : _server_list)
{
Expand Down Expand Up @@ -82,7 +83,6 @@ void Client::setState(ClientState state)

void Client::checkCGI(const std::string &request_target, HTTPMethod method)
{
_serversetting.printServerSettings();
const LocationSettings &loc =
_serversetting.resolveLocation(request_target);

Expand Down Expand Up @@ -183,8 +183,13 @@ ClientState Client::handleConnection(
_exit(1);
_response.clear();
_file_manager.setResponse(e.what());
_state = _file_manager.openErrorPage(
_serversetting.getErrorDir().substr(1), e.getStatusCode());

const std::string errdir = _serversetting.getErrorDir();
if (errdir.empty())
_state = _file_manager.openErrorPage("", e.getStatusCode());
else
_state = _file_manager.openErrorPage(errdir.substr(1),
e.getStatusCode());
return (_state);
}
catch (ReturnException &e)
Expand Down
2 changes: 1 addition & 1 deletion src/HTTPRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <unistd.h>

HTTPRequest::HTTPRequest()
: _bytes_read(0), _content_length(0), _max_body_size(),
: _header_end(), _bytes_read(0), _content_length(0), _max_body_size(),
_methodType(HTTPMethod::UNKNOWN), _http_request(), _request_target(),
_http_version(), _body(), _headers(), _cgi(false)
{
Expand Down
3 changes: 1 addition & 2 deletions src/Poll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ void Poll::pollFDs(void)
Logger &logger = Logger::getInstance();
logger.log(INFO, "Polling " + std::to_string(_poll_fds.size()) +
" file descriptors");

int poll_count = poll(_poll_fds.data(), _poll_fds.size(), NO_TIMEOUT);
logger.log(DEBUG, "foo");
if (poll_count == SYSTEM_ERROR || poll_count == 0)
throw SystemException("poll"); // TODO: change poll_count 0 handler
}
Expand Down

0 comments on commit 6bba31b

Please sign in to comment.