Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CreateServerLocationsの実装 #83

Merged
merged 19 commits into from
Jul 22, 2022
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
4 changes: 2 additions & 2 deletions docs/class/config_class.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ classDiagram
-bool autoindex
-string index_page
-string path
-string redirect_uri
-string redirect_url
-set~string~ allow_methods
-string alias
-string cgi_extension
Expand Down Expand Up @@ -74,7 +74,7 @@ classDiagram
-int client_max_body_size
-bool autoindex
-string index_page
-string redirect_uri
-string redirect_url
-set~string~ allow_methods
-string path
-string alias
Expand Down
4 changes: 2 additions & 2 deletions docs/class/transaction_class.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Transaction {
throw HTTPException(413); // ステータスコードを設定。
}
if (sl.IsRedirect()) {
return ResponseBuilder.BuildRedirect(sl.redirect_uri());
return ResponseBuilder.BuildRedirect(sl.redirect_url());
}
if (sl.IsCGI()) {
return CGIExecutor(req, sl);
Expand Down Expand Up @@ -140,7 +140,7 @@ ResponseBuilder {
}
return new HTTPResponse();
}
HTTPResponse BuildRedirect(string redirect_uri) {
HTTPResponse BuildRedirect(string redirect_url) {
// locationにredirect_urlを設定
// status_codeは302
// TODO: これとerror_pageで302が設定されていた場合
Expand Down
15 changes: 15 additions & 0 deletions srcs/Config/DefaultValues.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "DefaultValues.hpp"

#include <string>

const std::string DefaultValues::kServerName = ""; // NOLINT
// TODO(iyamada)
// デフォルトのpathはどうするか。正規表現で全部マッチみたいになってそう。
const std::string DefaultValues::kPath = ""; // NOLINT
const std::string DefaultValues::kIndexPage = ""; // NOLINT
const std::string DefaultValues::kRedirectUrl = ""; // NOLINT
const std::string DefaultValues::kAlias = ""; // NOLINT
const std::string DefaultValues::kCgiExtension = ""; // NOLINT
const int DefaultValues::kPort = 80;
const int DefaultValues::kClientMaxBodySize = 1024;
const bool DefaultValues::kAutoIndex = false;
22 changes: 22 additions & 0 deletions srcs/Config/DefaultValues.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef SRCS_CONFIG_DEFAULTVALUES_HPP_
#define SRCS_CONFIG_DEFAULTVALUES_HPP_

#include <string>

/*
Store default directive value
*/
class DefaultValues {
public:
static const std::string kServerName;
static const std::string kPath;
static const std::string kIndexPage;
static const std::string kRedirectUrl;
static const std::string kAlias;
static const std::string kCgiExtension;
static const int kPort;
static const int kClientMaxBodySize;
static const bool kAutoIndex;
};

#endif // SRCS_CONFIG_DEFAULTVALUES_HPP_
13 changes: 13 additions & 0 deletions srcs/Config/InitialValues.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "InitialValues.hpp"

#include <string>

const std::string InitialValues::kServerName = ""; // NOLINT
const std::string InitialValues::kPath = ""; // NOLINT
const std::string InitialValues::kIndexPage = ""; // NOLINT
const std::string InitialValues::kRedirectUrl = ""; // NOLINT
const std::string InitialValues::kAlias = ""; // NOLINT
const std::string InitialValues::kCgiExtension = ""; // NOLINT
const int InitialValues::kPort = -1;
const int InitialValues::kClientMaxBodySize = -1;
const bool InitialValues::kAutoIndex = false;
22 changes: 22 additions & 0 deletions srcs/Config/InitialValues.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef SRCS_CONFIG_INITIALVALUES_HPP_
#define SRCS_CONFIG_INITIALVALUES_HPP_

#include <string>

/*
Store initial directive value
*/
class InitialValues {
public:
static const std::string kServerName;
static const std::string kPath;
static const std::string kIndexPage;
static const std::string kRedirectUrl;
static const std::string kAlias;
static const std::string kCgiExtension;
static const int kPort;
static const int kClientMaxBodySize;
static const bool kAutoIndex;
};

#endif // SRCS_CONFIG_INITIALVALUES_HPP_
10 changes: 5 additions & 5 deletions srcs/Config/LocationContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ LocationContext& LocationContext::operator=(const LocationContext& other) {
this->auto_index_ = other.auto_index_;
this->index_page_ = other.index_page_;
this->path_ = other.path_;
this->redirect_uri_ = other.redirect_uri_;
this->redirect_url_ = other.redirect_url_;
this->allow_methods_ = other.allow_methods_;
this->alias_ = other.alias_;
this->cgi_extension_ = other.cgi_extension_;
Expand All @@ -33,8 +33,8 @@ int LocationContext::client_max_body_size() const {
bool LocationContext::auto_index() const { return this->auto_index_; }
std::string LocationContext::index_page() const { return this->index_page_; }
std::string LocationContext::path() const { return this->path_; }
std::string LocationContext::redirect_uri() const {
return this->redirect_uri_;
std::string LocationContext::redirect_url() const {
return this->redirect_url_;
}
std::set<std::string> LocationContext::allow_methods() const {
return this->allow_methods_;
Expand All @@ -54,8 +54,8 @@ void LocationContext::set_index_page(const std::string& index_page) {
this->index_page_ = index_page;
}
void LocationContext::set_path(const std::string& path) { this->path_ = path; }
void LocationContext::set_redirect_uri(const std::string& redirect_uri) {
this->redirect_uri_ = redirect_uri;
void LocationContext::set_redirect_url(const std::string& redirect_url) {
this->redirect_url_ = redirect_url;
}
void LocationContext::set_alias(const std::string& alias) {
this->alias_ = alias;
Expand Down
6 changes: 3 additions & 3 deletions srcs/Config/LocationContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class LocationContext {
bool auto_index() const;
std::string index_page() const;
std::string path() const;
std::string redirect_uri() const;
std::string redirect_url() const;
std::set<std::string> allow_methods() const;
std::string alias() const;
std::string cgi_extension() const;
Expand All @@ -26,7 +26,7 @@ class LocationContext {
void set_auto_index(bool auto_index);
void set_index_page(const std::string& index_page);
void set_path(const std::string& path);
void set_redirect_uri(const std::string& redirect_uri);
void set_redirect_url(const std::string& redirect_url);
void set_alias(const std::string& alias);
void set_cgi_extension(const std::string& cgi_extension);

Expand All @@ -39,7 +39,7 @@ class LocationContext {
bool auto_index_;
std::string index_page_;
std::string path_;
std::string redirect_uri_;
std::string redirect_url_;
std::set<std::string> allow_methods_;
std::string alias_;
std::string cgi_extension_;
Expand Down
7 changes: 6 additions & 1 deletion srcs/Config/ServerContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include <sstream>

#include "InitialValues.hpp"
#include "WebservConfig.hpp"

template <typename T>
static T strtonum(const std::string& s) {
std::stringstream ss(s);
Expand All @@ -11,7 +14,9 @@ static T strtonum(const std::string& s) {
}

ServerContext::ServerContext()
: client_max_body_size_(1024), auto_index_(false), port_(80) {}
: client_max_body_size_(InitialValues::kClientMaxBodySize),
auto_index_(InitialValues::kAutoIndex),
port_(InitialValues::kPort) {}

ServerContext::ServerContext(const ServerContext& other) { *this = other; }

Expand Down
Loading