-
Notifications
You must be signed in to change notification settings - Fork 192
Method not allowed #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Method not allowed #243
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d2de18f
test: Replace depracted CURL macro
LeSpocky a81eb6e
http_resource: Rename private member
LeSpocky 51c85a4
http_resource: Add new public class method 'get_allowed_methods'
LeSpocky dc3c27f
test: Introduce new unit test suite for http_resource
LeSpocky 883b505
test: Add check for 'Allow:' header when returning 405
LeSpocky 538c560
webserver: Send 'Allow:' header along with 405 response
LeSpocky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| This file is part of libhttpserver | ||
| Copyright (C) 2021 Alexander Dahl | ||
|
|
||
| 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 <microhttpd.h> | ||
|
|
||
| #include <algorithm> | ||
| #include <memory> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "httpserver.hpp" | ||
| #include "littletest.hpp" | ||
|
|
||
| using std::shared_ptr; | ||
| using std::sort; | ||
| using std::string; | ||
| using std::vector; | ||
|
|
||
| using httpserver::http_request; | ||
| using httpserver::http_resource; | ||
| using httpserver::http_response; | ||
| using httpserver::string_response; | ||
|
|
||
| class simple_resource : public http_resource { | ||
| public: | ||
| const shared_ptr<http_response> render_GET(const http_request&) { | ||
| return shared_ptr<string_response>(new string_response("OK")); | ||
| } | ||
| }; | ||
|
|
||
| LT_BEGIN_SUITE(http_resource_suite) | ||
| void set_up() { | ||
| } | ||
|
|
||
| void tear_down() { | ||
| } | ||
| LT_END_SUITE(http_resource_suite) | ||
|
|
||
| LT_BEGIN_AUTO_TEST(http_resource_suite, disallow_all_methods) | ||
| simple_resource sr; | ||
| sr.disallow_all(); | ||
| auto allowed_methods = sr.get_allowed_methods(); | ||
| LT_CHECK_EQ(allowed_methods.size(), 0); | ||
| LT_END_AUTO_TEST(disallow_all_methods) | ||
|
|
||
| LT_BEGIN_AUTO_TEST(http_resource_suite, allow_some_methods) | ||
| simple_resource sr; | ||
| sr.disallow_all(); | ||
| sr.set_allowing(MHD_HTTP_METHOD_GET, true); | ||
| sr.set_allowing(MHD_HTTP_METHOD_POST, true); | ||
| auto allowed_methods = sr.get_allowed_methods(); | ||
| LT_CHECK_EQ(allowed_methods.size(), 2); | ||
| // elements in http_resource::method_state are sorted (std::map) | ||
| vector<string> some_methods{MHD_HTTP_METHOD_GET, MHD_HTTP_METHOD_POST}; | ||
| sort(some_methods.begin(), some_methods.end()); | ||
| LT_CHECK_COLLECTIONS_EQ(allowed_methods.cbegin(), allowed_methods.cend(), | ||
| some_methods.cbegin()) | ||
| LT_END_AUTO_TEST(allow_some_methods) | ||
|
|
||
| LT_BEGIN_AUTO_TEST(http_resource_suite, allow_all_methods) | ||
| simple_resource sr; | ||
| sr.allow_all(); | ||
| auto allowed_methods = sr.get_allowed_methods(); | ||
| // elements in http_resource::method_state are sorted (std::map) | ||
| vector<string> all_methods{MHD_HTTP_METHOD_GET, MHD_HTTP_METHOD_POST, | ||
| MHD_HTTP_METHOD_PUT, MHD_HTTP_METHOD_HEAD, MHD_HTTP_METHOD_DELETE, | ||
| MHD_HTTP_METHOD_TRACE, MHD_HTTP_METHOD_CONNECT, | ||
| MHD_HTTP_METHOD_OPTIONS, MHD_HTTP_METHOD_PATCH}; | ||
| sort(all_methods.begin(), all_methods.end()); | ||
| LT_CHECK_COLLECTIONS_EQ(allowed_methods.cbegin(), allowed_methods.cend(), | ||
| all_methods.cbegin()) | ||
| LT_END_AUTO_TEST(allow_all_methods) | ||
|
|
||
| LT_BEGIN_AUTO_TEST_ENV() | ||
| AUTORUN_TESTS() | ||
| LT_END_AUTO_TEST_ENV() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.