Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
additional files cleaned
  • Loading branch information
etr committed Mar 4, 2021
commit 3dc042ff550e2cfe09ad5039a756577b6fe52d78
14 changes: 6 additions & 8 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);
httpserver::webserver ws = httpserver::create_webserver(8080);

hello_world_resource hwr;
hwr.disallow_all();
Expand Down
24 changes: 10 additions & 14 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);
httpserver::webserver ws = httpserver::create_webserver(8080);

user_pass_resource hwr;
ws.register_resource("/hello", &hwr);
Expand Down
52 changes: 34 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,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::INTERNAL_SELECT)
int main(int argc, char** argv) {
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
52 changes: 34 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,26 @@
#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) {
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
2 changes: 1 addition & 1 deletion test/unit/http_utils_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ LT_BEGIN_AUTO_TEST(http_utils_suite, unescape_partial_marker)
char* with_marker = (char*) malloc(6 * sizeof(char));
sprintf(with_marker, "%s", "A+B%0");
std::string string_with_marker = with_marker;
int expected_size = http::http_unescape(string_with_marker);
int expected_size = httpserver::http::http_unescape(string_with_marker);

char* expected = (char*) malloc(6 * sizeof(char));
sprintf(expected, "%s", "A B%0");
Expand Down