couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cml...@apache.org
Subject svn commit: r671151 - /incubator/couchdb/trunk/src/couchdb/couch_httpd.erl
Date Tue, 24 Jun 2008 12:16:04 GMT
Author: cmlenz
Date: Tue Jun 24 05:16:04 2008
New Revision: 671151

URL: http://svn.apache.org/viewvc?rev=671151&view=rev
Log:
Change `Server` HTTP header to say CouchDB instead of MochiWeb, and add a `Cache-Control:
must-revalidate` header to all JSON and attachment responses.

Modified:
    incubator/couchdb/trunk/src/couchdb/couch_httpd.erl

Modified: incubator/couchdb/trunk/src/couchdb/couch_httpd.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_httpd.erl?rev=671151&r1=671150&r2=671151&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_httpd.erl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_httpd.erl Tue Jun 24 05:16:04 2008
@@ -98,9 +98,11 @@
         "/_restart" ->
             handle_restart_request(Req, Method);
         "/_utils" ->
-            {ok, Req:respond({301, [{"Location", "/_utils/"}], <<>>})};
+            {ok, Req:respond({301, [
+                {"Location", "/_utils/"}
+            ] ++ server_header(), <<>>})};
         "/_utils/" ++ PathInfo ->
-            {ok, Req:serve_file(PathInfo, DocumentRoot)};
+            {ok, Req:serve_file(PathInfo, DocumentRoot, server_header())};
         "/_" ++ _Path ->
             throw({not_found, unknown_private_path});
         "/favicon.ico" ->
@@ -613,9 +615,10 @@
             throw({not_found, missing});
         {Type, Bin} ->
             Resp = Req:respond({200, [
-                {"content-type", Type},
-                {"content-length", integer_to_list(couch_doc:bin_size(Bin))}
-            ], chunked}),
+                {"Cache-Control", "must-revalidate"},
+                {"Content-Type", Type},
+                {"Content-Length", integer_to_list(couch_doc:bin_size(Bin))}
+            ] ++ server_header(), chunked}),
             couch_doc:bin_foldl(Bin,
                 fun(BinSegment, []) ->
                     ok = Resp:write_chunk(BinSegment),
@@ -899,11 +902,11 @@
     {500, error, Error}.
 
 send_error(Req, {method_not_allowed, Methods}) ->
-    {ok, Req:respond({405, [{"Allow", Methods}], <<>>})};
+    {ok, Req:respond({405, [{"Allow", Methods}] ++ server_header(), <<>>})};
 send_error(Req, {modified, Etag}) ->
-    {ok, Req:respond({412, [{"Etag", Etag}], <<>>})};
+    {ok, Req:respond({412, [{"Etag", Etag}] ++ server_header(), <<>>})};
 send_error(Req, {not_modified, Etag}) ->
-    {ok, Req:respond({304, [{"Etag", Etag}], <<>>})};
+    {ok, Req:respond({304, [{"Etag", Etag}] ++ server_header(), <<>>})};
 send_error(Req, Error) ->
     {Code, Json} = error_to_json(Error),
     ?LOG_INFO("HTTP Error (code ~w): ~p", [Code, Error]),
@@ -919,18 +922,23 @@
     send_json(Req, Code, [], Value).
 
 send_json(Req, Code, Headers, Value) ->
-    ContentType = negotiate_content_type(Req),
+    DefaultHeaders = [
+        {"Content-Type", negotiate_content_type(Req)},
+        {"Cache-Control", "must-revalidate"}
+    ] ++ server_header(),
     Body = cjson:encode(Value),
-    Resp = Req:respond({Code, [{"Content-Type", ContentType}] ++ Headers,
-                        Body}),
+    Resp = Req:respond({Code, DefaultHeaders ++ Headers, Body}),
     {ok, Resp}.
 
 start_json_response(Req, Code) ->
     start_json_response(Req, Code, []).
 
 start_json_response(Req, Code, Headers) ->
-    ContentType = negotiate_content_type(Req),
-    Req:respond({Code, [{"Content-Type", ContentType}] ++ Headers, chunked}).
+    DefaultHeaders = [
+        {"Content-Type", negotiate_content_type(Req)},
+        {"Cache-Control", "must-revalidate"}
+    ] ++ server_header(),
+    Req:respond({Code, DefaultHeaders ++ Headers, chunked}).
 
 end_json_response(Resp) ->
     Resp:write_chunk(""),
@@ -949,3 +957,7 @@
         true  -> "application/json";
         false -> "text/plain;charset=utf-8"
     end.
+
+server_header() ->
+    [{"Server", "CouchDB/" ++ couch_server:get_version() ++
+                " (Erlang OTP/" ++ erlang:system_info(otp_release) ++ ")"}].



Mime
View raw message