-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathredirect_handler.cc
More file actions
35 lines (28 loc) · 1000 Bytes
/
redirect_handler.cc
File metadata and controls
35 lines (28 loc) · 1000 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "redirect_handler.h"
RedirectHandler::RedirectHandler() {}
RedirectHandler::~RedirectHandler() {}
RedirectHandler::Status RedirectHandler::Init(const std::string& uri_prefix, const NginxConfig& config) {
(void) uri_prefix;
// expecting one statement in child block: url <url>;
bool url_found = false;
for (std::size_t i = 0; i < config.statements_.size(); i++) {
if (config.statements_[i]->tokens_.size() >= 2 &&
config.statements_[i]->tokens_[0] == "url") {
url_ = config.statements_[i]->tokens_[1];
url_found = true;
}
}
if (!url_found) {
return INTERNAL_ERROR;
}
return OK;
}
RedirectHandler::Status RedirectHandler::HandleRequest(const Request& request, Response* response) {
(void) request;
response->SetStatus(Response::ResponseCode::REDIRECT);
response->AddHeader("Location", url_);
return OK;
}
std::string RedirectHandler::GetName() {
return "RedirectHandler";
}