|
| 1 | +/* |
| 2 | + This file is part of libhttpserver |
| 3 | + Copyright (C) 2011, 2012, 2013, 2014, 2015 Sebastiano Merlino |
| 4 | +
|
| 5 | + This library is free software; you can redistribute it and/or |
| 6 | + modify it under the terms of the GNU Lesser General Public |
| 7 | + License as published by the Free Software Foundation; either |
| 8 | + version 2.1 of the License, or (at your option) any later version. |
| 9 | +
|
| 10 | + This library is distributed in the hope that it will be useful, |
| 11 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | + Lesser General Public License for more details. |
| 14 | +
|
| 15 | + You should have received a copy of the GNU Lesser General Public |
| 16 | + License along with this library; if not, write to the Free Software |
| 17 | + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 18 | + USA |
| 19 | +*/ |
| 20 | + |
| 21 | +#include <httpserver.hpp> |
| 22 | + |
| 23 | +using namespace httpserver; |
| 24 | + |
| 25 | +class user_pass_resource : public httpserver::http_resource |
| 26 | +{ |
| 27 | + public: |
| 28 | + const std::shared_ptr<http_response> render_GET(const http_request& req) |
| 29 | + { |
| 30 | + if (req.get_user() != "myuser" || req.get_pass() != "mypass") |
| 31 | + { |
| 32 | + return std::shared_ptr<basic_auth_fail_response>(new basic_auth_fail_response("FAIL", "test@example.com")); |
| 33 | + } |
| 34 | + return std::shared_ptr<string_response>(new string_response(req.get_user() + " " + req.get_pass(), 200, "text/plain")); |
| 35 | + } |
| 36 | +}; |
| 37 | + |
| 38 | +int main(int argc, char** argv) { |
| 39 | + webserver ws = create_webserver(8080); |
| 40 | + |
| 41 | + user_pass_resource hwr; |
| 42 | + ws.register_resource("/hello", &hwr); |
| 43 | + ws.start(true); |
| 44 | + |
| 45 | + return 0; |
| 46 | +} |
0 commit comments