0

我有一个小的 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_query 函数时,我从 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>
4

1 回答 1

8

尽管您没有显示它,但您尝试访问的 URL 似乎有一个查询字符串,其中至少有一个名为 的变量i,如下所示:

http://example.com/foo?i=10

对于该 URL,yaws_api:parse_query/1将 return [{"i","10"}],然后您尝试使用该{html, iolist()}构造将其作为 HTML 返回到 Yaws。不幸的是,[{"i","10"}]它不是 iolist、字符串或二进制文件,因此 Yaws 失败了。

您可以通过使用调用转换[{"i","10"}]为字符串来解决此问题,如下所示:yaws_api:f/2

out(Arg) ->
    {html, yaws_api:f("~p", [http(parse_query,Arg)])}.

或使用标准io_lib:format/2调用:

out(Arg) ->
    {html, io_lib:format("~p", [http(parse_query,Arg)])}.

yaws_api:f/2函数只是io_lib:format/2.

于 2012-10-28T19:38:08.220 回答