Skip to content
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
16 changes: 16 additions & 0 deletions .github/workflows/verify-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ jobs:
cc-compiler: g++-7
debug: nodebug
coverage: nocoverage
- test-group: extra
os: ubuntu-latest
build-type: lint
compiler-family: gcc
c-compiler: gcc-7
cc-compiler: g++-7
debug: debug
coverage: nocoverage
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand Down Expand Up @@ -258,6 +266,10 @@ jobs:
- name: Install valgrind if needed
run: sudo apt-get install valgrind valgrind-dbg
if: ${{ matrix.build-type == 'valgrind' && matrix.os == 'ubuntu-latest' }}

- name: Install cpplint if needed
run: sudo pip3 install cpplint ;
if: ${{ matrix.build-type == 'lint' && matrix.os == 'ubuntu-latest' }}

- name: Install IWYU dependencies if needed
run: |
Expand Down Expand Up @@ -357,6 +369,10 @@ jobs:
run: sudo ldconfig ;
if: ${{ matrix.os == 'ubuntu-latest' }}

- name: Run cpplint on code
run: cpplint --extensions=cpp,hpp --headers=hpp --recursive . ;
if: ${{ matrix.build-type == 'lint' && matrix.os == 'ubuntu-latest' }}

- name: Run libhttpserver configure
run: |
# Set memory check flags. They need to stay in step as env variables don't propagate across steps.
Expand Down
4 changes: 4 additions & 0 deletions CPPLINT.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
linelength=200
headers=hpp
extensions=cpp,hpp
filter=-test/littletest.hpp
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Sun Mar 07 20:02:10 2021 -0800
Cleaned code to support cpplint and extra warnings.
Use pointers in place of non-const references.

Thu Feb 25 20:27:12 2021 -0800
Simplified dependency management for libmicrohttpd

Expand Down
9 changes: 5 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

AC_PREREQ(2.57)
m4_define([libhttpserver_MAJOR_VERSION],[0])dnl
m4_define([libhttpserver_MINOR_VERSION],[18])dnl
m4_define([libhttpserver_REVISION],[2])dnl
m4_define([libhttpserver_MINOR_VERSION],[19])dnl
m4_define([libhttpserver_REVISION],[0])dnl
m4_define([libhttpserver_PKG_VERSION],[libhttpserver_MAJOR_VERSION.libhttpserver_MINOR_VERSION.libhttpserver_REVISION])dnl
m4_define([libhttpserver_LDF_VERSION],[libhttpserver_MAJOR_VERSION:libhttpserver_MINOR_VERSION:libhttpserver_REVISION])dnl
AC_INIT([libhttpserver], libhttpserver_PKG_VERSION, [electrictwister2000@gmail.com])
Expand Down Expand Up @@ -194,8 +194,8 @@ AM_LDFLAGS="-lstdc++"

if test x"$debugit" = x"yes"; then
AC_DEFINE([DEBUG],[],[Debug Mode])
AM_CXXFLAGS="$AM_CXXFLAGS -DDEBUG -g -Wall -Wno-uninitialized -O0"
AM_CFLAGS="$AM_CXXFLAGS -DDEBUG -g -Wall -Wno-uninitialized -O0"
AM_CXXFLAGS="$AM_CXXFLAGS -DDEBUG -g -Wall -Wextra -Werror -pedantic -std=c++14 -Wno-unused-command-line-argument -O0"
AM_CFLAGS="$AM_CXXFLAGS -DDEBUG -g -Wall -Wextra -Werror -pedantic -Wno-unused-command-line-argument -O0"
else
AC_DEFINE([NDEBUG],[],[No-debug Mode])
AM_CXXFLAGS="$AM_CXXFLAGS -O3"
Expand Down Expand Up @@ -270,6 +270,7 @@ AC_SUBST(EXT_LIB_PATH)
AC_SUBST(EXT_LIBS)

AC_CONFIG_FILES([test/test_content:test/test_content])
AC_CONFIG_FILES([test/test_content_empty:test/test_content_empty])
AC_CONFIG_FILES([test/cert.pem:test/cert.pem])
AC_CONFIG_FILES([test/key.pem:test/key.pem])
AC_CONFIG_FILES([test/test_root_ca.pem:test/test_root_ca.pem])
Expand Down
16 changes: 7 additions & 9 deletions examples/allowing_disallowing_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@

