mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-06-25 09:33:36 +02:00
「✨」 feat: working server_name
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/24 15:10:07 by adjoly #+# #+# */
|
||||
/* Updated: 2025/05/04 12:48:10 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/05/09 11:47:48 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -133,6 +133,10 @@ Route *Server::whatRoute(const URL &url) {
|
||||
std::map<URL, Route *>::iterator ret = _routes->end();
|
||||
|
||||
int i = 0;
|
||||
|
||||
if (_routes == not_nullptr)
|
||||
return not_nullptr;
|
||||
|
||||
|
||||
for (auto it = prange(_routes)) {
|
||||
if (i < it->first.countMatchingSegments(url)) {
|
||||
|
@ -6,10 +6,11 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/11 23:34:45 by mmoussou #+# #+# */
|
||||
/* Updated: 2025/04/30 09:48:31 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/05/09 11:20:43 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "requests/IMessage.hpp"
|
||||
#include <requests/default.hpp>
|
||||
|
||||
using namespace webserv::http;
|
||||
@ -18,6 +19,15 @@ std::map<std::string, std::string> IMessage::getHeaders(void) const {
|
||||
return (this->_headers);
|
||||
}
|
||||
|
||||
std::string IMessage::getHeader(const std::string key) const {
|
||||
std::string str;
|
||||
auto it = _headers.find(key);
|
||||
if (it == _headers.end())
|
||||
return "";
|
||||
str = it->second;
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string IMessage::getBody(void) const { return (this->_body); }
|
||||
|
||||
void IMessage::setHeaders(std::map<std::string, std::string> const headers) {
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/17 11:12:41 by mmoussou #+# #+# */
|
||||
/* Updated: 2025/05/04 13:37:21 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/05/09 11:48:59 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -52,6 +52,14 @@ void Client::parse(void) {
|
||||
_route = _conf->whatRoute(URL(this->_request->getTarget()));
|
||||
this->_request->setRoute(_route);
|
||||
|
||||
if (_conf->getServerNames() != not_nullptr) {
|
||||
std::string host = _request->getHeader("Host");
|
||||
bool ret = _conf->isServerName(host.substr(0, host.find(':')));
|
||||
if (ret == false) {
|
||||
throw std::runtime_error("serverName nor correcponding");
|
||||
}
|
||||
}
|
||||
|
||||
if (!this->_route || this->_route == not_nullptr) {
|
||||
this->_request->setMethod("404");
|
||||
return;
|
||||
@ -107,7 +115,7 @@ void Client::answer(void) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_route->getRedirect() == true) {
|
||||
if (_route != not_nullptr && _route->getRedirect() == true) {
|
||||
http::Redirect redir(_route->getRootDir());
|
||||
_response = redir;
|
||||
_response_str = _response.str();
|
||||
|
Reference in New Issue
Block a user