I have a small yaws appmod test:
-module(webservice).
-include("../include/yaws_api.hrl").
-compile(export_all).
http(parse_query,Arg) ->
yaws_api:parse_query(Arg);
out(Arg) ->
{html, [http(parse_query,Arg)]}.
When the yaws_api:parse_query function is ran I get the following ERROR REPORT from the yaws interactive mode:
Yaws process died: {function_clause,
[{yaws_server,binary_size,
[0,{"i",undefined}],
[{file,"yaws_server.erl"},{line,3015}]},
{yaws_server,binary_size,2,
[{file,"yaws_server.erl"},{line,3018}]},
{yaws_server,binary_size,2,
[{file,"yaws_server.erl"},{line,3018}]},
{yaws_server,deflate_accumulated,4,
[{file,"yaws_server.erl"},{line,3712}]},
{yaws_server,deliver_accumulated,4,
[{file,"yaws_server.erl"},{line,3666}]},
{yaws_server,finish_up_dyn_file,2,
[{file,"yaws_server.erl"},{line,2745}]},
{yaws_server,aloop,4,
[{file,"yaws_server.erl"},{line,1175}]},
{yaws_server,acceptor0,2,
[{file,"yaws_server.erl"},{line,1016}]}]}
The appmod is setup in config with:
<server localhost>
port = 8080
listen = 127.0.0.1
#docroot = /usr/share/yaws
docroot = /usr/lib/yaws/www
appmods = </,webservice>
# dir_listings = true
</server>
Though you don't show it, it looks like the URL you're trying to access has a query string with at least one variable named i
, something like this:
http://example.com/foo?i=10
For that URL, yaws_api:parse_query/1
will return [{"i","10"}]
, which you're then trying to return to Yaws as HTML using the {html, iolist()}
construct. Unfortunately, [{"i","10"}]
is not an iolist, string, or binary, so Yaws fails.
You can fix this by converting [{"i","10"}]
to a string using the yaws_api:f/2
call, like this:
out(Arg) ->
{html, yaws_api:f("~p", [http(parse_query,Arg)])}.
or using the standard io_lib:format/2
call:
out(Arg) ->
{html, io_lib:format("~p", [http(parse_query,Arg)])}.
The yaws_api:f/2
function is just a wrapper around io_lib:format/2
.