[Cowboy Erlang]:使用提供的Cowboy示例web_服务器将pin指向localhost:8080时出错

[Cowboy Erlang]:使用提供的Cowboy示例web_服务器将pin指向localhost:8080时出错,erlang,connection,webserver,localhost,cowboy,Erlang,Connection,Webserver,Localhost,Cowboy,我正在尝试github存储库提供的牛仔示例: 我使用erlang.mk成功构建了发行版,并运行以下命令,该命令将在我的linux终端中打开erlang shell: $ ./_rel/web_server_example/bin/web_server_example console 但是当我打开http://localhost:8080在我的web浏览器中,我收到以下错误报告: =错误报告===2014年11月26日::14:33:48===节点“web\u服务器”上的处理中出错_examp

我正在尝试github存储库提供的牛仔示例:

我使用erlang.mk成功构建了发行版,并运行以下命令,该命令将在我的linux终端中打开erlang shell:

$ ./_rel/web_server_example/bin/web_server_example console
但是当我打开
http://localhost:8080
在我的web浏览器中,我收到以下错误报告:

=错误报告===2014年11月26日::14:33:48===节点“web\u服务器”上的处理中出错_example@127.0.0.1'具有退出值: {function_子句,[{cowboy_req,sure_response,[{ok,{http_req,{Port,ranch_tcp,keepalive,,'http/1.1',{{127,0,0,1},57150},未定义,8080,,未定义,未定义,{,},{,},{,},{,},{,},{,},},{,},},{,},},{,},},未定义,[],未定义,[],未定义,[],等待,{,},未定义

=错误报告===2014年11月26日::14:33:48===Ranch listener http已使用cowboy_协议启动连接进程:开始链接/4 有理由退出: 3.功能方面:1.功能方面:1.功能方面:1.条款,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,下一个请求,3[{file,“src/cowboy_protocol.erl”},{line,454}]}

这是第454行附近的“src/cowboy_protocol.erl”:

-spec next_request(cowboy_req:req(), #state{}, any()) -> ok.
next_request(Req, State=#state{req_keepalive=Keepalive, timeout=Timeout},
        HandlerRes) ->
    cowboy_req:ensure_response(Req, 204),
    %% If we are going to close the connection,
    %% we do not want to attempt to skip the body.
    case cowboy_req:get(connection, Req) of
        close ->
            terminate(State);
        _ ->
            %% Skip the body if it is reasonably sized. Close otherwise.
            Buffer = case cowboy_req:body(Req) of
                {ok, _, Req2} -> cowboy_req:get(buffer, Req2);
                _ -> close
            end,
            %% Flush the resp_sent message before moving on.
            if HandlerRes =:= ok, Buffer =/= close ->
                    receive {cowboy_req, resp_sent} -> ok after 0 -> ok end,
                    ?MODULE:parse_request(Buffer,
                        State#state{req_keepalive=Keepalive + 1,
                        until=until(Timeout)}, 0);
                true ->
                    terminate(State)
            end
    end.
以及webb_server_app.erl文件:

%% Feel free to use, reuse and abuse the code in this file.

%% @private
-module(web_server_app).
-behaviour(application).

%% API.
-export([start/2]).
-export([stop/1]).

%% API.

start(_Type, _Args) ->
    Dispatch = cowboy_router:compile([
        {'_', [
            {"/[...]", cowboy_static, {priv_dir, web_server, "", [
                {mimetypes, cow_mimetypes, all},
                {dir_handler, directory_handler}
            ]}}
        ]}
    ]),
    {ok, _} = cowboy:start_http(http, 100, [{port, 8080}], [
        {env, [{dispatch, Dispatch}]},
        {middlewares, [cowboy_router, directory_lister, cowboy_handler]}
    ]),
    web_server_sup:start_link().

stop(_State) ->
    ok.
有没有人对到底是什么导致了这个问题,以及如何解决这个问题有什么建议?谢谢

编辑:

我可以确认故障发生在我的Erlang OTP版本R16B02中。更改为最新的Erlang版本(17.3),并解决配置阶段出现的缺少文件依赖关系(使用以下链接中的解决方案):


解决了问题。web_服务器示例现在运行时没有错误。

错误是
函数子句
,因此
cowboy_req:sure_response/2
的参数肯定是错误的。事实上,它们是错误的,因为第一个参数是
{ok,Request}
而不是
Request
。您必须追溯到调用
next\u Request/3
的函数的参数不正确,因为它显然应该在没有
ok
的情况下调用

也许在最后的某个地方,你会发现:

Req = some_function(...)
您需要将其更改为:

{ok, Req} = some_function(...)
祝你好运,猎虫快乐:D


更新:我刚刚克隆了repo,它对我来说很好。我得到了目录列表,所以它不是cowboy中的bug,而是用户代码中的某个地方。

我正在寻找这个bug,不过我是个新手。所以你是说错误在web_服务器示例本身,或者你能让端口8080上的本地主机实际显示出来吗priv文件夹中有什么?我可以显示文件夹中的内容。看起来,您确实更改了示例中的某些内容。请再次尝试克隆存储库并使用Erlang 17。这可能会有所帮助。好的,我可以确认我的情况下,故障出在Erlang OTP版本R16B02中。更改为最新的Erlang版本(17.3),以及使用以下链接中的解决方案解决配置过程中出现的其他问题:解决了问题。web_服务器示例现在可以正常工作,谢谢:)