Skip to content
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

Why :malformed? check before :known-content-type? #260

Open
vspinu opened this issue Jun 21, 2016 · 1 comment
Open

Why :malformed? check before :known-content-type? #260

vspinu opened this issue Jun 21, 2016 · 1 comment

Comments

@vspinu
Copy link

vspinu commented Jun 21, 2016

I am going through liberator put-all-together example and I am puzzled as of why json parsing occurs so early in the decision tree (:malformed? node). The content header is checked in the later stage (:known-content-type?). So, if content is not json, I am parsing it for nothing.

It looks to me that either malfromed? should occur later in the decision tree, or the tutorial's json parsing should occur in processable? node.

@ordnungswidrig
Copy link
Member

You've found an issue. As stated in the documentation :malformed? is for HTTP protocol level errors when parsing the request. One can argue whether invalid data in the request entity ("body") counts as an malformed request or not. In general I would advise to use :processable? for this but unfortunately the status code 422 "not-processable" is not part of the HTTP spec but defined in a WebDAV extension.

IIRC the tutorial was written at a time when :processable? did not yet exist in liberator. In any case the :malformed? function must take the request content-type into account before trying to parse it as JSON.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants