Skip to content
Browse files

avoid code duplication: use get_line from ts_http_common

  • Loading branch information...
1 parent 47f2240 commit acb70824cd179cbc1baeab6a3d382d90285ca8ec @nniclausse nniclausse committed
Showing with 4 additions and 32 deletions.
  1. +2 −31 src/lib/http_utils.erl
  2. +2 −1 src/tsung/ts_http_common.erl
View
33 src/lib/http_utils.erl
@@ -12,7 +12,7 @@
%% Returns: {ok, #ws_http, Body}
%%--------------------------------------------------------------------
parse_headers(Http, Tail) ->
- case get_line(Tail) of
+ case ts_http_common:get_line(Tail) of
{line, Line, Tail2} ->
parse_headers(parse_line(Line, Http), Tail2);
{lastline, Line, _} ->
@@ -55,6 +55,7 @@ check_headers(Headers, RequiredHeaders) ->
%%--------------------------------------------------------------------
parse_status([A,B,C|_], Http) ->
Status=list_to_integer([A,B,C]),
+ ts_mon:add({ count, Status }),
Http#ws_http{status = Status}.
%%--------------------------------------------------------------------
@@ -79,33 +80,3 @@ parse_line("sec-websocket-accept: " ++ TailLine, Http) ->
Http#ws_http{headers=Headers, accept=TailLine};
parse_line(_Line, Http) ->
Http.
-
-%% code taken from yaws
-is_nb_space(X) ->
- lists:member(X, [$\s, $\t]).
-
-%% ret: {line, Line, Trail} | {lastline, Line, Trail}
-get_line(L) ->
- get_line(L, true, []).
-
-get_line("\r\n\r\n" ++ Tail, _Cap, Cur) ->
- {lastline, lists:reverse(Cur), Tail};
-get_line("\r\n", _, _) ->
- {more};
-get_line("\r\n" ++ Tail, Cap, Cur) ->
- case is_nb_space(hd(Tail)) of
- true -> %% multiline ... continue
- get_line(Tail, Cap,[$\n, $\r | Cur]);
- false ->
- {line, lists:reverse(Cur), Tail}
- end;
-get_line([$:|T], true, Cur) -> % ':' separator
- get_line(T, false, [$:|Cur]);%the rest of the header isn't set to lower char
-get_line([H|T], false, Cur) ->
- get_line(T, false, [H|Cur]);
-get_line([Char|T], true, Cur) when Char >= $A, Char =< $Z ->
- get_line(T, true, [Char + 32|Cur]);
-get_line([H|T], true, Cur) ->
- get_line(T, true, [H|Cur]);
-get_line([], _, _) -> %% Headers are fragmented ... We need more data
- {more}.
View
3 src/tsung/ts_http_common.erl
@@ -42,7 +42,8 @@
http_no_body/2,
parse/2,
parse_req/1,
- parse_req/2
+ parse_req/2,
+ get_line/1
]).
%%----------------------------------------------------------------------

0 comments on commit acb7082

Please sign in to comment.
Something went wrong with that request. Please try again.