couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cml...@apache.org
Subject svn commit: r671125 - in /incubator/couchdb/trunk: bin/couchdb.tpl.in src/mochiweb/Makefile.am src/mochiweb/mochiweb_html.erl src/mochiweb/mochiweb_request.erl src/mochiweb/mochiweb_socket_server.erl
Date Tue, 24 Jun 2008 11:06:24 GMT
Author: cmlenz
Date: Tue Jun 24 04:06:24 2008
New Revision: 671125

URL: http://svn.apache.org/viewvc?rev=671125&view=rev
Log:
Updated MochiWeb in trunk to r82.

Modified:
    incubator/couchdb/trunk/bin/couchdb.tpl.in
    incubator/couchdb/trunk/src/mochiweb/Makefile.am
    incubator/couchdb/trunk/src/mochiweb/mochiweb_html.erl
    incubator/couchdb/trunk/src/mochiweb/mochiweb_request.erl
    incubator/couchdb/trunk/src/mochiweb/mochiweb_socket_server.erl

Modified: incubator/couchdb/trunk/bin/couchdb.tpl.in
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/bin/couchdb.tpl.in?rev=671125&r1=671124&r2=671125&view=diff
==============================================================================
--- incubator/couchdb/trunk/bin/couchdb.tpl.in (original)
+++ incubator/couchdb/trunk/bin/couchdb.tpl.in Tue Jun 24 04:06:24 2008
@@ -206,7 +206,7 @@
     command="`%ICU_CONFIG% --invoke` \
         %ERL% $interactive_option -smp auto -sasl errlog_type error \
         -pa %localerlanglibdir%/couch-%version%/ebin \
-            %localerlanglibdir%/mochiweb-r76/ebin \
+            %localerlanglibdir%/mochiweb-r82/ebin \
         -eval \"application:load(inets)\" \
         -eval \"application:load(crypto)\" \
         -eval \"application:load(couch)\" \

Modified: incubator/couchdb/trunk/src/mochiweb/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/mochiweb/Makefile.am?rev=671125&r1=671124&r2=671125&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/mochiweb/Makefile.am (original)
+++ incubator/couchdb/trunk/src/mochiweb/Makefile.am Tue Jun 24 04:06:24 2008
@@ -10,7 +10,7 @@
 ## License for the specific language governing permissions and limitations under
 ## the License.
 
-mochiwebebindir = $(localerlanglibdir)/mochiweb-r76/ebin
+mochiwebebindir = $(localerlanglibdir)/mochiweb-r82/ebin
 
 mochiweb_file_collection = \
     mochifmt.erl \

Modified: incubator/couchdb/trunk/src/mochiweb/mochiweb_html.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/mochiweb/mochiweb_html.erl?rev=671125&r1=671124&r2=671125&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/mochiweb/mochiweb_html.erl (original)
+++ incubator/couchdb/trunk/src/mochiweb/mochiweb_html.erl Tue Jun 24 04:06:24 2008
@@ -101,7 +101,7 @@
 to_html(Tokens) when is_list(Tokens) ->
     to_html(Tokens, []).
 
-%% @spec escape(string() | binary()) -> string()
+%% @spec escape(string() | atom() | binary()) -> binary()
 %% @doc Escape a string such that it's safe for HTML (amp; lt; gt;).
 escape(B) when is_binary(B) ->
     escape(binary_to_list(B), []);
@@ -110,7 +110,7 @@
 escape(S) when is_list(S) ->
     escape(S, []).
 
-%% @spec escape_attr(S::string()) -> string()
+%% @spec escape_attr(string() | binary() | atom() | integer() | float()) -> binary()
 %% @doc Escape a string such that it's safe for HTML attrs
 %%      (amp; lt; gt; quot;).
 escape_attr(B) when is_binary(B) ->

Modified: incubator/couchdb/trunk/src/mochiweb/mochiweb_request.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/mochiweb/mochiweb_request.erl?rev=671125&r1=671124&r2=671125&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/mochiweb/mochiweb_request.erl (original)
+++ incubator/couchdb/trunk/src/mochiweb/mochiweb_request.erl Tue Jun 24 04:06:24 2008
@@ -15,11 +15,11 @@
 -export([send/1, recv/1, recv/2, recv_body/0, recv_body/1]).
 -export([start_response/1, start_response_length/1, start_raw_response/1]).
 -export([respond/1, ok/1]).
--export([not_found/0]).
+-export([not_found/0, not_found/1]).
 -export([parse_post/0, parse_qs/0]).
 -export([should_close/0, cleanup/0]).
 -export([parse_cookie/0, get_cookie_value/1]).
--export([serve_file/2]).
+-export([serve_file/2, serve_file/3]).
 -export([test/0]).
 
 -define(SAVE_QS, mochiweb_request_qs).
@@ -276,9 +276,16 @@
     Response.
 
 %% @spec not_found() -> response()
