case dispatch(Env, AppWebModule) of{ok, Status, ContentType, H, Content} ->Req:respond({Status, [{"Content-Type", ContentType}|Headers], Content});{redirect, Url} ->Req:respond({302,[{"Location", Url},{"Content-Type", "text/html; charset=UTF-8"}],""});{static, File} ->Req:serve_file(StaticFile, "path/to/file/dir")endThis is, in part, trivially converted to ewgi.case dispatch(C) of {ok, Status, ContentType, Headers, Content} -> {ewgi_context, Request, {ewgi_response, {Status, "OK"}, [{"content-type", ContentType} | Headers], Content, undefined}}; {redirect, Url} -> {ewgi_context, Request, {ewgi_response, {302, "Temporary redirect"}, [{"Location", Url}, {"Content-Type", "text/html; charset=UTF-8"}], "", undefined}}; {static, File} -> ??????????????????????????? end.What do I do with files? :)One answer is to get rid of {static, File} and let the webserver handle static content before it ever gets to the innards. However, there are cases when this may leak down to middleware or the framework (say, we cache output in static files).
In this case calls mochiweb's
Req:respond({Code, Headers, chunked})
and then invokes your allable to write chunks of the file.
The callable is written in a continuation passing style.
It returns a tuple {DataRead, callable}. When all the data is read the
callable must return an empty tuple {}
Take a look in ewgi_mochiweb.erl:
handle_result1 and handle_stream_result
cheers,
filippo
The "stream" that you return is element 4 of the response tuple. It
also should conform to the stream format in the specification:
So, something like this:
fun() -> {<<"binary chunk 1">>, fun() -> {<<"binary chunk2">>, fun()
-> {} end} end} end.
You would produce it with your above example as in this gist:
http://gist.github.com/148423
Best,
Hunter
Also, please note that my examples are very "raw" in that they
directly manipulate the ewgi tuples. It's obviously best to use a
layer of abstraction to manipulate them (as in the ewgi_api module for
example).