inhabitedtype / ocaml-webmachine

A REST toolkit for OCaml
Other
221 stars 31 forks source link

PUT fails when content_types_provided is empty #86

Closed xguerin closed 6 years ago

xguerin commented 6 years ago

Hello,

I am trying to write a write only controller that supports only PUT and POST operations. To do so, I define the following:

method content_types_provided rd =
  Wm.continue [ ] rd

method content_types_accepted rd =
  Wm.continue [ "application/json", self#of_json ] rd

Interestingly, this fails to process either PUT of POST operations with the following error:

406 - PUT / - v3b13, v3b12, v3b11, v3b10, v3b9, v3b8, v3b7, v3b6, v3b5, v3b4, v3b3, v3c3, v3c4

However, if I also define "application/json" in content_types_provided, the same request works:

204 - PUT / - v3b13, v3b12, v3b11, v3b10, v3b9, v3b8, v3b7, v3b6, v3b5, v3b4, v3b3, v3c3, v3c4, v3d4, v3e5, v3f6, v3g7, v3g8, v3h10, v3i12, v3l13, v3m16, v3n16, v3o16, v3o14, v3p11, v3o20

It seems that the FSM has been implemented that way, but is that intuitively correct? I mean is it intended for a service to accept a type only if also generates it?

Thanks !

seliopou commented 6 years ago

I believe if you changed the content_types_provided handler to something else besides "application/json", you would see the same behavior. The state machine is trying to generate a response body based on the Accept header of the request. If there is no Accept header present, then it'll just pick the first one in the list of content_types_provided. But if the list of types provided is empty, it'll just fail since it doesn't know how to generate a body.

seliopou commented 6 years ago

I believe this question has been answered. If that's not the case please feel free to continue the discussion.