-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,153 additions
and
380 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
server { | ||
server_name server.com; | ||
listen 127.0.0.1:4242; | ||
error_page 403 error_pages/403.html; | ||
error_page 404 error_pages/404.html; | ||
error_page 405 error_pages/405.html; | ||
error_page 413 error_pages/413.html; | ||
error_page 500 error_pages/500.html; | ||
client_max_body_size 100000; | ||
|
||
location / { | ||
autoindex on; | ||
allow_methods GET POST DELETE; | ||
root web_root; | ||
upload_dir web_root/uploads | ||
index index.html index.php; | ||
cgi .php cgi-bin/php-cgi; | ||
} | ||
|
||
location /potato/ { | ||
autoindex on; | ||
root web_root; | ||
allow_methods GET POST DELETE; | ||
} | ||
|
||
location /redirect/ { | ||
return 301 https://google.com; | ||
} | ||
|
||
} | ||
server { | ||
server_name server2.com; | ||
listen 127.0.0.1:4242; | ||
error_page 403 error_pages/403.html; | ||
error_page 404 error_pages/404.html; | ||
error_page 405 error_pages/405.html; | ||
error_page 413 error_pages/413.html; | ||
error_page 500 error_pages/500.html; | ||
client_max_body_size 100; | ||
|
||
location / { | ||
autoindex off; | ||
allow_methods GET POST; | ||
root web_root; | ||
upload_dir web_root/uploads | ||
index index.html index.php; | ||
cgi .php cgi-bin/php-cgi; | ||
} | ||
|
||
location /potato2/ { | ||
autoindex on; | ||
root web_root; | ||
allow_methods GET; | ||
} | ||
|
||
location /redirect/ { | ||
return 301 https://google.com; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef CONFIG_HPP | ||
#define CONFIG_HPP | ||
|
||
#include "common.hpp" | ||
|
||
struct LocationConfig { | ||
std::string path; | ||
bool autoindex; | ||
std::vector<std::string> allow_methods; | ||
std::string root; | ||
std::string upload_dir; | ||
std::vector<std::string> index; | ||
std::string cgi_extension; | ||
std::string cgi_path; | ||
std::string redirect; | ||
}; | ||
|
||
struct ServerConfig { | ||
std::string server_name; | ||
std::string listen; | ||
std::map<int, std::string> error_pages; | ||
size_t client_max_body_size; | ||
std::vector<LocationConfig> locations; | ||
}; | ||
|
||
class Config { | ||
public: | ||
Config(const std::string &filePath); | ||
const std::vector<ServerConfig>& getServers() const; | ||
void printServers() const; | ||
|
||
private: | ||
std::string filePath; | ||
std::vector<ServerConfig> servers; | ||
|
||
void parseConfigFile(); | ||
void parseServerBlock(const std::vector<std::string> &lines, size_t &index); | ||
void parseLocationBlock(const std::vector<std::string> &lines, size_t &index, ServerConfig &server); | ||
std::string trim(const std::string& str); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* Request.hpp :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: bmoretti <bmoretti@student.42sp.org.br> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/07/11 18:24:18 by bmoretti #+# #+# */ | ||
/* Updated: 2024/07/11 18:58:26 by bmoretti ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef REQUEST_HPP | ||
# define REQUEST_HPP | ||
|
||
# include "common.hpp" | ||
|
||
typedef struct s_request | ||
{ | ||
std::string method; | ||
std::string uri; | ||
std::map<std::string, std::string> headers; | ||
} t_request; | ||
|
||
class Request | ||
{ | ||
public: | ||
Request(const char * str); | ||
~Request(); | ||
|
||
t_request getRequest() const; | ||
|
||
private: | ||
const char * _str; | ||
t_request _request; | ||
|
||
std::string _trim(const std::string & str); | ||
void _parseHTTPRequest(); | ||
|
||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* Response.hpp :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: bmoretti <bmoretti@student.42sp.org.br> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/07/13 13:06:55 by bmoretti #+# #+# */ | ||
/* Updated: 2024/07/13 14:02:44 by bmoretti ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef RESPONSE_HPP | ||
# define RESPONSE_HPP | ||
|
||
# include "common.hpp" | ||
# include "Request.hpp" | ||
|
||
typedef struct s_response | ||
{ | ||
std::string statusLine; | ||
std::map<std::string, std::string> headers; | ||
std::string body; | ||
} t_response; | ||
|
||
class Response | ||
{ | ||
public: | ||
Response(Request & request); | ||
~Response(); | ||
|
||
std::string getResponse() const; | ||
|
||
private: | ||
Request & _request; | ||
t_response _response; | ||
|
||
void _generateStatusLine(); | ||
void _generateHeaders(); | ||
void _generateBody(); | ||
std::string _generateResponse() const; | ||
|
||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.