Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,6 @@ <h3>Special Files</h3>
<a href="/assets/old_index.html" class="btn">Archive File</a>
</div>
</div>
<!-- GET Tests -->
<h3><span class="method-badge get">GET</span> Method Tests</h3>
<div class="button-row">
<a href="/index.html" class="btn">Get HTML File</a>
<a href="/assets/style.css" class="btn">Get CSS File</a>
<a href="/assets/test.jpg" class="btn">Get Image File</a>
</div>

<!-- POST Tests -->
<h3><span class="method-badge post">POST</span> Method Test</h3>
Expand Down Expand Up @@ -343,13 +336,6 @@ <h3>Directory Tests</h3>
<a href="/empty/" class="btn">Empty Directory Test</a>
</div>

<h3>Static Files</h3>
<div class="button-row">
<a href="/test.html" class="btn">HTML File</a>
<a href="/test.txt" class="btn">Text File</a>
<a href="/test.pdf" class="btn">PDF File</a>
<a href="/test.json" class="btn">JSON File</a>
</div>
</div>

<!-- CGI Tests -->
Expand Down
2 changes: 1 addition & 1 deletion conf/default.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
server {
listen 0.0.0.0:8081;
listen 0.0.0.0:8001;
server_name localhost;
root ./;
autoindex on;
Expand Down
79 changes: 79 additions & 0 deletions conf/redirect.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
server {
listen 0.0.0.0:9050;
server_name localhost;
root ./;
autoindex on;
client_max_body_size 1m;
index assets/index.html;
use_chunked_encoding true;
chunk_size 100;
allowed_redirects 301 https://google.com;

# Custom error pages
error_page 404 /error_page/404.html;
error_page 403 /error_page/403.html;
error_page 500 /error_page/500.html;

# Main site and directory listing test
location /assets/ {
root ./;
index old_index.html;
allowed_methods GET;
autoindex on;
}

location /cgi-bin/ {
root ./;
allowed_methods GET POST;
cgi_path /usr/bin/python3 /usr/bin/php;
cgi_ext .py .php;
autoindex off;
}

location /uploads/ {
root ./;
allowed_methods POST GET DELETE;
}
}

server {
listen 0.0.0.0:9051;
server_name localhost;
root ./;
autoindex on;
client_max_body_size 1m;
index assets/index.html;
use_chunked_encoding true;
chunk_size 100;

# Custom error pages
error_page 404 /error_page/404.html;
error_page 403 /error_page/403.html;
error_page 500 /error_page/500.html;

# Main site and directory listing test
location /assets/ {
root ./;
index old_index.html;
allowed_methods GET;
autoindex on;
}

location /google/ {
allowed_redirects 301 https://google.com;
}

location /cgi-bin/ {
root ./;
allowed_methods GET POST;
cgi_path /usr/bin/python3 /usr/bin/php;
cgi_ext .py .php;
autoindex off;
}

location /uploads/ {
root ./;
allowed_methods POST GET DELETE;
}

}
2 changes: 1 addition & 1 deletion inc/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Config {
void setServerConf( ServerConf server );

//member fucnitons
void parse( std::string& filename );
void parse( std::string& filename );
void parseServerConfBlock( ServerConf& server );
void parseLocationConfBlock( ServerConf&, std::stringstream& );
};
Expand Down
8 changes: 0 additions & 8 deletions inc/HttpHelpers.hpp

This file was deleted.

3 changes: 3 additions & 0 deletions inc/HttpRequest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class HttpRequest {
//cgi response string
std::string _cgiResponseString;
std::string _hostname;
int _port;

// reference to which serverConf i have matched from request
ServerConf _server;
Expand All @@ -46,6 +47,7 @@ class HttpRequest {
ServerConf getServer() const;
PathInfo getPathInfo() const;
std::string getCgiResponseString() const;
int getPort() const;

//setters
void setMethod( std::string );
Expand All @@ -59,6 +61,7 @@ class HttpRequest {
void setServer( ServerConf );
void setPathInfo( PathInfo );
void setCgiResponseString(const std::string& cgiResponseString);
void setPort(const int port);

// main handler
void handleRequest(const std::string& rawRequest);
Expand Down
8 changes: 8 additions & 0 deletions inc/Response.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Response {
std::string _reasonPhrase;
const ServerConf* _serverConf;
LocationConf* _locationConf;
// for redirects
std::string _redirectDest;

// to make cookies work
// cookie value we want to have
Expand Down Expand Up @@ -62,6 +64,10 @@ class Response {
bool serveRootIndexfile(HttpRequest& ReqObj, std::string fullPath);
bool serveLocationIndex(HttpRequest& ReqObj);



// Handlers
void HandleRedirectRequest(HttpRequest& ReqObj, std::map<std::string, std::string > redirect);
void HandleDeleteRequest(HttpRequest& ReqObj, PathInfo& pathInfo);
void HandlePostRequest(HttpRequest& ReqObj,PathInfo& pathinfo);
void genarateUploadSucces(HttpRequest& ReqObj);
Expand All @@ -80,6 +86,7 @@ class Response {
std::string getServerName();
std::string getCurrentDateTime();
std::string getContentType(HttpRequest &reqObj, const std::string& extension);
std::string getRedirectDest();

// Setters
void setHttpResponse(const std::string& httpResponse) { _httpResponse = httpResponse; }
Expand All @@ -91,6 +98,7 @@ class Response {
void setFilename(const std::string& filename) { _filename = filename; }
void setStatusCode(int statusCode) { m_statusCode = statusCode; }
void setReasonPhrase(const std::string &reasonPhrase);
void setRedirectDest(const std::string& redirectDest) { _redirectDest = redirectDest; };

// for cookie setter
void setSetCookieValue(std::string value);
Expand Down
10 changes: 5 additions & 5 deletions src/Config/ServerConfAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ void ServerConf::checkAccess( void ){
throw( std::runtime_error( \
"RootDir: " + _rootDir + " not accsessible" ) );

//check every location
for( std::vector< LocationConf >::iterator it = _locations.begin(); \
it != _locations.end(); it++ ){
it->checkAccess( _rootDir );
}
// //check every location
// for( std::vector< LocationConf >::iterator it = _locations.begin();
// it != _locations.end(); it++ ){
// it->checkAccess( _rootDir );
// }

//check every errorpage path
for( std::map< int, std::string >::iterator it = _errorPages.begin(); \
Expand Down
24 changes: 0 additions & 24 deletions src/Http/HttpHelpers.cpp

This file was deleted.

Loading