Skip to content

Commit

Permalink
fix(buildResponse): remove http:// from requestTarget
Browse files Browse the repository at this point in the history
  • Loading branch information
dantol29 committed May 17, 2024
1 parent 7f0d179 commit 93c9955
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,16 @@ void Server::buildResponse(Connection &conn, size_t &i, HTTPRequest &request, HT
std::string requestTarget = request.getRequestTarget();
// if there is "?" in the request target, we need to remove it
if (std::find(requestTarget.begin(), requestTarget.end(), '?') != requestTarget.end())
requestTarget = requestTarget.substr(0, requestTarget.find("?"));
std::cout << "Request target: " << requestTarget << std::endl;
requestTarget = (requestTarget.substr(0, requestTarget.find("?")));

size_t http = requestTarget.find("http://");
if (http != std::string::npos)
{
std::string remove = "http://";
requestTarget.erase(http, remove.length());
}
request.setRequestTarget(requestTarget);
std::cout << "Request target: " << request.getRequestTarget() << std::endl;

for (size_t i = 0; i < _config.getServerBlocks().size(); i++)
{
Expand Down
42 changes: 42 additions & 0 deletions var/localhost:8080/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome to Our Web Service</title>
</head>
<body>
<header>
<div class="container">
<h1>Welcome to Our Web Service</h1>
</div>
</header>
<nav>
<div class="container">
<a href="/development_site/cgi-bin/hello_py.cgi">Development Site</a>
<a href="/perl_site/index.html">Perl Site</a>
<a href="/php_site/index.html">PHP Site</a>
<a href="/www.python_site.com/index.html">Python Site</a>
</div>
</nav>
<div class="container">
<article>
<h2>About This Server</h2>
<p>Welcome to our multi-faceted web server. Here, you can find a variety of web applications and sites ranging from development tools to language-specific sites. Whether you're here to explore our Perl, PHP, or Python projects, or to delve into our development tools, there's something for everyone.</p>
<p>Please use the navigation above to explore our sites.</p>
</article>
</div>
<form action="http://localhost:8080/" method="post" enctype="multipart/form-data">
<label for="file">Choose a file:</label>
<input type="file" id="file" name="file">
<br>
<input type="submit" value="Upload">
</form>
<h2>Upload Multiple Files</h2>
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="files[]" multiple>
<br>
<input type="submit" value="Upload Files">
</form>
</body>
</html>
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions webserv_default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ server {
listen 8080;
server_name localho:8080 localhost:8080 www.localhost:8080;
allow_methods GET POST DELETE;
autoindex off;
autoindex on;
root /var/;
error_page 404 404.html;
cgi_ext .cgi;
Expand All @@ -20,7 +20,7 @@ server {

server {
listen 8080;
server_name www.example.com;
server_name www.php_site.com;
allow_methods GET POST DELETE;
autoindex off;
root var/;
Expand Down

0 comments on commit 93c9955

Please sign in to comment.