diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..2bbe336
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,21 @@
+---
+BasedOnStyle: Google
+BreakBeforeBraces: Custom
+BraceWrapping:
+ BeforeCatch: true
+ BeforeElse: true
+ SplitEmptyFunction: false
+ SplitEmptyRecord: false
+ SplitEmptyNamespace: false
+IndentWidth: 4
+AccessModifierOffset: -4
+IndentCaseLabels: false
+NamespaceIndentation: Inner
+ColumnLimit: 0
+AlignConsecutiveMacros: Consecutive
+DerivePointerAlignment: false
+SpacesBeforeTrailingComments: 1
+AllowShortBlocksOnASingleLine: Always
+AllowShortCaseLabelsOnASingleLine: true
+AllowShortIfStatementsOnASingleLine: AllIfsAndElse
+...
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..f426e1a
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,38 @@
+name: CI
+
+on: [push, pull_request]
+
+jobs:
+ lint:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - name: Run lint
+ uses: jidicula/clang-format-action@v4.11.0
+ with:
+ clang-format-version: "13"
+ fallback-style: "LLVM"
+
+ build-linux:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - name: Install dependencies
+ run: |
+ sudo apt-get update
+ sudo apt-get install -y g++ make
+ - name: Build
+ run: make
+ env:
+ CC: gcc
+ CXX: g++
+
+ build-macos:
+ runs-on: macos-latest
+ steps:
+ - uses: actions/checkout@v3
+ - name: Build
+ run: make
+ env:
+ CC: gcc
+ CXX: g++
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 67765a8..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,29 +0,0 @@
-before_install:
- - "eval \"${MATRIX_EVAL}\""
-language: cpp
-matrix:
- include:
- -
- env:
- - "MATRIX_EVAL=\"TESTENV=lint && STYLE=LLVM\""
- os: osx
- script:
- - "find . -name *.h -exec bash -c 'cmp <(clang-format --style=LLVM $0) $0' {} \\;"
- - "find . -name *.hpp -exec bash -c 'cmp <(clang-format --style=LLVM $0) $0' {} \\;"
- - "find . -name *.c -exec bash -c 'cmp <(clang-format --style=LLVM $0) $0' {} \\;"
- - "find . -name *.cpp -exec bash -c 'cmp <(clang-format --style=LLVM $0) $0' {} \\;"
- -
- before_install:
- - "sudo apt-get update"
- - "sudo apt-get install -y g++ make"
- env:
- - "MATRIX_EVAL=\"TESTENV=build && CC=gcc && CXX=g++\""
- os: linux
- script:
- - make
- -
- env:
- - "MATRIX_EVAL=\"TESTENV=build && CC=gcc && CXX=g++\""
- os: osx
- script:
- - make
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..972a459
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,49 @@
+CXX = g++
+CXXFLAGS = -std=c++11 -Wall -pedantic
+
+BUILD_DIR = build
+TEMPLATE_DIR = .template
+OUT_EXE = myserver.out
+
+ifeq ($(OS),Windows_NT)
+ LDLIBS += -l Ws2_32
+endif
+
+all: $(BUILD_DIR) $(OUT_EXE)
+
+$(OUT_EXE): $(BUILD_DIR)/main.o $(BUILD_DIR)/handlers.o $(BUILD_DIR)/response.o $(BUILD_DIR)/request.o $(BUILD_DIR)/utilities.o $(BUILD_DIR)/strutils.o $(BUILD_DIR)/server.o $(BUILD_DIR)/route.o $(BUILD_DIR)/template_parser.o
+ $(CXX) $(CXXFLAGS) $^ $(LDLIBS) -o $@
+
+$(BUILD_DIR):
+ mkdir -p $(BUILD_DIR)
+
+$(BUILD_DIR)/template_parser.o: utils/template_parser.cpp utils/template_parser.hpp utils/request.cpp utils/request.hpp utils/utilities.hpp utils/utilities.cpp utils/strutils.hpp utils/strutils.cpp
+ $(CXX) $(CXXFLAGS) -c $< -o $@
+
+$(BUILD_DIR)/response.o: utils/response.cpp utils/response.hpp utils/include.hpp
+ $(CXX) $(CXXFLAGS) -c $< -o $@
+
+$(BUILD_DIR)/request.o: utils/request.cpp utils/request.hpp utils/include.hpp utils/utilities.hpp
+ $(CXX) $(CXXFLAGS) -c $< -o $@
+
+$(BUILD_DIR)/utilities.o: utils/utilities.cpp utils/utilities.hpp utils/strutils.hpp
+ $(CXX) $(CXXFLAGS) -c $< -o $@
+
+$(BUILD_DIR)/strutils.o: utils/strutils.cpp utils/strutils.hpp
+ $(CXX) $(CXXFLAGS) -c $< -o $@
+
+$(BUILD_DIR)/server.o: server/server.cpp server/server.hpp server/route.hpp utils/utilities.hpp utils/strutils.hpp utils/response.hpp utils/request.hpp utils/include.hpp utils/template_parser.hpp utils/template_parser.cpp
+ $(CXX) $(CXXFLAGS) -c $< -o $@
+
+$(BUILD_DIR)/route.o: server/route.cpp server/route.hpp utils/utilities.hpp utils/response.hpp utils/request.hpp utils/include.hpp
+ $(CXX) $(CXXFLAGS) -c $< -o $@
+
+$(BUILD_DIR)/handlers.o: examples/handlers.cpp server/server.hpp utils/utilities.hpp utils/response.hpp utils/request.hpp utils/include.hpp
+ $(CXX) $(CXXFLAGS) -c $< -o $@
+
+$(BUILD_DIR)/main.o: examples/main.cpp server/server.hpp utils/utilities.hpp utils/response.hpp utils/request.hpp utils/include.hpp
+ $(CXX) $(CXXFLAGS) -c $< -o $@
+
+.PHONY: all clean
+clean:
+ rm -rf $(BUILD_DIR) $(TEMPLATE_DIR) *.o *.out &> /dev/null
diff --git a/README.md b/README.md
index c959749..ddbbee5 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,9 @@
AP HTTP
===
-[](https://travis-ci.com/UTAP/APHTTP)
-[](https://llvm.org/docs/CodingStandards.html)
-[](https://github.com/UTAP/APHTTP/releases/latest)
-[](https://github.com/UTAP/APHTTP/wiki)
-**AP HTTP::_server_** is a simple web application server-side blocking framework for C++ based on simplified versions of [W++](http://konteck.github.io/wpp/), [HappyHTTP](http://scumways.com/happyhttp/happyhttp.html), and [cpp-netlib](http://cpp-netlib.org/).
+[](https://github.com/AP-ECE-UT/APHTTP/license.md)
+[](https://github.com/AP-ECE-UT/APHTTP/releases/latest)
+[](https://github.com/AP-ECE-UT/APHTTP/wiki)
+
+**AP HTTP::_server_** is a simple web application server-side blocking framework for C++.
+This library is based on simplified versions of [W++](http://konteck.github.io/wpp/), [HappyHTTP](http://scumways.com/happyhttp/happyhttp.html), and [cpp-netlib](http://cpp-netlib.org/).
diff --git a/examples/handlers.cpp b/examples/handlers.cpp
index e88ddba..ce10ab7 100644
--- a/examples/handlers.cpp
+++ b/examples/handlers.cpp
@@ -1,54 +1,60 @@
#include "handlers.hpp"
-using namespace std;
-
-Response *RandomNumberHandler::callback(Request *req) {
- Response *res = new Response;
- res->setHeader("Content-Type", "text/html");
- string body;
- body += "";
- body += "";
- body += "
";
- body += "AP HTTP
";
- body += "";
- body += "a random number in [1, 10] is: ";
- body += to_string(rand() % 10 + 1);
- body += "
";
- body += "";
- body += "SeddionId: ";
- body += req->getSessionId();
- body += "
";
- body += "";
- body += "";
- res->setBody(body);
- return res;
+#include
+#include
+
+Response* RandomNumberHandler::callback(Request* req) {
+ Response* res = new Response();
+ res->setHeader("Content-Type", "text/html");
+
+ std::string randomNumber = std::to_string(std::rand() % 10 + 1);
+ std::string body;
+
+ body += "";
+ body += "";
+
+ body += "";
+ body += " Random Number Page";
+ body += "";
+
+ body += "";
+ body += " AP HTTP
";
+ body += " A random number in [1, 10] is: " + randomNumber + "
";
+ body += " SessionId: " + req->getSessionId() + "
";
+ body += "";
+
+ body += "";
+ res->setBody(body);
+ return res;
}
-Response *LoginHandler::callback(Request *req) {
- string username = req->getBodyParam("username");
- string password = req->getBodyParam("password");
- if (username == "root")
- throw Server::Exception("Remote root access has been disabled.");
- cout << "username: " << username << ",\tpassword: " << password << endl;
- Response *res = Response::redirect("/rand");
- res->setSessionId("SID");
- return res;
+Response* LoginHandler::callback(Request* req) {
+ std::string username = req->getBodyParam("username");
+ std::string password = req->getBodyParam("password");
+ if (username == "root") {
+ throw Server::Exception("Remote root access has been disabled.");
+ }
+ std::cout << "username: " << username << ",\tpassword: " << password << std::endl;
+ Response* res = Response::redirect("/rand");
+ res->setSessionId("SID");
+ return res;
}
-Response *UploadHandler::callback(Request *req) {
- string name = req->getBodyParam("file_name");
- string file = req->getBodyParam("file");
- cout << name << " (" << file.size() << "B):\n" << file << endl;
- Response *res = Response::redirect("/");
- return res;
+Response* UploadHandler::callback(Request* req) {
+ std::string name = req->getBodyParam("file_name");
+ std::string file = req->getBodyParam("file");
+ utils::writeToFile(file, name);
+ Response* res = Response::redirect("/");
+ return res;
}
-ColorHandler::ColorHandler(string filePath) : TemplateHandler(filePath) {}
+ColorHandler::ColorHandler(const std::string& filePath)
+ : TemplateHandler(filePath) {}
-map ColorHandler::handle(Request *req) {
- map context;
- string newName = "I am " + req->getQueryParam("name");
- context["name"] = newName;
- context["color"] = req->getQueryParam("color");
- return context;
+std::map ColorHandler::handle(Request* req) {
+ std::string newName = "I am " + req->getQueryParam("name");
+ std::map context;
+ context["name"] = newName;
+ context["color"] = req->getQueryParam("color");
+ return context;
}
diff --git a/examples/handlers.hpp b/examples/handlers.hpp
index 987d310..ed82807 100644
--- a/examples/handlers.hpp
+++ b/examples/handlers.hpp
@@ -1,30 +1,30 @@
-#ifndef _MY_HANDLERS_
-#define _MY_HANDLERS_
+#ifndef HANDLERS_HPP_INCLUDE
+#define HANDLERS_HPP_INCLUDE
+
+#include