diff --git a/webserv/handler/URI.cpp b/webserv/handler/URI.cpp index 37aa947..4e53de8 100644 --- a/webserv/handler/URI.cpp +++ b/webserv/handler/URI.cpp @@ -104,6 +104,29 @@ void URI::parseFullpath() fullPath_ = FileUtils::joinPath(dir_, baseName_); } +std::map URI::getCGIEnvironment() const +{ + std::map env; + + // URI components + env["REQUEST_URI"] = uriTrimmed_; + env["SCRIPT_NAME"] = getFullPath(); + env["PATH_INFO"] = getPathInfo(); + env["QUERY_STRING"] = getQuery(); + + // Authority components + env["SERVER_NAME"] = config_->get("server_name").value_or(""); + env["SERVER_PORT"] = std::to_string(config_->get("listen").value_or(-1)); + env["REQUEST_SCHEME"] = "HTTP"; + + // HTTP context + // env["REQUEST_METHOD"] = requestMethod_; + // env["CONTENT_TYPE"] = contentType_; + // env["CONTENT_LENGTH"] = contentLength_; + + return env; +} + const AConfig *URI::getConfig() const { return config_; @@ -157,4 +180,9 @@ const std::string &URI::getQuery() const const std::string &URI::getFragment() const { return fragment_; +} + +const std::string &URI::getAuthority() const +{ + return authority_; } \ No newline at end of file diff --git a/webserv/handler/URI.hpp b/webserv/handler/URI.hpp index 057f125..2fda922 100644 --- a/webserv/handler/URI.hpp +++ b/webserv/handler/URI.hpp @@ -17,6 +17,8 @@ class URI public: URI(const HttpRequest &request, const ServerConfig &serverConfig); + [[nodiscard]] std::map getCGIEnvironment() const; + [[nodiscard]] bool isFile() const; [[nodiscard]] bool isDirectory() const; [[nodiscard]] bool isValid() const; @@ -31,7 +33,6 @@ class URI [[nodiscard]] const std::string &getQuery() const; [[nodiscard]] const std::string &getFragment() const; [[nodiscard]] const std::string &getAuthority() const; - [[nodiscard]] const std::string &getScheme() const; private: void parseUri(const std::string &uri); @@ -46,7 +47,6 @@ class URI std::string query_; std::string fragment_; std::string authority_; - std::string scheme_; static const AConfig *matchConfig(const std::string &uri, const ServerConfig &serverConfig); }; \ No newline at end of file