You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ii...@apache.org on 2019/10/01 18:08:28 UTC

[couchdb] 05/08: Add helper functions to work with contexts

This is an automated email from the ASF dual-hosted git repository.

iilyak pushed a commit to branch opentracing
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit fd9331ce1fb9bdc9def784172901a927f2f68c5c
Author: ILYA Khlopotov <ii...@apache.org>
AuthorDate: Tue Oct 1 15:59:01 2019 +0000

    Add helper functions to work with contexts
---
 src/chttpd/src/chttpd.erl | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/chttpd/src/chttpd.erl b/src/chttpd/src/chttpd.erl
index 704e203..e00088d 100644
--- a/src/chttpd/src/chttpd.erl
+++ b/src/chttpd/src/chttpd.erl
@@ -44,7 +44,9 @@
 
 -export([
     chunked_response_buffer_size/0,
-    close_delayed_json_object/4
+    close_delayed_json_object/4,
+    contexts_to_list/1,
+    set_contexts/2
 ]).
 
 -record(delayed_resp, {
@@ -1237,6 +1239,14 @@ span_ok(_Resp) ->
 span_error(_ErrorStr, _ReasonStr, []) ->
     fun(Span) -> Span end.
 
+contexts_to_list(Req) ->
+    set_contexts(Req, []).
+
+set_contexts(#httpd{user_ctx=UserCtx, request_ctx=RequestCtx}, KVList0) ->
+    KVList1 = lists:keystore(request_ctx, 1, KVList0, {request_ctx, RequestCtx}),
+    KVList2 = lists:keystore(user_ctx, 1, KVList1, {user_ctx, UserCtx}),
+    KVList2.
+
 -ifdef(TEST).
 
 -include_lib("eunit/include/eunit.hrl").