|
| 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 | +#define MY_OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4" |
| 24 | + |
| 25 | +using namespace httpserver; |
| 26 | + |
| 27 | +class digest_resource : public httpserver::http_resource { |
| 28 | +public: |
| 29 | + const std::shared_ptr<http_response> render_GET(const http_request& req) { |
| 30 | + if (req.get_digested_user() == "") { |
| 31 | + return std::shared_ptr<digest_auth_fail_response>(new digest_auth_fail_response("FAIL", "test@example.com", MY_OPAQUE, true)); |
| 32 | + } |
| 33 | + else { |
| 34 | + bool reload_nonce = false; |
| 35 | + if(!req.check_digest_auth("test@example.com", "mypass", 300, reload_nonce)) { |
| 36 | + return std::shared_ptr<digest_auth_fail_response>(new digest_auth_fail_response("FAIL", "test@example.com", MY_OPAQUE, reload_nonce)); |
| 37 | + } |
| 38 | + } |
| 39 | + return std::shared_ptr<string_response>(new string_response("SUCCESS", 200, "text/plain")); |
| 40 | + } |
| 41 | +}; |
| 42 | + |
| 43 | +int main(int argc, char** argv) { |
| 44 | + webserver ws = create_webserver(8080); |
| 45 | + |
| 46 | + digest_resource hwr; |
| 47 | + ws.register_resource("/hello", &hwr); |
| 48 | + ws.start(true); |
| 49 | + |
| 50 | + return 0; |
| 51 | +} |
0 commit comments