summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Kocoloski <kocolosk@apache.org>2009-11-30 18:33:59 +0000
committerAdam Kocoloski <kocolosk@apache.org>2009-11-30 18:33:59 +0000
commitb409b8836b82612880df1628cf831d0420e5eb2a (patch)
treea6f9052f5f1d9446c0a36191aa23ded7bce93e94
parent85809452290b99a0a00a91dd319b82f51f9f0c4a (diff)
ETags on POSTs to _view and _list should depend on Keys. COUCHDB-586
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@885529 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--share/www/script/test/etags_views.js23
-rw-r--r--share/www/script/test/list_views.js22
-rw-r--r--src/couchdb/couch_httpd_show.erl2
-rw-r--r--src/couchdb/couch_httpd_view.erl2
4 files changed, 47 insertions, 2 deletions
diff --git a/share/www/script/test/etags_views.js b/share/www/script/test/etags_views.js
index 8d248983..a12734f8 100644
--- a/share/www/script/test/etags_views.js
+++ b/share/www/script/test/etags_views.js
@@ -63,6 +63,29 @@ couchTests.etags_views = function(debug) {
});
T(xhr.status == 304);
+ // confirm ETag changes with different POST bodies
+ xhr = CouchDB.request("POST", "/test_suite_db/_design/etags/_view/basicView",
+ {body: JSON.stringify({keys:[1]})}
+ );
+ var etag1 = xhr.getResponseHeader("etag");
+ xhr = CouchDB.request("POST", "/test_suite_db/_design/etags/_view/basicView",
+ {body: JSON.stringify({keys:[2]})}
+ );
+ var etag2 = xhr.getResponseHeader("etag");
+ T(etag1 != etag2, "POST to map view generates key-depdendent ETags");
+
+ xhr = CouchDB.request("POST",
+ "/test_suite_db/_design/etags/_view/withReduce?group=true",
+ {body: JSON.stringify({keys:[1]})}
+ );
+ etag1 = xhr.getResponseHeader("etag");
+ xhr = CouchDB.request("POST",
+ "/test_suite_db/_design/etags/_view/withReduce?group=true",
+ {body: JSON.stringify({keys:[2]})}
+ );
+ etag2 = xhr.getResponseHeader("etag");
+ T(etag1 != etag2, "POST to reduce view generates key-depdendent ETags");
+
// all docs
xhr = CouchDB.request("GET", "/test_suite_db/_all_docs");
T(xhr.status == 200);
diff --git a/share/www/script/test/list_views.js b/share/www/script/test/list_views.js
index e31f0f83..d0400ff9 100644
--- a/share/www/script/test/list_views.js
+++ b/share/www/script/test/list_views.js
@@ -224,6 +224,17 @@ couchTests.list_views = function(debug) {
headers: {"if-none-match": etag}
});
T(xhr.status == 304);
+
+ // confirm ETag changes with different POST bodies
+ xhr = CouchDB.request("POST", "/test_suite_db/_design/lists/_list/basicBasic/basicView",
+ {body: JSON.stringify({keys:[1]})}
+ );
+ var etag1 = xhr.getResponseHeader("etag");
+ xhr = CouchDB.request("POST", "/test_suite_db/_design/lists/_list/basicBasic/basicView",
+ {body: JSON.stringify({keys:[2]})}
+ );
+ var etag2 = xhr.getResponseHeader("etag");
+ T(etag1 != etag2, "POST to map _list generates key-depdendent ETags");
// test the richness of the arguments
xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/basicJSON/basicView");
@@ -310,6 +321,17 @@ couchTests.list_views = function(debug) {
});
T(xhr.status == 304);
+ // confirm ETag changes with different POST bodies
+ xhr = CouchDB.request("POST", "/test_suite_db/_design/lists/_list/simpleForm/withReduce?group=true",
+ {body: JSON.stringify({keys:[1]})}
+ );
+ var etag1 = xhr.getResponseHeader("etag");
+ xhr = CouchDB.request("POST", "/test_suite_db/_design/lists/_list/simpleForm/withReduce?group=true",
+ {body: JSON.stringify({keys:[2]})}
+ );
+ var etag2 = xhr.getResponseHeader("etag");
+ T(etag1 != etag2, "POST to reduce _list generates key-depdendent ETags");
+
// verify the etags expire correctly
var docs = makeDocs(11, 12);
db.bulkSave(docs);
diff --git a/src/couchdb/couch_httpd_show.erl b/src/couchdb/couch_httpd_show.erl
index 14b9b415..5c95070a 100644
--- a/src/couchdb/couch_httpd_show.erl
+++ b/src/couchdb/couch_httpd_show.erl
@@ -191,7 +191,7 @@ output_map_list(#httpd{mochi_req=MReq, user_ctx=UserCtx}=Req, Lang, ListSrc, Vie
Headers = MReq:get(headers),
Hlist = mochiweb_headers:to_list(Headers),
Accept = proplists:get_value('Accept', Hlist),
- CurrentEtag = couch_httpd_view:view_group_etag(Group, Db, {Lang, ListSrc, Accept, UserCtx}),
+ CurrentEtag = couch_httpd_view:view_group_etag(Group, Db, {Lang, ListSrc, Accept, UserCtx, Keys}),
couch_httpd:etag_respond(Req, CurrentEtag, fun() ->
% get the os process here
% pass it into the view fold with closures
diff --git a/src/couchdb/couch_httpd_view.erl b/src/couchdb/couch_httpd_view.erl
index cb9f8687..af91b654 100644
--- a/src/couchdb/couch_httpd_view.erl
+++ b/src/couchdb/couch_httpd_view.erl
@@ -202,7 +202,7 @@ output_reduce_view(Req, Db, View, Group, QueryArgs, Keys) ->
skip = Skip,
group_level = GroupLevel
} = QueryArgs,
- CurrentEtag = view_group_etag(Group, Db),
+ CurrentEtag = view_group_etag(Group, Db, Keys),
couch_httpd:etag_respond(Req, CurrentEtag, fun() ->
{ok, GroupRowsFun, RespFun} = make_reduce_fold_funs(Req, GroupLevel, QueryArgs, CurrentEtag, #reduce_fold_helper_funs{}),
{Resp, _RedAcc3} = lists:foldl(