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

No handler called on PUT request? #33

Closed
slegrand45 opened this issue Nov 1, 2015 · 3 comments
Closed

No handler called on PUT request? #33

slegrand45 opened this issue Nov 1, 2015 · 3 comments
Labels

Comments

@slegrand45
Copy link
Contributor

I'm not sure if it's the right way to handle PUT request but with the following code neither the to_json method nor the process_post is called with a PUT request:

class id = object(self)
  inherit [Cohttp_lwt_body.t] Wm.resource

  method allowed_methods rd =
    Wm.continue [`GET; `POST; `PUT; `DELETE] rd

  method content_types_provided rd =
    Wm.continue [
      ("application/json", self#to_json);
    ] rd

  method content_types_accepted rd =
    Wm.continue [
      ("application/json", (Wm.continue true));
    ] rd

  method process_post rd =
    print_endline "  process_post method  " ; flush_all () ;
    Wm.continue true

  method private to_json rd =
    print_endline "  to_json method  " ; flush_all () ;
    let json = ... in
    Wm.continue (`String json) rd

end

The states path is: v3b13, v3b12, v3b11, v3b10, v3b9, v3b8, v3b7, v3b6, v3b5, v3b4, v3b3, v3c3, v3c4, v3d4, v3d5, v3e5, v3f6, v3f7, v3g7, v3g8, v3h10, v3i12, v3l13, v3m16, v3n16, v3o16, v3o14, v3p11, v3o20

@seliopou
Copy link
Member

seliopou commented Nov 1, 2015

That path looks correct.process_post should definitely not be called on a PUT. It should call content_types_accepted at v3o14, and then call the appropriate handler, which in your example will do nothing and indicate success. In the accepted handlers, it's up to the user to generate a body if appropriate. Webmachine won't generate a response automatically via content_types_provided.

@seliopou seliopou closed this as completed Nov 1, 2015
@slegrand45
Copy link
Contributor Author

Ah, ok, didn't get it. My bad, sorry.

@seliopou
Copy link
Member

seliopou commented Nov 1, 2015

Not a problem! Happy to see somebody interested in the project.

This behavior confused me a bit when I ported the library as well. The rationale for this behavior, at least for a PUT, is that the representation that was just pushed to the server would be the same one the server would return. For POST, not much is said about its response body in the spec, mostly because it can affect many different resources; the resource that process_post is the resource that handles the request, but that doesn't necessary limit the scope of its effects.

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

No branches or pull requests

2 participants