aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaweł Chmielowski <pchmielowski@process-one.net>2012-04-06 18:55:27 +0200
committerPaweł Chmielowski <pchmielowski@process-one.net>2012-04-11 16:04:05 +0200
commit66b7caafe0039a88d49353d32bede4e06a6ea6e7 (patch)
tree265b905f00422cf0171e905a7da5d661c3fcc5bd /src
parentParse correctly https request split into multiple packets (diff)
Don't use binary:match to extract lines from binaries
This was added in R13B3, lets roll our own implementation to make sure it works on older erlang versions.
Diffstat (limited to 'src')
-rw-r--r--src/web/ejabberd_http.erl16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/web/ejabberd_http.erl b/src/web/ejabberd_http.erl
index 3ffad6ed0..57e3e927b 100644
--- a/src/web/ejabberd_http.erl
+++ b/src/web/ejabberd_http.erl
@@ -1001,12 +1001,22 @@ old_integer_to_hex(I) when I>=16 ->
% The following code is mostly taken from yaws_ssl.erl
+extract_line(_, <<>>, _) ->
+ none;
+extract_line(0, <<"\r", Rest/binary>>, Line) ->
+ extract_line(1, Rest, Line);
+extract_line(0, <<A:8, Rest/binary>>, Line) ->
+ extract_line(0, Rest, <<Line/binary, A>>);
+extract_line(1, <<"\n", Rest/binary>>, Line) ->
+ {Line, Rest};
+extract_line(1, Data, Line) ->
+ extract_line(0, Data, <<Line/binary, "\r">>).
+
decode_packet(_, <<"\r\n", Rest/binary>>) ->
{ok, http_eoh, Rest};
decode_packet(Type, Data) ->
- case binary:match(Data, <<"\r\n">>) of
- {Start, _Len} ->
- <<LineB:Start/binary, _:2/binary, Rest/binary>> = Data,
+ case extract_line(0, Data, <<>>) of
+ {LineB, Rest} ->
Line = binary_to_list(LineB),
Result = case Type of
http ->