Erlang 当使用Yaws_api特定代码时,Yaws“进程死亡”
我有一个小型yaws appmod测试:Erlang 当使用Yaws_api特定代码时,Yaws“进程死亡”,erlang,yaws,Erlang,Yaws,我有一个小型yaws appmod测试: -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)]}. 当yaws_api:parse_查询函数运行时,我从yaws交互模式
-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)]}.
当yaws_api:parse_查询函数运行时,我从yaws交互模式获得以下错误报告:
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}]}]}
appmod在配置中设置为:
<server localhost>
port = 8080
listen = 127.0.0.1
#docroot = /usr/share/yaws
docroot = /usr/lib/yaws/www
appmods = </,webservice>
# dir_listings = true
</server>
虽然没有显示,但您尝试访问的URL似乎有一个查询字符串,其中至少有一个名为i的变量,类似于:
http://example.com/foo?i=10
out(Arg) ->
{html, yaws_api:f("~p", [http(parse_query,Arg)])}.
对于该URL,yaws_api:parse_query/1将返回[{i,10}],然后您尝试使用{HTML,iolist}构造将其作为HTML返回给yaws。不幸的是,[{i,10}]不是iolist、string或binary,因此Yaws失败
您可以通过使用yaws_api:f/2调用将[{i,10}]转换为字符串来修复此问题,如下所示:
http://example.com/foo?i=10
out(Arg) ->
{html, yaws_api:f("~p", [http(parse_query,Arg)])}.
或者使用标准io_lib:format/2调用:
yaws_api:f/2函数只是io_lib:format/2的包装器