Permalink
Browse files

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...
1 parent 2dc13c5 commit 951eac690253bc85e046f4066df5983120343697 @rzezeski rzezeski committed with Vagabond Mar 2, 2011
Showing with 19 additions and 1 deletion.
  1. +19 −1 src/luwak_wm_file.erl
View
@@ -124,6 +124,7 @@
-define(HEAD_RANGE, "Range").
-define(HEAD_CRANGE, "Content-Range").
+-define(HEAD_BLOCK_SZ, "X-Luwak-Block-Size").
%% @spec init(proplist()) -> {ok, context()}
%% @doc Initialize this resource. This function extracts the
@@ -495,7 +496,8 @@ accept_doc_body(RD, Ctx=#ctx{key=K, client=C}) ->
H0 = case Ctx#ctx.handle of
{ok, H} -> H;
_ ->
- {ok, H} = luwak_file:create(C, K, dict:new()),
+ FileProps = extract_file_props(RD),
+ {ok, H} = luwak_file:create(C, K, FileProps, dict:new()),
H
end,
{ok,H1} = luwak_file:set_attributes(C, H0, UserMetaMD),
@@ -543,6 +545,22 @@ extract_user_meta(RD) ->
end,
mochiweb_headers:to_list(wrq:req_headers(RD))).
+%% @spec extract_file_props(reqdata()) -> proplists()
+%% @doc Extract Luwak file properties from custom headers prefixed by
+%% X-Luwak- in the client's request.
+extract_file_props(RD) ->
+ extract_headers(RD, [{block_size, ?HEAD_BLOCK_SZ}], []).
+
+extract_headers(_RD, [], Acc) ->
+ Acc;
+extract_headers(RD, [{Key, Header}|T], Acc) ->
+ case wrq:get_req_header(Header, RD) of
+ undefined ->
+ extract_headers(RD, T, Acc);
+ Val ->
+ extract_headers(RD, T, [{Key, Val}|Acc])
+ end.
+
%% @spec produce_doc_body(reqdata(), context()) -> {binary(), reqdata(), context()}
%% @doc Extract the value of the document, and place it in the response
%% body of the request.

0 comments on commit 951eac6

Please sign in to comment.