liberator icon indicating copy to clipboard operation
liberator copied to clipboard

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

Open vspinu opened this issue 8 years ago • 1 comments

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.

vspinu avatar Jun 21 '16 11:06 vspinu

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.

ordnungswidrig avatar Jun 21 '16 12:06 ordnungswidrig