#include <httpserver.hpp>

using namespace httpserver;

class hello_world_resource : public http_resource {
public:
const std::shared_ptr<http_response> render(const http_request&) {
return std::shared_ptr<http_response>(new string_response("Hello, World!"));
}
class hello_world_resource : public httpserver::http_resource {
public:
const std::shared_ptr<httpserver::http_response> render(const httpserver::http_request&) {
return std::shared_ptr<httpserver::http_response>(new httpserver::string_response("Hello, World!"));
}
};

int main(int argc, char** argv) {
webserver ws = create_webserver(8080);
int main() {
httpserver::webserver ws = httpserver::create_webserver(8080);

hello_world_resource hwr;
hwr.disallow_all();
Expand Down
26 changes: 11 additions & 15 deletions examples/basic_authentication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,19 @@

#include <httpserver.hpp>

using namespace httpserver;

class user_pass_resource : public httpserver::http_resource
{
public:
const std::shared_ptr<http_response> render_GET(const http_request& req)
{
if (req.get_user() != "myuser" || req.get_pass() != "mypass")
{
return std::shared_ptr<basic_auth_fail_response>(new basic_auth_fail_response("FAIL", "test@example.com"));
}
return std::shared_ptr<string_response>(new string_response(req.get_user() + " " + req.get_pass(), 200, "text/plain"));
}
class user_pass_resource : public httpserver::http_resource {
public:
const std::shared_ptr<httpserver::http_response> render_GET(const httpserver::http_request& req) {
if (req.get_user() != "myuser" || req.get_pass() != "mypass") {
return std::shared_ptr<httpserver::basic_auth_fail_response>(new httpserver::basic_auth_fail_response("FAIL", "test@example.com"));
}

return std::shared_ptr<httpserver::string_response>(new httpserver::string_response(req.get_user() + " " + req.get_pass(), 200, "text/plain"));
}
};

int main(int argc, char** argv) {
webserver ws = create_webserver(8080);
int main() {
httpserver::webserver ws = httpserver::create_webserver(8080);

user_pass_resource hwr;
ws.register_resource("/hello", &hwr);
Expand Down
54 changes: 36 additions & 18 deletions examples/benchmark_nodelay.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
/*
This file is part of libhttpserver
Copyright (C) 2011, 2012, 2013, 2014, 2015 Sebastiano Merlino

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*/

#include <cstdlib>
#include <memory>

Expand All @@ -6,31 +26,29 @@
#define PATH "/plaintext"
#define BODY "Hello, World!"

using namespace httpserver;

class hello_world_resource : public http_resource {
public:
hello_world_resource(const std::shared_ptr<http_response>& resp):
resp(resp)
{
}
class hello_world_resource : public httpserver::http_resource {
public:
explicit hello_world_resource(const std::shared_ptr<httpserver::http_response>& resp):
resp(resp) {
}

const std::shared_ptr<http_response> render(const http_request&) {
return resp;
}
const std::shared_ptr<httpserver::http_response> render(const httpserver::http_request&) {
return resp;
}

private:
std::shared_ptr<http_response> resp;
private:
std::shared_ptr<httpserver::http_response> resp;
};

int main(int argc, char** argv)
{
webserver ws = create_webserver(atoi(argv[1]))
.start_method(http::http_utils::INTERNAL_SELECT)
int main(int argc, char** argv) {
std::ignore = argc;

httpserver::webserver ws = httpserver::create_webserver(atoi(argv[1]))
.start_method(httpserver::http::http_utils::INTERNAL_SELECT)
.tcp_nodelay()
.max_threads(atoi(argv[2]));

std::shared_ptr<http_response> hello = std::shared_ptr<http_response>(new string_response(BODY, 200));
std::shared_ptr<httpserver::http_response> hello = std::shared_ptr<httpserver::http_response>(new httpserver::string_response(BODY, 200));
hello->with_header("Server", "libhttpserver");

hello_world_resource hwr(hello);
Expand Down
54 changes: 36 additions & 18 deletions examples/benchmark_select.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
/*
This file is part of libhttpserver
Copyright (C) 2011, 2012, 2013, 2014, 2015 Sebastiano Merlino

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*/

#include <cstdlib>
#include <memory>

Expand All @@ -6,30 +26,28 @@
#define PATH "/plaintext"
#define BODY "Hello, World!"

using namespace httpserver;

class hello_world_resource : public http_resource {
public:
hello_world_resource(const std::shared_ptr<http_response>& resp):
resp(resp)
{
}
class hello_world_resource : public httpserver::http_resource {
public:
explicit hello_world_resource(const std::shared_ptr<httpserver::http_response>& resp):
resp(resp) {
}

const std::shared_ptr<http_response> render(const http_request&) {
return resp;
}
const std::shared_ptr<httpserver::http_response> render(const httpserver::http_request&) {
return resp;
}

private:
std::shared_ptr<http_response> resp;
private:
std::shared_ptr<httpserver::http_response> resp;
};

int main(int argc, char** argv)
{
webserver ws = create_webserver(atoi(argv[1]))
.start_method(http::http_utils::INTERNAL_SELECT)
int main(int argc, char** argv) {
std::ignore = argc;

httpserver::webserver ws = httpserver::create_webserver(atoi(argv[1]))
.start_method(httpserver::http::http_utils::INTERNAL_SELECT)
.max_threads(atoi(argv[2]));

std::shared_ptr<http_response> hello = std::shared_ptr<http_response>(new string_response(BODY, 200));
std::shared_ptr<httpserver::http_response> hello = std::shared_ptr<httpserver::http_response>(new httpserver::string_response(BODY, 200));
hello->with_header("Server", "libhttpserver");

hello_world_resource hwr(hello);
Expand Down
54 changes: 36 additions & 18 deletions examples/benchmark_threads.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
/*
This file is part of libhttpserver
Copyright (C) 2011, 2012, 2013, 2014, 2015 Sebastiano Merlino

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*/

#include <cstdlib>
#include <memory>

Expand All @@ -6,29 +26,27 @@
#define PATH "/plaintext"
#define BODY "Hello, World!"

using namespace httpserver;

class hello_world_resource : public http_resource {
public:
hello_world_resource(const std::shared_ptr<http_response>& resp):
resp(resp)
{
}
class hello_world_resource : public httpserver::http_resource {
public:
explicit hello_world_resource(const std::shared_ptr<httpserver::http_response>& resp):
resp(resp) {
}

const std::shared_ptr<http_response> render(const http_request&) {
return resp;
}
const std::shared_ptr<httpserver::http_response> render(const httpserver::http_request&) {
return resp;
}

private:
std::shared_ptr<http_response> resp;
private:
std::shared_ptr<httpserver::http_response> resp;
};

int main(int argc, char** argv)
{
webserver ws = create_webserver(atoi(argv[1]))
.start_method(http::http_utils::THREAD_PER_CONNECTION);
int main(int argc, char** argv) {
std::ignore = argc;

httpserver::webserver ws = httpserver::create_webserver(atoi(argv[1]))
.start_method(httpserver::http::http_utils::THREAD_PER_CONNECTION);

std::shared_ptr<http_response> hello = std::shared_ptr<http_response>(new string_response(BODY, 200));
std::shared_ptr<httpserver::http_response> hello = std::shared_ptr<httpserver::http_response>(new httpserver::string_response(BODY, 200));
hello->with_header("Server", "libhttpserver");

hello_world_resource hwr(hello);
Expand Down
16 changes: 7 additions & 9 deletions examples/custom_access_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,19 @@

#include <httpserver.hpp>

using namespace httpserver;

void custom_access_log(const std::string& url) {
std::cout << "ACCESSING: " << url << std::endl;
}

class hello_world_resource : public http_resource {
public:
const std::shared_ptr<http_response> render(const http_request&) {
return std::shared_ptr<http_response>(new string_response("Hello, World!"));
}
class hello_world_resource : public httpserver::http_resource {
public:
const std::shared_ptr<httpserver::http_response> render(const httpserver::http_request&) {
return std::shared_ptr<httpserver::http_response>(new httpserver::string_response("Hello, World!"));
}
};

int main(int argc, char** argv) {
webserver ws = create_webserver(8080)
int main() {
httpserver::webserver ws = httpserver::create_webserver(8080)
.log_access(custom_access_log);

hello_world_resource hwr;
Expand Down
Loading