Skip to content

Commit 2cf26d4

Browse files
committed
move status code to separate enums folder
1 parent f8e2066 commit 2cf26d4

7 files changed

Lines changed: 13 additions & 12 deletions

File tree

‎example/main.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// Personally, I don't encourange using namespaces, but, I left it here just so
1010
// that the code could be more readable ¯\_(ツ)_/¯
1111
using namespace expresso::core;
12+
using namespace expresso::enums;
1213
using namespace expresso::middleware;
1314

1415
// Global variable, just for fun :)

‎include/expresso/core/response.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <zippuccino/zipper.h>
1111

1212
#include <expresso/core/cookie.h>
13-
#include <expresso/core/status_code.h>
13+
#include <expresso/enums/status_code.h>
1414

1515
namespace expresso {
1616

@@ -21,7 +21,7 @@ class Response {
2121
bool hasEnded;
2222

2323
int socket;
24-
expresso::core::STATUS_CODE statusCode;
24+
expresso::enums::STATUS_CODE statusCode;
2525

2626
std::string message;
2727
std::vector<Cookie *> cookies;
@@ -41,7 +41,7 @@ class Response {
4141
void setCookie(Cookie *cookie);
4242
std::string get(std::string headerName);
4343

44-
Response &status(expresso::core::STATUS_CODE code);
44+
Response &status(expresso::enums::STATUS_CODE code);
4545
Response &send(std::string response);
4646
Response &json(std::string response);
4747
Response &json(json::object response);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace expresso {
44

5-
namespace core {
5+
namespace enums {
66

77
enum STATUS_CODE {
88
// Informational responses
@@ -105,6 +105,6 @@ enum STATUS_CODE {
105105
NETWORK_CONNECT_TIMEOUT_ERROR = 599
106106
};
107107

108-
} // namespace core
108+
} // namespace enums
109109

110110
} // namespace expresso

‎src/core/response.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ std::map<std::string, std::set<std::string>> Response::MIME_TYPES = {
1919

2020
expresso::core::Response::Response(int clientSocket)
2121
: hasEnded(false), socket(clientSocket),
22-
statusCode(expresso::core::STATUS_CODE::OK), message("") {
22+
statusCode(expresso::enums::STATUS_CODE::OK), message("") {
2323
return;
2424
}
2525

@@ -57,7 +57,7 @@ std::string expresso::core::Response::get(std::string headerName) {
5757
}
5858

5959
expresso::core::Response &
60-
expresso::core::Response::status(expresso::core::STATUS_CODE code) {
60+
expresso::core::Response::status(expresso::enums::STATUS_CODE code) {
6161
this->statusCode = code;
6262

6363
return *this;
@@ -168,7 +168,7 @@ void expresso::core::Response::sendFiles(const std::set<std::string> &paths,
168168
}
169169

170170
void expresso::core::Response::sendNotFound() {
171-
this->status(expresso::core::STATUS_CODE::NOT_FOUND)
171+
this->status(expresso::enums::STATUS_CODE::NOT_FOUND)
172172
.send(expresso::core::Response::NOT_FOUND)
173173
.end();
174174

‎src/core/server.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void expresso::core::Server::handleConnection(int clientSocket) {
110110
logger::error(
111111
e.what(),
112112
"void expresso::core::Server::handleConnection(int clientSocket)");
113-
res->status(STATUS_CODE::BAD_REQUEST).send("Bad Request");
113+
res->status(expresso::enums::STATUS_CODE::BAD_REQUEST).send("Bad Request");
114114
}
115115

116116
return;

‎src/middleware/cors.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ bool expresso::middleware::Cors::use(expresso::core::Request &req,
8484

8585
if (requestOrigin == "") {
8686
res.set("Access-Control-Allow-Origin", "null");
87-
res.status(expresso::core::STATUS_CODE::FORBIDDEN)
87+
res.status(expresso::enums::STATUS_CODE::FORBIDDEN)
8888
.send(expresso::middleware::Cors::FORBIDDEN);
8989
return false;
9090
}
@@ -101,7 +101,7 @@ bool expresso::middleware::Cors::use(expresso::core::Request &req,
101101

102102
if (!isOriginPresent) {
103103
res.set("Access-Control-Allow-Origin", "null");
104-
res.status(expresso::core::STATUS_CODE::FORBIDDEN)
104+
res.status(expresso::enums::STATUS_CODE::FORBIDDEN)
105105
.send(expresso::middleware::Cors::FORBIDDEN);
106106
return false;
107107
}

‎src/middleware/static_serve.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ bool expresso::middleware::StaticServe::use(expresso::core::Request &req,
3232

3333
res.send(this->getFolderHTML(req, tempPath));
3434
res.set("Content-Type", "text/html");
35-
res.status(expresso::core::STATUS_CODE::OK);
35+
res.status(expresso::enums::STATUS_CODE::OK);
3636
return false;
3737
}
3838

0 commit comments

Comments
 (0)