-
Notifications
You must be signed in to change notification settings - Fork 125
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
feat: Return correct status codes for invalid requests #1119
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super; just some (hopefully) simplification suggestions.
config/ldp/modes/default.json
Outdated
@@ -7,7 +7,24 @@ | |||
"@type": "WaterfallHandler", | |||
"handlers": [ | |||
{ "@type": "MethodModesExtractor" }, | |||
{ "@type": "SparqlPatchModesExtractor" } | |||
{ | |||
"@type": "WrappedMethodModesExtractor", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm that took some parsing. Should we really do wrapping here?
I wonder if we can come to a solution with a MethodFilter
or so, which basically is a generic handler that returns canHandle
true only for listed methods.
I initially thought a SequenceHandler
with a MethodFilter
followed by SparqlUpdateModesExtractor
, but then I saw that The canHandle check of this handler will always succeed
(why though? we could at least check the first step?) so fair enough. But still, suggestion below on WrappedMethodModesExtractor
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I recall, SequenceHandler
and ParallelHandler
were specifically made for situations where we had a bunch of handlers that always had to be executed, with SequenceHandler
being used if the order mattered (e.g., middleware first).
I do agree that this change does add a bit of verbosity to the config, but perhaps this is just a result of how it is written here? Maybe it would be clearer if the WrappedMethodModesExtractor
(or its generic alternative) would be defined in a separate block? In that case the main ModesExtractor would be a WaterfallHandler with 3 simple entries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check
* Only allows {@link Operation}s with the specified methods. | ||
* If the method matches the Operation will be sent to the provided extractor. | ||
*/ | ||
export class WrappedMethodModesExtractor extends ModesExtractor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So at the very least, I would turn this into ConditionalOperationHandler
, since there seems to be no need to use the specific ModesExtractor
subclass.
I wonder if we can have a pattern similar to IfNeededConverter
, which can be used both in a wrapped and a chained way (note the default value for the constructor argument).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can definitely make this generic (will also need this for the N3 Patch PR anyway). Personally I'm more of a fan of the wrapped solution instead of the fallthrough solution. I think that was also my opinion for the IfNeededConverter
😄
config/ldp/modes/default.json
Outdated
@@ -7,7 +7,24 @@ | |||
"@type": "WaterfallHandler", | |||
"handlers": [ | |||
{ "@type": "MethodModesExtractor" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe some comments to the extent of "extract permissions based on the method" / "extract permissions based on the request body".
7ddc716
to
e3e3982
Compare
📁 Related issues
Closes #364
✍️ Description
StaticThrowHandler
is an implementation of the class discussed in the related issue. This PR resolves the cases of returning a 405 in case of unsupported HTTP methods and returning a 415 in case of unsupported PATCH formats. There are probably other situations that also should be updated now, but those can have their own issue when they pop up.Major change since a class is renamed (would otherwise be a minor).
Extracting access modes for a PATCH request is now split over 2 classes, one which checks the method and one which checks the body. This allows us to differentiate between 405 and 415. This will probably also be useful once #1060 is added.
The 405 fallback is added both when extracting modes and when calling an operation handler. The 415 fallback is added in modes and in the patcher. In practice, only the modes fallback is relevant, but the other instances are needed in case the server is configured with a different
ModesExtractor
(e.g., a debug extractor that never sets any mode).The example case of #364 of returning a 406 in case conneg is not possible is not solved by this PR since the current implementation of the
ChainedConverter
does not allow for this solution (since itscanHandle
is too permissive for this).