-%% @doc respond({404, [{"Content-Type", "text/plain"}], "Not found."}).
+%% @doc Alias for <code>not_found([])</code>.
 not_found() ->
-    respond({404, [{"Content-Type", "text/plain"}], <<"Not found.">>}).
+    not_found([]).
+
+%% @spec not_found(ExtraHeaders) -> response()
+%% @doc Alias for <code>respond({404, [{"Content-Type", "text/plain"}
+%% | ExtraHeaders], &lt;&lt;"Not found."&gt;&gt;})</code>.
+not_found(ExtraHeaders) ->
+    respond({404, [{"Content-Type", "text/plain"} | ExtraHeaders],
+             <<"Not found.">>}).
 
 %% @spec ok({value(), iodata()} | {value(), ioheaders(), iodata() | {file, IoDevice}}) ->
 %%           response()
@@ -326,7 +333,9 @@
         %% unread data left on the socket, can't safely continue
         orelse (DidNotRecv
                 andalso get_header_value("content-length") =/= undefined
-                andalso list_to_integer(get_header_value("content-length")) > 0).
+                andalso list_to_integer(get_header_value("content-length")) > 0)
+        orelse (DidNotRecv
+                andalso get_header_value("transfer-encoding") =:= "chunked").
 
 %% @spec cleanup() -> ok
 %% @doc Clean up any junk in the process dictionary, required before continuing
@@ -455,9 +464,14 @@
 %% @spec serve_file(Path, DocRoot) -> Response
 %% @doc Serve a file relative to DocRoot.
 serve_file(Path, DocRoot) ->
+    serve_file(Path, DocRoot, []).
+
+%% @spec serve_file(Path, DocRoot, ExtraHeaders) -> Response
+%% @doc Serve a file relative to DocRoot.
+serve_file(Path, DocRoot, ExtraHeaders) ->
     case mochiweb_util:safe_relative_path(Path) of
         undefined ->
-            not_found();
+            not_found(ExtraHeaders);
         RelPath ->
             FullPath = filename:join([DocRoot, RelPath]),
             File = case filelib:is_dir(FullPath) of
@@ -471,20 +485,23 @@
                     LastModified = httpd_util:rfc1123_date(FileInfo#file_info.mtime),
                     case get_header_value("if-modified-since") of
                         LastModified ->
-                            respond({304, [], ""});
+                            respond({304, ExtraHeaders, ""});
                         _ ->
                             case file:open(File, [raw, binary]) of
                                 {ok, IoDevice} ->
                                     ContentType = mochiweb_util:guess_mime(File),
-                                    Res = ok({ContentType, [{"last-modified", LastModified}],
{file, IoDevice}}),
+                                    Res = ok({ContentType,
+                                              [{"last-modified", LastModified}
+                                               | ExtraHeaders],
+                                              {file, IoDevice}}),
                                     file:close(IoDevice),
                                     Res;
                                 _ ->
-                                    not_found()
+                                    not_found(ExtraHeaders)
                             end
                     end;
                 {error, _} ->
-                    not_found()
+                    not_found(ExtraHeaders)
             end
     end.
 

Modified: incubator/couchdb/trunk/src/mochiweb/mochiweb_socket_server.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/mochiweb/mochiweb_socket_server.erl?rev=671125&r1=671124&r2=671125&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/mochiweb/mochiweb_socket_server.erl (original)
+++ incubator/couchdb/trunk/src/mochiweb/mochiweb_socket_server.erl Tue Jun 24 04:06:24 2008
@@ -96,6 +96,14 @@
             gen_server:start_link(Name, ?MODULE, State, [])
     end.
 
+ipv6_supported() ->
+    case (catch inet:getaddr("localhost", inet6)) of
+        {ok, _Addr} ->
+            true;
+        {error, _} ->
+            false
+    end.
+
 init(State=#mochiweb_socket_server{ip=Ip, port=Port, backlog=Backlog}) ->
     process_flag(trap_exit, true),
     BaseOpts = [binary, 
@@ -106,11 +114,16 @@
                 {active, false},
                 {nodelay, true}],
     Opts = case Ip of
-               any ->
-                   BaseOpts;
-               Ip ->
-                   [{ip, Ip} | BaseOpts]
-           end,
+        any ->
+            case ipv6_supported() of % IPv4, and IPv6 if supported
+                true -> [inet, inet6 | BaseOpts];
+                _ -> BaseOpts
+            end;
+        {_, _, _, _} -> % IPv4
+            [inet, {ip, Ip} | BaseOpts];
+        {_, _, _, _, _, _, _, _} -> % IPv6
+            [inet6, {ip, Ip} | BaseOpts]
+    end,
     case gen_tcp_listen(Port, Opts, State) of
         {stop, eacces} ->
             case Port < 1024 of 



Mime
View raw message