You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ch...@apache.org on 2013/11/07 20:35:03 UTC

[1/2] git commit: updated refs/heads/1922-cors-reduce-headers to a9486d2

Updated Branches:
  refs/heads/1922-cors-reduce-headers [created] a9486d266


COUCHDB-1922: Demonstration of bug


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/0a6dead3
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/0a6dead3
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/0a6dead3

Branch: refs/heads/1922-cors-reduce-headers
Commit: 0a6dead37b6ced514ba0a7e258435b0bcc992f68
Parents: 6ee2e72
Author: Russell Branca <ch...@gmail.com>
Authored: Thu Nov 7 10:50:41 2013 -0800
Committer: Russell Branca <ch...@gmail.com>
Committed: Thu Nov 7 10:50:41 2013 -0800

----------------------------------------------------------------------
 src/couchdb/couch_httpd_cors.erl | 2 ++
 test/etap/231-cors.t             | 9 ++++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/0a6dead3/src/couchdb/couch_httpd_cors.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd_cors.erl b/src/couchdb/couch_httpd_cors.erl
index 91fe1ae..dde2cfd 100644
--- a/src/couchdb/couch_httpd_cors.erl
+++ b/src/couchdb/couch_httpd_cors.erl
@@ -24,6 +24,8 @@
 
 -export([is_preflight_request/1, cors_headers/2]).
 
+-compile(export_all).
+
 -define(SUPPORTED_HEADERS, "Accept, Accept-Language, Content-Type," ++
         "Expires, Last-Modified, Pragma, Origin, Content-Length," ++
         "If-Match, Destination, X-Requested-With, " ++

http://git-wip-us.apache.org/repos/asf/couchdb/blob/0a6dead3/test/etap/231-cors.t
----------------------------------------------------------------------
diff --git a/test/etap/231-cors.t b/test/etap/231-cors.t
index ce52747..fb84585 100644
--- a/test/etap/231-cors.t
+++ b/test/etap/231-cors.t
@@ -32,7 +32,7 @@ server() ->
 main(_) ->
     test_util:init_code_path(),
 
-    etap:plan(30),
+    etap:plan(31),
     case (catch test()) of
         ok ->
             etap:end_tests();
@@ -75,6 +75,9 @@ test() ->
     test_no_headers_server(),
     test_no_headers_db(),
 
+    % Reduce headers test
+    test_reduce_headers(),
+
     % Now enable CORS
     ok = couch_config:set("httpd", "enable_cors", "true", false),
     ok = couch_config:set("cors", "origins", "http://example.com", false),
@@ -447,3 +450,7 @@ maybe_append_vhost(true) ->
     [{"Host", "http://example.com"}];
 maybe_append_vhost(Else) ->
     [].
+
+test_reduce_headers() ->
+    etap:is([], couch_httpd_cors:reduce_headers(["foo"],["bar"]),
+        "Reduce headers only allows the second list of fields").


[2/2] git commit: updated refs/heads/1922-cors-reduce-headers to a9486d2

Posted by ch...@apache.org.
COUCHDB-1922: fix CORS exposed headers


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/a9486d26
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/a9486d26
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/a9486d26

Branch: refs/heads/1922-cors-reduce-headers
Commit: a9486d2668939fb87a7298d31a7717be0d1912cc
Parents: 0a6dead
Author: Russell Branca <ch...@gmail.com>
Authored: Thu Nov 7 11:34:58 2013 -0800
Committer: Russell Branca <ch...@gmail.com>
Committed: Thu Nov 7 11:34:58 2013 -0800

----------------------------------------------------------------------
 src/couchdb/couch_httpd_cors.erl | 8 +++++---
 test/etap/231-cors.t             | 2 +-
 2 files changed, 6 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/a9486d26/src/couchdb/couch_httpd_cors.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd_cors.erl b/src/couchdb/couch_httpd_cors.erl
index dde2cfd..9ac8858 100644
--- a/src/couchdb/couch_httpd_cors.erl
+++ b/src/couchdb/couch_httpd_cors.erl
@@ -37,6 +37,8 @@
 % as defined in http://www.w3.org/TR/cors/#terminology
 -define(SIMPLE_HEADERS, ["Cache-Control", "Content-Language",
         "Content-Type", "Expires", "Last-Modified", "Pragma"]).
+-define(ALLOWED_HEADERS, lists:sort(["Server", "Etag",
+        "Accept-Ranges" | ?SIMPLE_HEADERS])).
 -define(SIMPLE_CONTENT_TYPE_VALUES, ["application/x-www-form-urlencoded",
         "multipart/form-data", "text/plain"]).
 
@@ -214,7 +216,7 @@ maybe_apply_cors_headers(CorsHeaders, RequestHeaders0) ->
     % return: RequestHeaders ++ CorsHeaders ++ ACEH
 
     RequestHeaders = [K || {K,_V} <- RequestHeaders0],
-    ExposedHeaders0 = reduce_headers(RequestHeaders, ?SIMPLE_HEADERS),
+    ExposedHeaders0 = reduce_headers(RequestHeaders, ?ALLOWED_HEADERS),
 
     % here we may have not moved Content-Type into ExposedHeaders,
     % now we need to check whether the Content-Type valus is
@@ -244,10 +246,10 @@ reduce_headers(A, B) ->
     reduce_headers0(A, B, []).
 
 reduce_headers0([], _B, Result) ->
-    Result;
+    lists:sort(Result);
 reduce_headers0([ElmA|RestA], B, Result) ->
     R = case member_nocase(ElmA, B) of
-    true -> Result;
+    false -> Result;
     _Else -> [ElmA | Result]
     end,
     reduce_headers0(RestA, B, R).

http://git-wip-us.apache.org/repos/asf/couchdb/blob/a9486d26/test/etap/231-cors.t
----------------------------------------------------------------------
diff --git a/test/etap/231-cors.t b/test/etap/231-cors.t
index fb84585..c770d69 100644
--- a/test/etap/231-cors.t
+++ b/test/etap/231-cors.t
@@ -222,7 +222,7 @@ test_db_request(VHost) ->
             "http://example.com",
             "db Access-Control-Allow-Origin ok"),
         etap:is(proplists:get_value("Access-Control-Expose-Headers", RespHeaders),
-            "Content-Type, Server",
+            "Cache-Control, Content-Type, Server",
             "db Access-Control-Expose-Headers ok");
     _ ->
         etap:is(false, true, "ibrowse failed")