Skip to content

Commit

Permalink
bump to 2.3.2, Case insensitive match for "Connection: close" (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
etrepum committed Jul 28, 2012
1 parent d541e9a commit 9d205a8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
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)
Expand Down
2 changes: 1 addition & 1 deletion src/mochiweb.app.src
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.3.2"},
{modules, []},
{registered, []},
{env, []},
Expand Down
9 changes: 8 additions & 1 deletion src/mochiweb_request.erl
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ should_close() ->
DidNotRecv = erlang:get(?SAVE_RECV) =:= undefined,
ForceClose orelse Version < {1, 0}
%% Connection: close
orelse get_header_value("connection") =:= "close"
orelse is_close(get_header_value("connection"))
%% HTTP 1.0 requires Connection: Keep-Alive
orelse (Version =:= {1, 0}
andalso get_header_value("connection") =/= "Keep-Alive")

This comment has been minimized.

Copy link
@benoitc

benoitc Jul 29, 2012

Collaborator

shouldn't it be the same for keep-alive then?

This comment has been minimized.

Copy link
@etrepum

etrepum via email Jul 29, 2012

Author Member

This comment has been minimized.

Copy link
@benoitc

benoitc Jul 30, 2012

Collaborator

well the keep-alive value is also a connection header. But OK...

This comment has been minimized.

Copy link
@etrepum

etrepum via email Jul 30, 2012

Author Member
Expand All @@ -394,6 +394,13 @@ should_close() ->
orelse (DidNotRecv
andalso get_header_value("transfer-encoding") =:= "chunked").

is_close("close") ->
true;
is_close(S=[_C, _L, _O, _S, _E]) ->
string:to_lower(S) =:= "close";
is_close(_) ->
false.

%% @spec cleanup() -> ok
%% @doc Clean up any junk in the process dictionary, required before continuing
%% a Keep-Alive request.
Expand Down
30 changes: 30 additions & 0 deletions src/mochiweb_request_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,34 @@ accepted_content_types_test() ->
?assertEqual(["application/json", "text/html"],
Req9:accepted_content_types(["text/html", "application/json"])).

should_close_test() ->
F = fun (V, H) ->
(mochiweb_request:new(
nil, 'GET', "/", V,
mochiweb_headers:make(H)
)):should_close()
end,
?assertEqual(
true,
F({1, 1}, [{"Connection", "close"}])),
?assertEqual(
true,
F({1, 0}, [{"Connection", "close"}])),
?assertEqual(
true,
F({1, 1}, [{"Connection", "ClOSe"}])),
?assertEqual(
false,
F({1, 1}, [{"Connection", "closer"}])),
?assertEqual(
false,
F({1, 1}, [])),
?assertEqual(
true,
F({1, 0}, [])),
?assertEqual(
false,
F({1, 0}, [{"Connection", "Keep-Alive"}])),
ok.

-endif.

2 comments on commit 9d205a8

@Xorcerer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we just make the return value of get_header_value/1 to lower case? If it is a string().

@etrepum
Copy link
Member Author

@etrepum etrepum commented on 9d205a8 Jul 29, 2012 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.