7
7
-record (ewp_request ,{
8
8
proto ,
9
9
version ,
10
- command ,
11
- compression ,
12
- response_compression ,
13
- has_body = false ,
10
+ envelope_kind ,
14
11
header ,
15
12
body
16
13
}).
17
- % ewp_request:parse("EWP 0.1 PING none none 2 2 H\ntest").
18
- parse_compression (RespCompStr ) ->
19
- parse_compression (RespCompStr ,[]).
20
-
21
- parse_compression (RespCompStr ,Prog ) ->
22
-
23
- Index = string :str (RespCompStr ," ," ),
24
- if
25
- Index < 1 ->
26
- [RespCompStr ];
27
- true ->
28
-
29
- parse_compression (string :substr (RespCompStr ,Index + 1 ),[Prog |string :slice (RespCompStr ,0 ,Index )])
30
- end
31
-
32
- .
33
14
34
15
parse (In ) ->
35
16
Index = str (In ," \n " ),
36
17
RequestLine = string :slice (In ,0 ,Index - 1 ),
37
18
RequestBody = string :substr (In ,Index + 1 ),
38
19
Request = string :tokens (RequestLine ," " ),
39
20
if
40
- length (Request ) < 7 ->
21
+ length (Request ) < 5 ->
41
22
exit (" Not enough items" );
42
23
true ->
43
24
ok
44
25
end ,
45
26
Proto = lists :nth (1 ,Request ),
46
27
Version = lists :nth (2 ,Request ),
47
- Command = lists :nth (3 ,Request ),
48
- Compression = lists :nth (4 ,Request ),
49
- ResponseCompression = parse_compression (lists :nth (5 ,Request )),
50
- HasBody = length (Request ) == 7 ,
51
- Header = string :slice (RequestBody ,0 ,list_to_integer (lists :nth (6 ,Request ))),
28
+ EnvelopeKind = lists :nth (3 ,Request ),
29
+ Header = string :slice (RequestBody ,0 ,list_to_integer (lists :nth (4 ,Request ))),
52
30
if
53
31
length (Request ) == 8 ->
54
32
Body = " " ;
55
33
true ->
56
- Body = string :slice (RequestBody ,list_to_integer (lists :nth (6 ,Request )),list_to_integer (lists :nth (7 ,Request )))
34
+ Body = string :slice (RequestBody ,list_to_integer (lists :nth (4 ,Request )),list_to_integer (lists :nth (5 ,Request )))
57
35
58
36
end ,
59
37
# ewp_request {
60
38
proto = Proto ,
61
39
version = Version ,
62
- command = Command ,
63
- compression = Compression ,
64
- response_compression = ResponseCompression ,
65
- has_body = HasBody ,
40
+ envelope_kind = EnvelopeKind ,
66
41
header = Header ,
67
42
body = Body
68
43
}
@@ -71,30 +46,15 @@ parse(In) ->
71
46
% ewp_request:marshal(ewp_request:parse("EWP 0.1 PING none none 2 2 H\ntest")).
72
47
% ewp_request:marshal(ewp_request:parse("EWP 0.1 PING none none 2 2\ntest")).
73
48
marshal (State )->
74
- if
75
- State # ewp_request .has_body ->
76
- binary_to_list (erlang :iolist_to_binary (io_lib :format (" ~s ~s ~s ~s ~s ~p ~p \n ~s~s " ,[
77
- State # ewp_request .proto ,
78
- State # ewp_request .version ,
79
- State # ewp_request .command ,
80
- State # ewp_request .compression ,
81
- lists :join (" ," ,State # ewp_request .response_compression ),
82
- string :len (State # ewp_request .header ),
83
- string :len (State # ewp_request .body ),
84
- State # ewp_request .header ,
85
- State # ewp_request .body
86
- ])));
87
- true ->
88
- binary_to_list (erlang :iolist_to_binary (io_lib :format (" ~s ~s ~s ~s ~s ~p ~p H\n ~s~s " ,[
89
- State # ewp_request .proto ,
90
- State # ewp_request .version ,
91
- State # ewp_request .command ,
92
- State # ewp_request .compression ,
93
- lists :join (" ," ,State # ewp_request .response_compression ),
94
- string :len (State # ewp_request .header ),
95
- string :len (State # ewp_request .body ),
96
- State # ewp_request .header ,
97
- State # ewp_request .body
98
- ])))
99
- end
49
+
50
+ binary_to_list (erlang :iolist_to_binary (io_lib :format (" ~s ~s ~s ~p ~p \n ~s~s " ,[
51
+ State # ewp_request .proto ,
52
+ State # ewp_request .version ,
53
+ State # ewp_request .envelope_kind ,
54
+ string :len (State # ewp_request .header ),
55
+ string :len (State # ewp_request .body ),
56
+ State # ewp_request .header ,
57
+ State # ewp_request .body
58
+ ])))
59
+
100
60
.
0 commit comments