-
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.
Merge pull request #11 from san-ghun/dev/multi-host
Dev/multi host
- Loading branch information
Showing
36 changed files
with
2,317 additions
and
1,030 deletions.
There are no files selected for viewing
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
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
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,35 @@ | ||
#ifndef CONTEXT_H | ||
#define CONTEXT_H | ||
|
||
#include "Config.hpp" | ||
#include "Location.hpp" | ||
#include "HttpRequest.hpp" | ||
|
||
std::string getMatchedLocation(const std::string& path, const std::map<std::string, Location*>& locations); | ||
std::string getParentPath(const std::string& path); | ||
std::string normalisePath(const std::string& path); | ||
|
||
class Context { | ||
public: | ||
Context(ServerConfig& config, HttpRequest& request); | ||
Context(const Context& other); | ||
~Context(); | ||
Context& operator=(const Context& other); | ||
; | ||
const ServerConfig& getServer() const; | ||
const Location& getLocation() const; | ||
const HttpRequest& getRequest() const; | ||
|
||
void setRequest(HttpRequest& request); | ||
void setServer(ServerConfig& config); | ||
void setLocation(Location& location); | ||
|
||
private: | ||
ServerConfig& _serverConfig; | ||
HttpRequest& _request; | ||
Location& _location; | ||
|
||
Location& _findLocation(Context& context) const; | ||
}; | ||
|
||
#endif // CONTEXT_H |
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,31 @@ | ||
#ifndef ERRORRESPONSE_HPP | ||
#define ERRORRESPONSE_HPP | ||
|
||
#include <string> | ||
#include <map> | ||
#include "Location.hpp" | ||
#include "HttpResponse.hpp" | ||
|
||
class Location; | ||
class HttpResponse; | ||
class Context; | ||
|
||
struct t_page_detail; | ||
|
||
class ErrorResponse : public HttpResponse { | ||
public: | ||
ErrorResponse(const Context& context); | ||
~ErrorResponse(); | ||
HttpResponse generateErrorResponse(int code); | ||
|
||
private: | ||
std::map<int, t_page_detail> _pageCache; | ||
|
||
|
||
std::string _getErrorPagePath(int code) const; | ||
std::string _getFullErrorPath(const std::string& path) const; | ||
t_page_detail _fetchPageData(int code); | ||
|
||
}; | ||
|
||
#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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: minakim <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/06/30 16:23:00 by sanghupa #+# #+# */ | ||
/* Updated: 2024/07/26 12:30:28 by minakim ### ########.fr */ | ||
/* Updated: 2024/10/23 11:19:30 by minakim ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -17,51 +17,82 @@ | |
# include <map> | ||
# include <vector> | ||
|
||
# include "Util.hpp" | ||
|
||
class HttpResponse; | ||
|
||
|
||
# define WHITESPACE " \t\r\n" | ||
# define NOT_SET 0 | ||
|
||
struct t_readed_parts { | ||
struct ReadedLines | ||
{ | ||
std::string request; | ||
std::vector<std ::string> headers; | ||
std::string body; | ||
bool iscomplete; | ||
t_readed_parts() : iscomplete(false) {} | ||
std::vector<std::string> headers; | ||
std::string bodyLines; | ||
}; | ||
|
||
|
||
class HttpRequest | ||
{ | ||
public: | ||
HttpRequest(); | ||
~HttpRequest(); | ||
|
||
bool parse(const std::string& requestData); | ||
|
||
std::string getMethod() const; | ||
std::string getUri() const; | ||
std::string getVersion() const; | ||
public: | ||
enum e_body_type | ||
{ | ||
RAW, | ||
CHUNKED, | ||
FORM_DATA, | ||
NONE | ||
}; | ||
|
||
std::map<std::string, std::string> getHeaders() const; | ||
std::string getBody() const; | ||
public: | ||
|
||
void setUri(std::string uri); | ||
HttpRequest(); | ||
HttpRequest(std::string& data); | ||
~HttpRequest(); | ||
bool parse(const std::string& requestData); | ||
|
||
std::string getMethod() const; | ||
std::string getUri() const; | ||
std::string getVersion() const; | ||
std::map<std::string, std::string> getHeaders() const; | ||
std::string getBody() const; | ||
|
||
size_t getContentLength() const; | ||
|
||
void setUri(const std::string& uri); | ||
void setMethod(const std::string& method); | ||
void setVersion(const std::string& version); | ||
void setHeaders(const std::map<std::string, std::string>& headers); | ||
void setBody(const std::vector<std::string>& bodyLines, e_body_type type); | ||
void setBody(const std::string& bodyLines, e_body_type type); | ||
void setContentLength(const ssize_t& contentLength); | ||
|
||
bool hasBody() const; | ||
|
||
bool isConnectionClose() const; | ||
static std::string trim(const std::string& str); | ||
private: | ||
std::string _method; | ||
std::string _uri; | ||
std::string _version; | ||
std::map<std::string, std::string> _headers; | ||
std::string _body; | ||
bool isConnectionClose() const; | ||
static std::string trim(const std::string& str); | ||
|
||
private: | ||
std::string _method; // GET, POST, DELETE | ||
std::string _uri; // | ||
std::string _version; // HTTP/1.1 | ||
std::map<std::string, std::string> _headers; // key: value | ||
std::string _body; // raw, chunked, formdata | ||
e_body_type _type; // type of body @see e_body_type | ||
std::pair<bool, size_t> _content; // from Headers["Content-Length"], if not found NOT_SET -1 | ||
|
||
t_readed_parts _splitRequestData(const std::string& requestData); | ||
bool _parseRequestLine(const std::string requestLine); | ||
bool _parseHeaders(const std::vector<std ::string> headerLines); | ||
bool _parseBody(const std::string bodylines); | ||
std::vector<std ::string> _convertPartToHeaders(std::istringstream& iss); | ||
std::string _convertPartToBody(std::istringstream& iss); | ||
|
||
ReadedLines _splitRequestData(const std::string& requestData); | ||
|
||
bool _processRequestBody(const std::string& bodyLines); | ||
bool _parseRequestLine(const std::string& requestLine); | ||
bool _parseHeaders(const std::vector<std ::string>& headerLines); | ||
|
||
std::vector<std ::string> _convertPartToHeaders(std::istringstream& iss); | ||
std ::string _convertPartToBodyLines(std::istringstream& iss); | ||
|
||
}; | ||
|
||
// TODO: implement "<< operator" for HttpRequest | ||
// std::ostream& operator<<(std::ostream& os, const HttpRequest& request); | ||
#endif |
Oops, something went wrong.