joeblog
joeblog

Reputation: 1225

Can Erlang's mod_esi redirect?

I'm trying to learn doing web application development in Erlang, just using the standard library's inets modules at this stage.

The snag I've hit is that I want to validate the data from a post query, and then either redirect back to the form page with error messages or to a welcome page.

Basically, what I need to do is get a return header which looks like

HTTP/1.1 303 OK
Location: /form.html
...

While mod_esi:deliver/2 lets me add header key: value fields, I don't see how I can replace the default

HTTP/1.1 200 OK
...

With HTTP/1.1 303 OK to do a redirect.

While I'm sure cowboy, elli, etc can do this easily, before learning a third-party application I was wondering if mod_esi or other inets modules can do this.

What I have is a module called handler which has a function form/3 (adhering to http://erlang.org/doc/man/mod_esi.html#Module:Function-3) which returns http://erlang.org/doc/man/mod_esi.html#deliver-2 as required.

Upvotes: 1

Views: 188

Answers (1)

uhoreg
uhoreg

Reputation: 11

If you include a Location header, mod_esi should automatically set the status to 302. If you want to set the status to something else, you can use the Status header. e.g. Status: 303 See Other. (This is how CGI works too.)

Upvotes: 1

Related Questions