An example of yaws gateway might look like this (not working code, just
a sketch of the interface :-) ):

-module(yawsgw, [Appl]).

-export([out/1]).
-export([setup_environ/1,
         start_response/2,
         run/1,
         write/1,
         end_response/0
        ]).

%% this is neded to run as a yaws appmod
out(Arg) ->
    run(Arg).

run(Arg) ->
    Env = setup_environ(Arg),
    Result = Appl:handle_req(Env, fun start_response/2),
    write(Result).

setup_environ(YawsArg) ->
    %% parse yaws arg and transform
    YawsArg.

start_response(["200"|_Rest], Headers) ->
    Headers;
start_response(Status, Headers) ->
    [{status, Status}, Headers].

write(Result) ->
    Result.

end_response() ->
    void.

Then the erlyweb adaptor would be something like:
handle_req(Env, StartResp) ->
    StartResp(out(Env, app_name(Env), req_str(Env)

out(A, AppName, ReqStr) -> Response.

IMHO Env should be a proplist containing all the http request data (e.g.
host name, query string, method, etc...) then we could add a list of
server specific values (e.g. the opaque for yaws) and group them inside Env.

In defining the interface above I followed the python wsgi api. I don't
know if this is general enough and if it fits well in erlang. I'll try
to write some hello world examples with yaws and mochiweb in the weekend.

Yariv Sadan wrote:
> I think that to generalize the interface between ErlyWeb and the web
> server(s) it runs on, the connector should define the following
> function:
> 
> out(A, AppName, RequestStr) -> Response.
> 
> A is an opaque record that encapsulates the request. ErlyWeb will just
> pass it down to the controller functions without inspecting or
> changing it. I'm not sure what information MochiWeb passes to the
> application handler and to what degree it overlaps with the Yaws arg,
> but ideally this request record should contain the same fields
> regardless of which web server you're using.
> 
> AppName is the application's name, as a string (this corresponds to
> the opaque field currently defined in the Yaws server settings).
> ErlyWeb will use it to derive the app metadata module name, i.e.
> [AppName]_erlyweb_data. (Alternatively, this can be the derived atom
> instead of the appname string. This would "leak" some ErlyWeb
> internals to the connector, but would be slightly more efficient than
> passing a string because ErlyWeb wouldn't have to call
> list_to_atom().)
> 
> RequestStr is the equivalent of the appmoddata field that's currently
> part of the Yaws arg. For example, if the appmod base is "/" and the
> browser requests "http://myapp.com/foo/bar/baz";, this would be
> "/foo/bar/baz". As a special case, if the browser requests
> "http://myapp.com";, this would be "/". ErlyWeb uses this value to
> derive the controller/function/parameters for the request.
> 
> Response is currently any appmod response value that Yaws accepts. I'm
> not sure if all of these values can be generalized to MochiWeb and
> other servers. However, if the connector could translate these values
> for all servers, this would allow seamlessly porting existing
> applications between servers without any work.
> 
> Yariv
> 
> 
> On Nov 12, 2007 1:09 PM, Filippo Pacini <[EMAIL PROTECTED]> wrote:
>> I've only used yaws for now and gave a quick look to mochiweb and
>> iserve, but I'd like to test one of the two sooner or later.
>>
>> For the interface following python's wsgi implementation we can think at
>> it as having two sides: the "server" or "gateway" side and the
>> "framework" one.
>> The framework side is a module providing a fun (e.g. handle_req)
>> accepting an environment record (basically a wrapper around the http
>> request and containing also data specific for the framework) and a
>> callback from the "gateway" side to send the response to the server.
>> The server/gateway for every http request it translates the request data
>> from the server format to the environment format and invokes the
>> application fun.
>>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"erlyweb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to