1
Mutoo 2014-01-30 15:58:17 +08:00
应该是原文代码没有转义 <- 后面有一部分被吃掉了。
|
2
yakczh OP @Mutoo 怎么样才能把Sec-WebSocket-Key 找出来
HeaderData= <<"Accept-Encoding: gzip, deflate\r\nSec-WebSocket-Key\r\nVpFuKOmlNacJn3CuGOrd9w==">>, HeaderList = binary:split(HeaderData, <<"\r\n">>, [global]), 。。。 {_, SecWebSocketKey} = lists:keyfind(<<"Sec-WebSocket-Key">>, 1, HeaderList1), 中间的代码应该怎么写? |
3
Mutoo 2014-01-30 16:28:14 +08:00
@yakczh
HeaderData= <<"Accept-Encoding: gzip, deflate\r\nSec-WebSocket-Key\r\nVpFuKOmlNacJn3CuGOrd9w==">>, 这行错了吧,应该是 HeaderData= <<"Accept-Encoding: gzip, deflate\r\nSec-WebSocket-Key: VpFuKOmlNacJn3CuGOrd9w==">>, 中间那行是 HeaderList1 = [list_to_tuple(binary:split(Header, <<": ">>)) || Header <- HeaderList] 整段如下 HeaderData= <<"Accept-Encoding: gzip, deflate\r\nSec-WebSocket-Key: VpFuKOmlNacJn3CuGOrd9w==">>, HeaderList = binary:split(HeaderData, <<"\r\n">>, [global]), HeaderList1 = [list_to_tuple(binary:split(Header, <<": ">>)) || Header <- HeaderList], {_, SecWebSocketKey} = lists:keyfind(<<"Sec-WebSocket-Key">>, 1, HeaderList1). 输出结果 > SecWebSocketKey. <<"VpFuKOmlNacJn3CuGOrd9w==">> |
4
yakczh OP @Mutoo 多谢指正,请教一下
[list_to_tuple( func || Header <- HeaderList] 这一行是什么语法 |
6
yakczh OP |
7
Mutoo 2014-01-30 17:03:00 +08:00
@yakczh 显示是有字符被吞了。
这部分的代码可以参考一下下面这个源码,99行附近 https://github.com/shyang/erlang-websockets-demo/blob/master/src/ws_srv.erl |
8
yakczh OP 上面代码50行的地方是 List = [list_to_tuple(binary:split(Line, <<": ">>)) || Line <- Lines, binary:match(Line, <<": ">>) /= nomatch],
我看了一下文档,列表解析的语法是 [Expr(E) || E <- List] 上面代码中 Line <- Lines,后面的 binary:match(Line, <<": ">>) /= nomatch 这句是不是是对子项处理的前提条件? |