Skip to content

Method not allowed#243

Merged
etr merged 6 commits intoetr:masterfrom
LeSpocky:method-not-allowed
Nov 12, 2021
Merged

Method not allowed#243
etr merged 6 commits intoetr:masterfrom
LeSpocky:method-not-allowed

Conversation

@LeSpocky
Copy link
Copy Markdown
Contributor

Identify the Bug

#240

Description of the Change

To be able to send along an additional header like Allow: GET, POST with an HTTP 405 (Method Not Allowed) response, the httpserver::http_resource class had to be extended to expose the allowed methods already stored in that object. Those can be used in the webserver then to build the necessary header line and attach it to the response.

Alternate Designs

The proposed version was selected based on discussion in the bug report #240.

Possible Drawbacks

  • public API change (httpserver::http_resource had to be changed)
  • Additional calculation overhead

Verification Process

Tests were added:

  • unit tests for the extension of the class httpserver::http_resource
  • integration tests for webserver to verify header is actually send in case

Release Notes

  • Class http_resource now allows to query the currently set allowed methods
  • Webserver now sends 'Allow:' header along with 405 (Method Not Allowed) responses, to comply with HTTP standard (RFC 7231)

According to CURL source that old macro is long gone, and was replaced.
Real issue is: you don't find the old macro in CURL's documentation
anymore, which makes it harder to understand what libhttpserver is doing
here.

Signed-off-by: Alexander Dahl <ada@thorsis.com>
Preparation for adding an interface to get a list of only allowed
methods aka methods where the boolean property is true.

References: etr#240
Suggested-by: Sebastiano Merlino <sebastiano@hey.com>
Signed-off-by: Alexander Dahl <ada@thorsis.com>
While the class had public methods for setting and testing the currently
allowed HTTP methods, there was no way to discover all at once. A
hypothetic user could have build such a list by calling 'is_allowed()'
on each possible HTTP method, but the http_resource class itself
contains the actual comprehensive list (map) of methods, which would
make that approach error prone.

Such a list is needed however for constructing the HTTP header 'Allow:'
which is mandatory under certain conditions according to RFC.

References: etr#240
Signed-off-by: Alexander Dahl <ada@thorsis.com>
@LeSpocky
Copy link
Copy Markdown
Contributor Author

The other thing cpplint complains about is header ordering, which will be easy to fix.

We want to test the recently introduced new API methods.

References: etr#240
Signed-off-by: Alexander Dahl <ada@thorsis.com>
RFC 7231 states an additional header "Allow:" must be sent along with a
response with code 405 (Method Not Allowed).

References: etr#240
Link: https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.5
Link: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Allow
Signed-off-by: Alexander Dahl <ada@thorsis.com>
@LeSpocky
Copy link
Copy Markdown
Contributor Author

The other thing cpplint complains about is header ordering, which will be easy to fix.

Done that and force pushed a new version. Lets see what CI says now?!

Copy link
Copy Markdown
Owner

@etr etr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It all looks good, only one comment to use the constant defined in http_utils for the "Allow" header.

RFC 7231 states an additional header "Allow:" MUST be sent along with a
response with code 405 (Method Not Allowed).

Fixes: etr#240
Link: https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.5
Link: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Allow
Signed-off-by: Alexander Dahl <ada@thorsis.com>
@etr etr merged commit 6b195cf into etr:master Nov 12, 2021
@LeSpocky LeSpocky deleted the method-not-allowed branch November 13, 2021 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants