2012-10-28 44 views
0

我有一個小的雅司病appmod測試:雅司病「過程中死亡」的時候yaws_api特定的代碼被用於

-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 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> 

回答

8

雖然你沒有表現出來,它看起來像在U RL你試圖訪問具有查詢字符串名爲i至少一個變量,像這樣:

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

對於URL,yaws_api:parse_query/1將返回[{"i","10"}],其中你再試圖返回雅司病作爲使用{html, iolist()}構造的HTML。不幸的是,[{"i","10"}]不是一個iolist,字符串或二進制文件,所以Yaws失敗。

您可以通過使用yaws_api:f/2電話轉換[{"i","10"}]爲一個字符串,這樣解決這個問題:

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