Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

allow block size to be set on creation

Allow the block_size property of a file to be set on creation via the
HTTP resource by way of the X-Luwak-Block-Size header.
  • Loading branch information...
commit 951eac690253bc85e046f4066df5983120343697 1 parent 2dc13c5
Ryan Zezeski authored March 02, 2011 Vagabond committed April 18, 2011

Showing 1 changed file with 19 additions and 1 deletion. Show diff stats Hide diff stats

  1. 20  src/luwak_wm_file.erl
20  src/luwak_wm_file.erl
@@ -124,6 +124,7 @@
124 124
 
125 125
 -define(HEAD_RANGE, "Range").
126 126
 -define(HEAD_CRANGE, "Content-Range").
  127
+-define(HEAD_BLOCK_SZ, "X-Luwak-Block-Size").
127 128
 
128 129
 %% @spec init(proplist()) -> {ok, context()}
129 130
 %% @doc Initialize this resource.  This function extracts the
@@ -495,7 +496,8 @@ accept_doc_body(RD, Ctx=#ctx{key=K, client=C}) ->
495 496
     H0 = case Ctx#ctx.handle of
496 497
              {ok, H} -> H;
497 498
              _ ->
498  
-                 {ok, H} = luwak_file:create(C, K, dict:new()),
  499
+                 FileProps = extract_file_props(RD),
  500
+                 {ok, H} = luwak_file:create(C, K, FileProps, dict:new()),
499 501
                  H
500 502
          end,
501 503
     {ok,H1} = luwak_file:set_attributes(C, H0, UserMetaMD),
@@ -543,6 +545,22 @@ extract_user_meta(RD) ->
543 545
                 end,
544 546
                 mochiweb_headers:to_list(wrq:req_headers(RD))).
545 547
 
  548
+%% @spec extract_file_props(reqdata()) -> proplists()
  549
+%% @doc Extract Luwak file properties from custom headers prefixed by
  550
+%%      X-Luwak- in the client's request.
  551
+extract_file_props(RD) ->
  552
+    extract_headers(RD, [{block_size, ?HEAD_BLOCK_SZ}], []).
  553
+
  554
+extract_headers(_RD, [], Acc) ->
  555
+    Acc;
  556
+extract_headers(RD, [{Key, Header}|T], Acc) ->
  557
+    case wrq:get_req_header(Header, RD) of
  558
+        undefined ->
  559
+            extract_headers(RD, T, Acc);
  560
+        Val ->
  561
+            extract_headers(RD, T, [{Key, Val}|Acc])
  562
+    end.
  563
+
546 564
 %% @spec produce_doc_body(reqdata(), context()) -> {binary(), reqdata(), context()}
547 565
 %% @doc Extract the value of the document, and place it in the response
548 566
 %%      body of the request.

0 notes on commit 951eac6

Please sign in to comment.
Something went wrong with that request. Please try again.