Skip to content

Instantly share code, notes, and snippets.

@filippo
Created July 16, 2009 13:04
Show Gist options
  • Save filippo/148396 to your computer and use it in GitHub Desktop.
Save filippo/148396 to your computer and use it in GitHub Desktop.
ewgi middleware example
loop(Req, DocRoot) ->
Mod = ewgi_mochiweb:new(fun ?MODULE:simple_stack/1),
Mod:run(Req).
simple_stack(Ctx) ->
to_upper(hello_app(Ctx)).
hello_app({ewgi_context, Request, _Response}) ->
ResponseHeaders = [{"Content-type", "text/plain"}],
Response = {ewgi_response, {200, "OK"}, ResponseHeaders,
[<<"Hello world!">>], undefined},
{ewgi_context, Request, Response}.
to_upper({ewgi_context, Request, Response}=Ctx) ->
Body = ewgi_api:response_message_body(Ctx),
Body1 = [string:to_upper(erlang:binary_to_list(B)) || B <- Body],
ewgi_api:response_message_body(Body1, Ctx).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment