summaryrefslogtreecommitdiff
path: root/src/couchdb/couch_httpd_auth.erl
diff options
context:
space:
mode:
authorFilipe David Borba Manana <fdmanana@apache.org>2010-08-04 10:36:35 +0000
committerFilipe David Borba Manana <fdmanana@apache.org>2010-08-04 10:36:35 +0000
commitaea47cc3831fd7b5a8c926557ad79cffbe9639ef (patch)
treebf2ec65b7f4630b75aa0a0b8c3957d2c868fd100 /src/couchdb/couch_httpd_auth.erl
parent495c20b9856b2abcbdc5a4620d6b4304dcafd70d (diff)
Allow POSTing of a JSON object to /_session/ for login.
Closes COUCHDB-842, patch by Jonathan D. Knezek. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@982200 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_httpd_auth.erl')
-rw-r--r--src/couchdb/couch_httpd_auth.erl6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/couchdb/couch_httpd_auth.erl b/src/couchdb/couch_httpd_auth.erl
index 7023e7f3..f76898e1 100644
--- a/src/couchdb/couch_httpd_auth.erl
+++ b/src/couchdb/couch_httpd_auth.erl
@@ -247,13 +247,17 @@ ensure_cookie_auth_secret() ->
% session handlers
% Login handler with user db
-% TODO this should also allow a JSON POST
handle_session_req(#httpd{method='POST', mochi_req=MochiReq}=Req) ->
ReqBody = MochiReq:recv_body(),
Form = case MochiReq:get_primary_header_value("content-type") of
% content type should be json
"application/x-www-form-urlencoded" ++ _ ->
mochiweb_util:parse_qs(ReqBody);
+ "application/json" ++ _ ->
+ {Pairs} = ?JSON_DECODE(ReqBody),
+ lists:map(fun({Key, Value}) ->
+ {?b2l(Key), ?b2l(Value)}
+ end, Pairs);
_ ->
[]
end,