Update style to (almost) conform to ndn-cxx style using clang-format
diff --git a/server/request_handler.cpp b/server/request_handler.cpp
index 6087046..d2b339e 100644
--- a/server/request_handler.cpp
+++ b/server/request_handler.cpp
@@ -28,18 +28,18 @@
//
#include "request_handler.hpp"
-#include <fstream>
-#include <sstream>
-#include <string>
-#include <boost/lexical_cast.hpp>
+#include "logging.h"
#include "mime_types.hpp"
#include "reply.hpp"
#include "request.hpp"
-#include <QIODevice>
-#include <QFile>
+#include <boost/lexical_cast.hpp>
#include <QDataStream>
+#include <QFile>
+#include <QIODevice>
#include <QString>
-#include "logging.h"
+#include <fstream>
+#include <sstream>
+#include <string>
INIT_LOGGER("HttpServer")
@@ -51,27 +51,24 @@
{
}
-void request_handler::handle_request(const request& req, reply& rep)
+void
+request_handler::handle_request(const request& req, reply& rep)
{
// Decode url to path.
std::string request_path;
- if (!url_decode(req.uri, request_path))
- {
+ if (!url_decode(req.uri, request_path)) {
rep = reply::stock_reply(reply::bad_request);
return;
}
// Request path must be absolute and not contain "..".
- if (request_path.empty() || request_path[0] != '/'
- || request_path.find("..") != std::string::npos)
- {
+ if (request_path.empty() || request_path[0] != '/' || request_path.find("..") != std::string::npos) {
rep = reply::stock_reply(reply::bad_request);
return;
}
// If path ends in slash (i.e. is a directory) then add "index.html".
- if (request_path[request_path.size() - 1] == '/')
- {
+ if (request_path[request_path.size() - 1] == '/') {
request_path += "index.html";
}
@@ -79,8 +76,7 @@
std::size_t last_slash_pos = request_path.find_last_of("/");
std::size_t last_dot_pos = request_path.find_last_of(".");
std::string extension;
- if (last_dot_pos != std::string::npos && last_dot_pos > last_slash_pos)
- {
+ if (last_dot_pos != std::string::npos && last_dot_pos > last_slash_pos) {
extension = request_path.substr(last_dot_pos + 1);
}
@@ -92,8 +88,7 @@
// in /usr/local/share
QString full_path = doc_root_.absolutePath() + QString(request_path.c_str());
QFile file(full_path);
- if (!file.exists() || !file.open(QIODevice::ReadOnly))
- {
+ if (!file.exists() || !file.open(QIODevice::ReadOnly)) {
rep = reply::stock_reply(reply::not_found);
return;
}
@@ -103,15 +98,12 @@
rep.status = reply::ok;
char buf[512];
QDataStream in(&file);
- while (true)
- {
+ while (true) {
int bytes = in.readRawData(buf, sizeof(buf));
- if (bytes > 0)
- {
+ if (bytes > 0) {
rep.content.append(buf, bytes);
}
- else
- {
+ else {
break;
}
}
@@ -122,39 +114,32 @@
rep.headers[1].value = mime_types::extension_to_type(extension);
}
-bool request_handler::url_decode(const std::string& in, std::string& out)
+bool
+request_handler::url_decode(const std::string& in, std::string& out)
{
out.clear();
out.reserve(in.size());
- for (std::size_t i = 0; i < in.size(); ++i)
- {
- if (in[i] == '%')
- {
- if (i + 3 <= in.size())
- {
+ for (std::size_t i = 0; i < in.size(); ++i) {
+ if (in[i] == '%') {
+ if (i + 3 <= in.size()) {
int value = 0;
std::istringstream is(in.substr(i + 1, 2));
- if (is >> std::hex >> value)
- {
+ if (is >> std::hex >> value) {
out += static_cast<char>(value);
i += 2;
}
- else
- {
+ else {
return false;
}
}
- else
- {
+ else {
return false;
}
}
- else if (in[i] == '+')
- {
+ else if (in[i] == '+') {
out += ' ';
}
- else
- {
+ else {
out += in[i];
}
}