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

some puzzled about examples code #266

Open
bugeb opened this issue Sep 22, 2016 · 2 comments
Open

some puzzled about examples code #266

bugeb opened this issue Sep 22, 2016 · 2 comments

Comments

@bugeb
Copy link

bugeb commented Sep 22, 2016

The following code from examples collection.clj

(defn check-content-type [ctx content-types]
  (if (#{:put :post} (get-in ctx [:request :request-method]))
    (or 
     (some #{(get-in ctx [:request :headers "content-type"])}
           content-types)
     [false {:message "Unsupported Content-Type"}])
    true))

(defresource list-resource
  :available-media-types ["application/json"]
  :allowed-methods [:get :post]
  :known-content-type? #(check-content-type % ["application/json"])
  ......)

:allowed-methods had checked request method, but check-content-type function once again check request method. there are other purpose?

(defn content-types-check [ctx content-types]
  (if (some #{(get-in ctx [:request :headers "content-type"])} content-types)
    true
    false))
@ordnungswidrig
Copy link
Member

check-content-type check if the request content-type supported. This is only done for the PUT and POST method and defaults to true for GET and the others. A GET request doesn't carry a content-type typically and this would make the known-content-type? decision return false.

@bugeb
Copy link
Author

bugeb commented Sep 22, 2016

Thanks.

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