Anonymous avatar Anonymous committed e515fe4

[mq]: link-header

Comments (0)

Files changed (2)

src/jiak_resource.erl

 %%          {io_list(), webmachine:wrq(), context()}
 %% @doc Get the representation of this resource that will be
 %%      sent to the client.
-produce_body(ReqData, Context=#ctx{key=container,module=Mod}) ->
+produce_body(ReqData, Context=#ctx{key=container,module=Mod,bucket=Bucket}) ->
     Qopts = wrq:req_qs(ReqData),
     Schema = case proplists:lookup("schema", Qopts) of
                  {"schema", "false"} -> [];
                                {ok, {K, NewCtx}} = retrieve_keylist(Context),
                                {[{keys, K}], NewCtx}
                        end,
+    KeyList = case Keys of
+        [{keys,Ks}] -> Ks;
+        _ -> []
+    end,
+    NewReqData = lists:foldl(fun(K,RD) ->
+                                     add_link_head(Bucket,K,"contained",RD)
+                             end,
+                             ReqData, KeyList),
     JSONSpec = {struct, Schema ++ Keys},
-    {mochijson2:encode(JSONSpec), ReqData, Context1};
-produce_body(ReqData, Context=#ctx{module=Module}) ->
+    {mochijson2:encode(JSONSpec), NewReqData, Context1};
+produce_body(ReqData, Context=#ctx{module=Module,bucket=Bucket}) ->
     {ok, {JiakObject0, Context1}} = retrieve_object(ReqData, Context),
     JiakObject = apply_read_mask(Module, JiakObject0),
+    {struct,JOProps} = JiakObject,
+    Links = proplists:get_value(<<"links">>, JOProps),
+    NewReqData = add_container_link(Bucket,
+                   lists:foldl(fun([B,K,T],RD) -> add_link_head(B,K,T,RD) end,
+                               ReqData, Links)),
     {mochijson2:encode(JiakObject),
      wrq:set_resp_header("X-JIAK-VClock",
                          binary_to_list(jiak_object:vclock(JiakObject)),
-                         ReqData),
+                         NewReqData),
      Context1}.    
 
+add_container_link(Bucket,ReqData) ->
+    Val = io_lib:format("</~s/~s>; rel=\"up\"",
+                    [riak:get_app_env(jiak_name, "jiak"),Bucket]),
+    wrq:merge_resp_headers([{"Link",Val}],ReqData).
+
+add_link_head(Bucket,Key,Tag,ReqData) ->
+    Val = io_lib:format("</~s/~s/~s>; riaktag=\"~s\"",
+                    [riak:get_app_env(jiak_name, "jiak"),Bucket, Key, Tag]),
+    wrq:merge_resp_headers([{"Link",Val}],ReqData).
+
 %% @spec full_schema(riak_object:bucket()) ->
 %%          [{schema_type(), [binary()]}]
 %% @type schema_type() = allowed_fields |

src/riak_bucketkeys.erl

 
 handle_cast({OpType,Bucket,Key},State=#state{ops=Ops}) ->
     BucketFrag = list_to_binary(
-                   lists:flatten(
-                     io_lib:format("~s-~b", 
-                                   [Bucket, 
-                                    erlang:phash2(Key) rem ?NFRAGS]))),
+                   [atom_to_list(Bucket),"-",
+                    integer_to_list(erlang:phash2(Key) rem ?NFRAGS)]),
     NewState = ensure_ring(State),
     OpList = case dict:find(BucketFrag, Ops) of
         error ->   [{OpType,Key}];
 
 %% @private 
 all_frags(Bucket) when is_atom(Bucket) ->
-    [list_to_binary(F) || F <- [atom_to_list(Bucket) ++ "-" ++ X || X <- [integer_to_list(I) || I <- lists:seq(0, ?NFRAGS-1)]]].
+    LB = atom_to_list(Bucket)++"-",
+    [list_to_binary(LB++integer_to_list(I)) || I <- lists:seq(0, ?NFRAGS-1)].
 %% @private
 ensure_ring(State=#state{ring=undefined}) ->
     riak_ring_manager:subscribe(self()),
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.