Skip to content

Commit

Permalink
mod_base: add option to controller_template to set the http status co…
Browse files Browse the repository at this point in the history
…de (0.x) (#3094)

* mod_base: add option to controller_template to set the http status code.
* Document http_status option
  • Loading branch information
mworrell committed Aug 25, 2022
1 parent 203e1d9 commit ddb96ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions doc/ref/controllers/controller_template.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ The following options can be given to the dispatch rule:
| |template. This overrules and id from | |
| |the query arguments. | |
+---------------------+--------------------------------------+------------------------+
|http_status |The HTTP status code to return. This |{http_status, 418} |
| |defaults to 200. | |
+---------------------+--------------------------------------+------------------------+


.. include:: acl_options.rst
Expand Down
13 changes: 10 additions & 3 deletions modules/mod_base/controllers/controller_template.erl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
%% @author Marc Worrell <marc@worrell.nl>
%% @copyright 2009-2013 Marc Worrell
%% @copyright 2009-2022 Marc Worrell
%% @doc Generic template controller, serves the template mentioned in the dispatch configuration.

%% Copyright 2009-2013 Marc Worrell
%% Copyright 2009-2022 Marc Worrell
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -74,7 +74,14 @@ provide_content(ReqData, Context) ->
],
Rendered = z_template:render(Template, Vars, Context4),
{Output, OutputContext} = z_context:output(Rendered, Context4),
?WM_REPLY(Output, OutputContext).
case z_context:get(http_status, OutputContext) of
Status when is_integer(Status) ->
{x, RD, ContextReply} = ?WM_REPLY(x, OutputContext),
RD1 = wrq:set_resp_body(Output, RD),
{{halt, Status}, RD1, ContextReply};
_ ->
?WM_REPLY(Output, OutputContext)
end.

set_optional_cache_header(Context) ->
case z_context:get(maxage, Context) of
Expand Down

0 comments on commit ddb96ba

Please sign in to comment.