Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated mochiweb verison #43

Merged
merged 1 commit into from
May 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
7 changes: 7 additions & 0 deletions lib/mochiweb-2.4.2/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: erlang
notifications:
email: false
otp_release:
- R14B03
- R14B02
- R14B01
33 changes: 31 additions & 2 deletions lib/mochiweb-2.3.1/CHANGES.md → lib/mochiweb-2.4.2/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,39 @@
Version 2.3.1 released XXXX-XX-XX
Version 2.4.2 released 2013-02-05

* Fixed issue in mochiweb_response introduced in v2.4.0
https://github.com/mochi/mochiweb/pull/100

Version 2.4.1 released 2013-01-30

* Fixed issue in mochiweb_request introduced in v2.4.0
https://github.com/mochi/mochiweb/issues/97
* Fixed issue in mochifmt_records introduced in v2.4.0
https://github.com/mochi/mochiweb/issues/96

Version 2.4.0 released 2013-01-23

* Switch from parameterized modules to explicit tuple module calls for
R16 compatibility (#95)
* Fix for mochiweb_acceptor crash with extra-long HTTP headers under
R15B02 (#91)
* Fix case in handling range headers (#85)
* Handle combined Content-Length header (#88)
* Windows security fix for `safe_relative_path`, any path with a
backslash on any platform is now considered unsafe (#92)

Version 2.3.2 released 2012-07-27

* Case insensitive match for "Connection: close" (#81)

Version 2.3.1 released 2012-03-31

* Fix edoc warnings (#63)
* Fix mochiweb_html handling of invalid charref sequences (unescaped &) (#69).
* Add a manual garbage collection between requests to avoid worst case behavior
on keep-alive sockets.
* Fix dst cookie bug (#73)
* Removed unnecessary template_dir option, see
https://github.com/basho/rebar/issues/203

Version 2.3.0 released 2011-10-14

Expand Down Expand Up @@ -33,4 +63,3 @@ Version 2.1.0 released 2011-08-29
* Added new `mochijson2:decode/2` with `{format, struct | proplist | eep18}`
options for easy decoding to various proplist formats. Also added encoding
support for eep18 style objects.

File renamed without changes.
13 changes: 5 additions & 8 deletions lib/mochiweb-2.3.1/Makefile → lib/mochiweb-2.4.2/Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
ROOT = ../..
REBAR = $(ROOT)/bin/rebar

PREFIX:=../
DEST:=$(PREFIX)$(PROJECT)

all: compile

compile:
@$(REBAR) compile
REBAR=./rebar

deps:
$(REBAR) get-deps
all:
@$(REBAR) get-deps compile

edoc:
@$(REBAR) doc
Expand All @@ -30,3 +26,4 @@ dialyzer:

app:
@$(REBAR) create template=mochiwebapp dest=$(DEST) appid=$(PROJECT)

File renamed without changes.
Binary file added lib/mochiweb-2.4.2/rebar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{erl_opts, [debug_info]}.
{cover_enabled, true}.
{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
{template_dir, "support/templates/"}.
{dialyzer_opts, [{warnings, [no_return,
no_unused,
no_improper_lists,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@
%% M:format("{0.bar}", [#rec{bar=foo}]).
%% foo

-module(mochifmt_records, [Recs]).
-module(mochifmt_records).
-author('[email protected]').
-export([get_value/2]).
-export([new/1, get_value/3]).

get_value(Key, Rec) when is_tuple(Rec) and is_atom(element(1, Rec)) ->
new([{_Rec, RecFields}]=Recs) when is_list(RecFields) ->
{?MODULE, Recs}.

get_value(Key, Rec, {?MODULE, Recs})
when is_tuple(Rec) and is_atom(element(1, Rec)) ->
try begin
Atom = list_to_existing_atom(Key),
{_, Fields} = proplists:lookup(element(1, Rec), Recs),
element(get_rec_index(Atom, Fields, 2), Rec)
end
catch error:_ -> mochifmt:get_value(Key, Rec)
end;
get_value(Key, Args) ->
get_value(Key, Args, {?MODULE, _Recs}) ->
mochifmt:get_value(Key, Args).

get_rec_index(Atom, [Atom | _], Index) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@

%% @doc Template module for a mochifmt formatter.

-module(mochifmt_std, []).
-module(mochifmt_std).
-author('[email protected]').
-export([format/2, get_value/2, format_field/2, get_field/2, convert_field/2]).
-export([new/0, format/3, get_value/3, format_field/3, get_field/3, convert_field/3]).

format(Format, Args) ->
new() ->
{?MODULE}.

format(Format, Args, {?MODULE}=THIS) ->
mochifmt:format(Format, Args, THIS).

get_field(Key, Args) ->
get_field(Key, Args, {?MODULE}=THIS) ->
mochifmt:get_field(Key, Args, THIS).

convert_field(Key, Args) ->
convert_field(Key, Args, {?MODULE}) ->
mochifmt:convert_field(Key, Args).

get_value(Key, Args) ->
get_value(Key, Args, {?MODULE}) ->
mochifmt:get_value(Key, Args).

format_field(Arg, Format) ->
format_field(Arg, Format, {?MODULE}=THIS) ->
mochifmt:format_field(Arg, Format, THIS).

%%
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%% This is generated from src/mochiweb.app.src
{application, mochiweb,
[{description, "MochiMedia Web Server"},
{vsn, "2.3.1"},
{vsn, "2.4.2"},
{modules, []},
{registered, []},
{env, []},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ quote(V0) ->
rfc2109_cookie_expires_date(LocalTime) ->
{{YYYY,MM,DD},{Hour,Min,Sec}} =
case calendar:local_time_to_universal_time_dst(LocalTime) of
[] ->
{Date, {Hour1, Min1, Sec1}} = LocalTime,
LocalTime2 = {Date, {Hour1 + 1, Min1, Sec1}},
case calendar:local_time_to_universal_time_dst(LocalTime2) of
[Gmt] -> Gmt;
[_,Gmt] -> Gmt
end;
[Gmt] -> Gmt;
[_,Gmt] -> Gmt
end,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-module(mochiweb_headers).
-author('[email protected]').
-export([empty/0, from_list/1, insert/3, enter/3, get_value/2, lookup/2]).
-export([delete_any/2, get_primary_value/2]).
-export([delete_any/2, get_primary_value/2, get_combined_value/2]).
-export([default/3, enter_from_list/2, default_from_list/2]).
-export([to_list/1, make/1]).
-export([from_binary/1]).
Expand Down Expand Up @@ -112,6 +112,34 @@ get_primary_value(K, T) ->
lists:takewhile(fun (C) -> C =/= $; end, V)
end.

%% @spec get_combined_value(key(), headers()) -> string() | undefined
%% @doc Return the value from the given header using a case insensitive search.
%% If the value of the header is a comma-separated list where holds values
%% are all identical, the identical value will be returned.
%% undefined will be returned for keys that are not present or the
%% values in the list are not the same.
%%
%% NOTE: The process isn't designed for a general purpose. If you need
%% to access all values in the combined header, please refer to
%% '''tokenize_header_value/1'''.
%%
%% Section 4.2 of the RFC 2616 (HTTP 1.1) describes multiple message-header
%% fields with the same field-name may be present in a message if and only
%% if the entire field-value for that header field is defined as a
%% comma-separated list [i.e., #(values)].
get_combined_value(K, T) ->
case get_value(K, T) of
undefined ->
undefined;
V ->
case sets:to_list(sets:from_list(tokenize_header_value(V))) of
[Val] ->
Val;
_ ->
undefined
end
end.

%% @spec lookup(key(), headers()) -> {value, {key(), string()}} | none
%% @doc Return the case preserved key and value for the given header using
%% a case insensitive search. none will be returned for keys that are
Expand Down Expand Up @@ -164,6 +192,49 @@ delete_any(K, T) ->

%% Internal API

tokenize_header_value(undefined) ->
undefined;
tokenize_header_value(V) ->
reversed_tokens(trim_and_reverse(V, false), [], []).

trim_and_reverse([S | Rest], Reversed) when S=:=$ ; S=:=$\n; S=:=$\t ->
trim_and_reverse(Rest, Reversed);
trim_and_reverse(V, false) ->
trim_and_reverse(lists:reverse(V), true);
trim_and_reverse(V, true) ->
V.

reversed_tokens([], [], Acc) ->
Acc;
reversed_tokens([], Token, Acc) ->
[Token | Acc];
reversed_tokens("\"" ++ Rest, [], Acc) ->
case extract_quoted_string(Rest, []) of
{String, NewRest} ->
reversed_tokens(NewRest, [], [String | Acc]);
undefined ->
undefined
end;
reversed_tokens("\"" ++ _Rest, _Token, _Acc) ->
undefined;
reversed_tokens([C | Rest], [], Acc) when C=:=$ ;C=:=$\n;C=:=$\t;C=:=$, ->
reversed_tokens(Rest, [], Acc);
reversed_tokens([C | Rest], Token, Acc) when C=:=$ ;C=:=$\n;C=:=$\t;C=:=$, ->
reversed_tokens(Rest, [], [Token | Acc]);
reversed_tokens([C | Rest], Token, Acc) ->
reversed_tokens(Rest, [C | Token], Acc);
reversed_tokens(_, _, _) ->
undefeined.

extract_quoted_string([], _Acc) ->
undefined;
extract_quoted_string("\"\\" ++ Rest, Acc) ->
extract_quoted_string(Rest, "\"" ++ Acc);
extract_quoted_string("\"" ++ Rest, Acc) ->
{Acc, Rest};
extract_quoted_string([C | Rest], Acc) ->
extract_quoted_string(Rest, [C | Acc]).

expand({array, L}) ->
mochiweb_util:join(lists:reverse(L), ", ");
expand(V) ->
Expand Down Expand Up @@ -237,6 +308,37 @@ get_primary_value_test() ->
get_primary_value(<<"baz">>, H)),
ok.

get_combined_value_test() ->
H = make([{hdr, foo}, {baz, <<"wibble,taco">>}, {content_length, "123, 123"},
{test, " 123, 123, 123 , 123,123 "},
{test2, "456, 123, 123 , 123"},
{test3, "123"}, {test4, " 123, "}]),
?assertEqual(
"foo",
get_combined_value(hdr, H)),
?assertEqual(
undefined,
get_combined_value(bar, H)),
?assertEqual(
undefined,
get_combined_value(<<"baz">>, H)),
?assertEqual(
"123",
get_combined_value(<<"content_length">>, H)),
?assertEqual(
"123",
get_combined_value(<<"test">>, H)),
?assertEqual(
undefined,
get_combined_value(<<"test2">>, H)),
?assertEqual(
"123",
get_combined_value(<<"test3">>, H)),
?assertEqual(
"123",
get_combined_value(<<"test4">>, H)),
ok.

set_cookie_test() ->
H = make([{"set-cookie", foo}, {"set-cookie", bar}, {"set-cookie", baz}]),
?assertEqual(
Expand Down Expand Up @@ -296,4 +398,23 @@ headers_test() ->
[] = ?MODULE:to_list(?MODULE:from_binary([<<"\r\n\r\n">>])),
ok.

tokenize_header_value_test() ->
?assertEqual(["a quote in a \"quote\"."],
tokenize_header_value("\"a quote in a \\\"quote\\\".\"")),
?assertEqual(["abc"], tokenize_header_value("abc")),
?assertEqual(["abc", "def"], tokenize_header_value("abc def")),
?assertEqual(["abc", "def"], tokenize_header_value("abc , def")),
?assertEqual(["abc", "def"], tokenize_header_value(",abc ,, def,,")),
?assertEqual(["abc def"], tokenize_header_value("\"abc def\" ")),
?assertEqual(["abc, def"], tokenize_header_value("\"abc, def\"")),
?assertEqual(["\\a\\$"], tokenize_header_value("\"\\a\\$\"")),
?assertEqual(["abc def", "foo, bar", "12345", ""],
tokenize_header_value("\"abc def\" \"foo, bar\" , 12345, \"\"")),
?assertEqual(undefined,
tokenize_header_value(undefined)),
?assertEqual(undefined,
tokenize_header_value("umatched quote\"")),
?assertEqual(undefined,
tokenize_header_value("\"unmatched quote")).

-endif.
Loading