Closed ulfsauer0815 closed 9 years ago
I think the better approach would be to make this configurable in the SpockCfg
. Although you can already set a default using the hookAny
hook.
How can I set a default with the hookAny
hook?
It looks like it is only called when no other route matches.
What I want to do is return an empty response (no headers, no body) for routes that do not explicitly set the response body, e.g.
post "foo" $
return ()
Additionally, how can I reset the headers and the response body this way?
is there a way to remove a header?
I still think that the default response should not include an html body and header.
(This will also be the default header for a response created with bytes
if it is not set by the user.)
Being able to configure that with the SpockCfg
would be ideal, but that does not look quite as straight forward to implement as I would like it to be... ;)
Ah, sorry I didn't understand you correctly! Yes, that's not possible yet. We could solve this using posthook
s, analog to the prehook
s. But the question there is: When do they fire? If you set a response, the handling currently terminates.
I think the empty response for routes that do not set anything is correct, but we should make sure that non-matched requests return a 404. That seems the case so I will merge the pull request.
For removing headers we'll need a new function, if you like you can contribute one. It will be a bit "tricky" because you will have to check the multiheader (headers that appear multiple times) and the headers and decide what to delete.
Spock initializes the response state with the error page with status 200 and an empty error message, which results in the following response body:
Especially with REST, empty responses are quite common and with this patch you would not need to specify an explicit response body and reset the content-type header.