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
fix benchmark and custom access examples
  • Loading branch information
etr committed Mar 4, 2021
commit 57c88bb8d6c6c2f682420fe55b8d0b713bb0264a
2 changes: 1 addition & 1 deletion CPPLINT.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
linelength=200
headers=hpp
extensions=cpp,hpp
filter=-test/littletest.hpp
filter=-test/littletest.hpp,-build/c++11
52 changes: 34 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,25 @@
#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) {
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
14 changes: 6 additions & 8 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)
httpserver::webserver ws = httpserver::create_webserver(8080)
.log_access(custom_access_log);

hello_world_resource hwr;
Expand Down