Permalink
Browse files

bump to 2.3.2, Case insensitive match for "Connection: close" (#81)

  • Loading branch information...
1 parent d541e9a commit 9d205a8ca87e62216de6215a7a8008ab4b6e31c3 @etrepum etrepum committed Jul 28, 2012
Showing with 43 additions and 2 deletions.
  1. +4 −0 CHANGES.md
  2. +1 −1 src/mochiweb.app.src
  3. +8 −1 src/mochiweb_request.erl
  4. +30 −0 src/mochiweb_request_tests.erl
View
@@ -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)
@@ -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, []},
@@ -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")
@benoitc
benoitc Jul 29, 2012 Collaborator

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

@etrepum
etrepum via email Jul 29, 2012 Member
@benoitc
benoitc Jul 30, 2012 Collaborator

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

@etrepum
etrepum via email Jul 30, 2012 Member
@@ -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.
@@ -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

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

@etrepum
Member
Please sign in to comment.