Erlang/OTP Forums

Author Message

<  Erlang questions mailing list  ~  Using mod_esi:deliver() ?

Guest
Posted: Mon Apr 07, 2008 10:49 am Reply with quote
Guest
Hi,

I'm trying out the httpd of inets using the Erl Scheme Interface in
R12B. But I don't quite understand how the mod_esi:deliver() mechanism
works. I appear to get no response back from the httpd when using it.

My trivial test module is this:

-module(test01).
-export([start/0, stop/1, test1/2, test2/3]).

start() ->
case application:get_application(inets) of
{ok, inets} ->
ok;
undefined ->
ok = inets:start()
end,
{ok, Pid} = inets:start(httpd, [
{port, 8989},
{server_name,"httpd_test"},
{server_root,"."},
{document_root,"."},
{bind_address, "localhost"},
{modules, [mod_log, mod_esi]},
{log_format, common},
{error_log, "error.log"},
{security_log, "security.log"},
{transfer_log, "transfer.log"},
{erl_script_alias, {"/example", [test01]}},
{erl_script_nocache, true}
]),
Pid.

stop(Pid) ->
ok = inets:stop(httpd, Pid).


test1(Env, Input) ->
io_lib:format("Content-Type:
text/plain\r\n\r\nTEST1\r\n\r\n~p\r\n\r\n~p\r\n", [Env, Input]).

test2(SessionID, Env, Input) ->
mod_esi:deliver(SessionID, "Content-Type: text/plain\r\n\r\n"),
mod_esi:deliver(SessionID,
io_lib:format("TEST2\r\n\r\n~p\r\n\r\n~p\r\n", [Env, Input])).


And http://localhost:8989/example/test01:test1?BlaBla gives me the
anticipated response, but
http://localhost:8989/example/test01:test2?SomethingElse does not
return any response at all. Both GETs are shown in the transfer log,
no errors as far as I can see.

Do I need to deliver some kind of EOF?

Thanks for all pointers,
Robby
_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions
Post recived from mailinglist
Guest
Posted: Mon Apr 07, 2008 12:40 pm Reply with quote
Guest
Found a previous message
http://www.erlang.org/pipermail/erlang-questions/2002-November/006058.html

But even adding a mod_esi:deliver(SessionID, "") at the end, does not
change anything. Still getting no response.

On the off chance, I also added an erl_script_timeout of 1 second,
still same result.

Does anyone have a working example that uses mod_esi:deliver, that I
could study?

Thanks,
Robby

PS This is R12B on Windows and my browser is IE6.
_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions
Post recived from mailinglist
Guest
Posted: Mon Apr 07, 2008 1:27 pm Reply with quote
Guest
On 4/7/08, Kyösti Ranto <kranto@gmail.com> wrote:
> Accoring to the documentation, the second argument of deliver/2 can be
> either of type string() or io_list(). I don't know about the latter
> but you can convert your parameter to string() by calling
> lists:flatten(), i.e.
>
> lists:flatten(io_lib:format(...))

Ha! That did it, mod_esi:deliver() works with flat strings.

Thanks,
Robby
_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions
Post recived from mailinglist
Guest
Posted: Mon Apr 07, 2008 2:59 pm Reply with quote
Guest
I poked around the sources of httpd a bit (R12B). and found
http_transport:send/3 :

%%-------------------------------------------------------------------------
%% send(RequestOrSocketType, Socket, Message) -> ok | {error, Reason}
%% SocketType = ip_comm | {ssl, _}
%% Socket = socket()
%% Message = list() | binary()
%% Description: Sends a packet on a socket, using either gen_tcp or ssl.
%%-------------------------------------------------------------------------
send(ip_comm, Socket, Message) ->
gen_tcp:send(Socket, Message);
send({ssl, _}, Socket, Message) ->
ssl:send(Socket, Message).

There's a small issue here, in that gen_tcp:send/2 takes a [char()] or
binary() as its second argument, whereas ssl:send/2 takes iolist() or
binary().

I think this is what causes iolist() arguments to mod_esi:deliver/2 to
not work under the ip_comm connection type.

Robby
_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions
Post recived from mailinglist
Guest
Posted: Tue Apr 08, 2008 6:57 am Reply with quote
Guest
On 4/7/08, Ky?sti Ranto <kranto@gmail.com> wrote:

> > Accoring to the documentation, the second argument of deliver/2 can be
> > either of type string() or io_list(). I don't know about the latter
> > but you can convert your parameter to string() by calling
> > lists:flatten(), i.e.
> >
> > lists:flatten(io_lib:format(...))
>

> Ha! That did it, mod_esi:deliver() works with flat strings.

No that is not entirely true. The data can be a string() or an io_list() but
if you want to send http-header data it has to be a string. From the documentation:

"Sends data from a Erl Scheme script back to the client. Note
that if any HTTP-header fields should be added by the
script they must be in the first call to deliver/2 and the
data in the call must be a string."

Regards Ingela - OTP team


_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions
Post recived from mailinglist
wuji
Posted: Mon Aug 20, 2012 8:13 am Reply with quote
User Joined: 10 Aug 2012 Posts: 654
on multiple levels," Greene said. "It's extremely hard to get get [h3]jordan 6s[/h3] get rid of. In most companies, if they get infected
it, they throw away the hard drive."If you can't do do [h3]imitation designer *beep*[/h3] do that, follow the instructions. They include backing up your
and reinstalling your operating system.What Do I Do if I I cheap polo ralph lauren I Lose Internet on Monday?The FBI and DCWG recommend contacting
Internet service provider. They'll be able to give you instructions instructions [h3]jordan 6 olympic[/h3] instructions on what to do next.Celebrities Against Plastic Surgery Kate
Says No to Botox and Plastic SurgeryBy LUCHINA FISHER and and knockoff designer *beep* and SHEILA MARIKARJuly 6, 2012— In a world where celebrities
to hold back time with Botox and more, Hollywood stars stars jordan 6 stars who choose to age gracefully make headlines.The latest is
Beckinsale, who says she's put off by all the surgically surgically [h2]jordan 6[/h2] surgically enhanced women around her in Hollywood and would prefer
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum