couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject svn commit: r1052032 - in /couchdb/branches/1.1.x: src/couchdb/couch_util.erl test/etap/140-attachment-comp.t
Date Wed, 22 Dec 2010 19:08:23 GMT
Author: fdmanana
Date: Wed Dec 22 19:08:23 2010
New Revision: 1052032

URL: http://svn.apache.org/viewvc?rev=1052032&view=rev
Log:
Merged revision 1052031 from trunk:

Make sure attachments get compressed when their MIME type lists parameters

Closes COUCHDB-996.


Modified:
    couchdb/branches/1.1.x/src/couchdb/couch_util.erl
    couchdb/branches/1.1.x/test/etap/140-attachment-comp.t

Modified: couchdb/branches/1.1.x/src/couchdb/couch_util.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/src/couchdb/couch_util.erl?rev=1052032&r1=1052031&r2=1052032&view=diff
==============================================================================
--- couchdb/branches/1.1.x/src/couchdb/couch_util.erl (original)
+++ couchdb/branches/1.1.x/src/couchdb/couch_util.erl Wed Dec 22 19:08:23 2010
@@ -398,7 +398,8 @@ compressible_att_type(MimeType) ->
     ),
     lists:any(
         fun(TypeExp) ->
-            Regexp = ["^\\s*", re:replace(TypeExp, "\\*", ".*"), "\\s*$"],
+            Regexp = ["^\\s*", re:replace(TypeExp, "\\*", ".*"),
+                "(?:\\s*;.*?)?\\s*", $$],
             re:run(MimeType, Regexp, [caseless]) =/= nomatch
         end,
         [T || T <- TypeExpList, T /= []]

Modified: couchdb/branches/1.1.x/test/etap/140-attachment-comp.t
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/test/etap/140-attachment-comp.t?rev=1052032&r1=1052031&r2=1052032&view=diff
==============================================================================
--- couchdb/branches/1.1.x/test/etap/140-attachment-comp.t (original)
+++ couchdb/branches/1.1.x/test/etap/140-attachment-comp.t Wed Dec 22 19:08:23 2010
@@ -22,7 +22,7 @@ test_db_name() ->
 main(_) ->
     test_util:init_code_path(),
 
-    etap:plan(78),
+    etap:plan(86),
     case (catch test()) of
         ok ->
             etap:end_tests();
@@ -75,6 +75,8 @@ test() ->
         "compress"
     ),
 
+    test_compressible_type_with_parameters(),
+
     timer:sleep(3000), % to avoid mochiweb socket closed exceptions
     couch_server:delete(test_db_name(), []),
     couch_server_sup:stop(),
@@ -702,6 +704,56 @@ test_create_already_compressed_att_with_
     ),
     ok.
 
+test_compressible_type_with_parameters() ->
+    {ok, {{_, Code, _}, _Headers, _Body}} = http:request(
+        put,
+        {db_url() ++ "/testdoc5/readme.txt", [],
+        "text/plain; charset=UTF-8", test_text_data()},
+        [],
+        [{sync, true}]),
+    etap:is(Code, 201, "Created text attachment with MIME type "
+        "'text/plain; charset=UTF-8' using the standalone api"),
+    {ok, {{_, Code2, _}, Headers2, Body}} = http:request(
+        get,
+        {db_url() ++ "/testdoc5/readme.txt", [{"Accept-Encoding", "gzip"}]},
+        [],
+        [{sync, true}]),
+    etap:is(Code2, 200, "HTTP response code is 200"),
+    Gziped = lists:member({"content-encoding", "gzip"}, Headers2),
+    etap:is(Gziped, true, "received body is gziped"),
+    Uncompressed = binary_to_list(zlib:gunzip(list_to_binary(Body))),
+    etap:is(Uncompressed, test_text_data(), "received data is gzipped"),
+    {ok, {{_, Code3, _}, _Headers3, Body3}} = http:request(
+        get,
+        {db_url() ++ "/testdoc5?att_encoding_info=true", []},
+        [],
+        [{sync, true}]),
+    etap:is(Code3, 200, "HTTP response code is 200"),
+    Json = couch_util:json_decode(Body3),
+    {TextAttJson} = couch_util:get_nested_json_value(
+        Json,
+        [<<"_attachments">>, <<"readme.txt">>]
+    ),
+    TextAttLength = couch_util:get_value(<<"length">>, TextAttJson),
+    etap:is(
+        TextAttLength,
+        length(test_text_data()),
+        "text attachment stub length matches the uncompressed length"
+    ),
+    TextAttEncoding = couch_util:get_value(<<"encoding">>, TextAttJson),
+    etap:is(
+        TextAttEncoding,
+        <<"gzip">>,
+        "text attachment stub has the encoding field set to gzip"
+    ),
+    TextAttEncLength = couch_util:get_value(<<"encoded_length">>, TextAttJson),
+    etap:is(
+        TextAttEncLength,
+        iolist_size(zlib:gzip(test_text_data())),
+        "text attachment stub encoded_length matches the compressed length"
+    ),
+    ok.
+
 test_png_data() ->
     {ok, Data} = file:read_file(
         test_util:source_file("share/www/image/logo.png")



Mime
View raw message