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
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,12 @@ script:
qemu-arm -L /usr/arm-linux-gnueabi/ ./.libs/http_utils ;
qemu-arm -L /usr/arm-linux-gnueabi/ ./.libs/threaded ;
fi
else
make check ;
cat test/test-suite.log ;
ls -l /usr/local/lib/ ;
ls -l /usr/lib/ ;
if [ "$TRAVIS_OS_NAME" = "linux" ]; then cd ../src/; cppcheck --error-exitcode=1 .; cd ../build; fi
fi
- make check
- cat test/test-suite.log
- ls -l /usr/local/lib/
- ls -l /usr/lib/
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then cd ../src/; cppcheck --error-exitcode=1 .; cd ../build; fi
after_success:
- if [ "$DEBUG" = "debug" ] && [ "$COVERAGE" = "coverage" ] && [ "$TRAVIS_OS_NAME" = "linux" ]; then bash <(curl -s https://codecov.io/bash); fi
matrix:
Expand Down
10 changes: 10 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ else
AM_CFLAGS="$AM_CXXFLAGS -O3"
fi

case $host_os in
darwin* )
AM_CXXFLAGS="$AM_CXXFLAGS -DDARWIN"
AM_CFLAGS="$AM_CFLAGS -DDARWIN"
;;
esac

AC_MSG_CHECKING([whether to build with coverage information])
AC_ARG_ENABLE([coverage],
[AS_HELP_STRING([--enable-coverage],
Expand Down Expand Up @@ -325,6 +332,9 @@ AC_CONFIG_LINKS([test/test_content:test/test_content])
AC_CONFIG_LINKS([test/cert.pem:test/cert.pem])
AC_CONFIG_LINKS([test/key.pem:test/key.pem])
AC_CONFIG_LINKS([test/test_root_ca.pem:test/test_root_ca.pem])
AC_CONFIG_LINKS([examples/cert.pem:examples/cert.pem])
AC_CONFIG_LINKS([examples/key.pem:examples/key.pem])
AC_CONFIG_LINKS([examples/test_content:examples/test_content])

AC_OUTPUT(
libhttpserver.pc
Expand Down
14 changes: 13 additions & 1 deletion examples/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,21 @@
LDADD = $(top_builddir)/src/libhttpserver.la
AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/httpserver/
METASOURCES = AUTO
noinst_PROGRAMS = hello_world service minimal_hello_world custom_error
noinst_PROGRAMS = hello_world service minimal_hello_world custom_error allowing_disallowing_methods handlers hello_with_get_arg setting_headers custom_access_log basic_authentication digest_authentication minimal_https minimal_file_response minimal_deferred url_registration minimal_ip_ban

hello_world_SOURCES = hello_world.cpp
service_SOURCES = service.cpp
minimal_hello_world_SOURCES = minimal_hello_world.cpp
custom_error_SOURCES = custom_error.cpp
allowing_disallowing_methods_SOURCES = allowing_disallowing_methods.cpp
handlers_SOURCES = handlers.cpp
hello_with_get_arg_SOURCES = hello_with_get_arg.cpp
setting_headers_SOURCES = setting_headers.cpp
custom_access_log_SOURCES = custom_access_log.cpp
basic_authentication_SOURCES = basic_authentication.cpp
digest_authentication_SOURCES = digest_authentication.cpp
minimal_https_SOURCES = minimal_https.cpp
minimal_file_response_SOURCES = minimal_file_response.cpp
minimal_deferred_SOURCES = minimal_deferred.cpp
url_registration_SOURCES = url_registration.cpp
minimal_ip_ban_SOURCES = minimal_ip_ban.cpp
42 changes: 42 additions & 0 deletions examples/allowing_disallowing_methods.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
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 <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!"));
}
};

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

hello_world_resource hwr;
hwr.disallow_all();
hwr.set_allowing("GET", true);
ws.register_resource("/hello", &hwr);
ws.start(true);

return 0;
}
46 changes: 46 additions & 0 deletions examples/basic_authentication.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
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 <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"));
}
};

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

user_pass_resource hwr;
ws.register_resource("/hello", &hwr);
ws.start(true);

return 0;
}
46 changes: 46 additions & 0 deletions examples/custom_access_log.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
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 <httpserver.hpp>
#include <iostream>

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!"));
}
};

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

hello_world_resource hwr;
ws.register_resource("/hello", &hwr);
ws.start(true);

return 0;
}
51 changes: 51 additions & 0 deletions examples/digest_authentication.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
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 <httpserver.hpp>

#define MY_OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4"

using namespace httpserver;

class digest_resource : public httpserver::http_resource {
public:
const std::shared_ptr<http_response> render_GET(const http_request& req) {
if (req.get_digested_user() == "") {
return std::shared_ptr<digest_auth_fail_response>(new digest_auth_fail_response("FAIL", "test@example.com", MY_OPAQUE, true));
}
else {
bool reload_nonce = false;
if(!req.check_digest_auth("test@example.com", "mypass", 300, reload_nonce)) {
return std::shared_ptr<digest_auth_fail_response>(new digest_auth_fail_response("FAIL", "test@example.com", MY_OPAQUE, reload_nonce));
}
}
return std::shared_ptr<string_response>(new string_response("SUCCESS", 200, "text/plain"));
}
};

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

digest_resource hwr;
ws.register_resource("/hello", &hwr);
ws.start(true);

return 0;
}
45 changes: 45 additions & 0 deletions examples/handlers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
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 <httpserver.hpp>

using namespace httpserver;

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

const std::shared_ptr<http_response> render(const http_request&) {
return std::shared_ptr<http_response>(new string_response("OTHER: Hello, World!"));
}
};

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

hello_world_resource hwr;
ws.register_resource("/hello", &hwr);
ws.start(true);

return 0;
}

40 changes: 40 additions & 0 deletions examples/hello_with_get_arg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
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 <httpserver.hpp>

using namespace httpserver;

class hello_world_resource : public http_resource {
public:
const std::shared_ptr<http_response> render(const http_request& req) {
return std::shared_ptr<http_response>(new string_response("Hello: " + req.get_arg("name")));
}
};

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

hello_world_resource hwr;
ws.register_resource("/hello", &hwr);
ws.start(true);

return 0;
}
55 changes: 55 additions & 0 deletions examples/minimal_deferred.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
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 <httpserver.hpp>

using namespace httpserver;

static int counter = 0;

ssize_t test_callback (char* buf, size_t max) {
if (counter == 2) {
return -1;
}
else {
memset(buf, 0, max);
strcat(buf, " test ");
counter++;
return std::string(buf).size();
}
}

class deferred_resource : public http_resource {
public:
const std::shared_ptr<http_response> render_GET(const http_request& req) {
return std::shared_ptr<deferred_response>(new deferred_response(test_callback, "cycle callback response"));
}
};

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

deferred_resource hwr;
ws.register_resource("/hello", &hwr);
ws.start(true);

return 0;
}

Loading