From: Peter Lemenkov <lemenkov@gmail.com>
Date: Thu, 14 Mar 2019 18:11:38 +0300
Subject: [PATCH] Remove tuple calls from Erlang 21
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl
index 781276006..ccdec0538 100644
--- a/src/couchdb/couch_httpd.erl
+++ b/src/couchdb/couch_httpd.erl
@@ -142,7 +142,7 @@ start_link(Name, Options) ->
[] ->
ok;
_ ->
- ok = mochiweb_socket:setopts(Req:get(socket), SocketOptions)
+ ok = mochiweb_socket:setopts(mochiweb_request:get(socket, Req), SocketOptions)
end,
apply(?MODULE, handle_request, [
Req, DefaultFun, UrlHandlers, DbUrlHandlers, DesignUrlHandlers
@@ -243,15 +243,15 @@ handle_request_int(MochiReq, DefaultFun,
Begin = erlang:timestamp(),
% for the path, use the raw path with the query string and fragment
% removed, but URL quoting left intact
- RawUri = MochiReq:get(raw_path),
+ RawUri = mochiweb_request:get(raw_path, MochiReq),
{"/" ++ Path, _, _} = mochiweb_util:urlsplit_path(RawUri),
- Headers = MochiReq:get(headers),
+ Headers = mochiweb_request:get(headers, MochiReq),
% get requested path
- RequestedPath = case MochiReq:get_header_value("x-couchdb-vhost-path") of
+ RequestedPath = case mochiweb_request:get_header_value("x-couchdb-vhost-path", MochiReq) of
undefined ->
- case MochiReq:get_header_value("x-couchdb-requested-path") of
+ case mochiweb_request:get_header_value("x-couchdb-requested-path", MochiReq) of
undefined -> RawUri;
R -> R
end;
@@ -266,15 +266,15 @@ handle_request_int(MochiReq, DefaultFun,
list_to_binary(FirstPart)
end,
?LOG_DEBUG("~p ~s ~p from ~p~nHeaders: ~p", [
- MochiReq:get(method),
+ mochiweb_request:get(method, MochiReq),
RawUri,
- MochiReq:get(version),
- MochiReq:get(peer),
- mochiweb_headers:to_list(MochiReq:get(headers))
+ mochiweb_request:get(version, MochiReq),
+ mochiweb_request:get(peer, MochiReq),
+ mochiweb_headers:to_list(mochiweb_request:get(headers, MochiReq))
]),
Method1 =
- case MochiReq:get(method) of
+ case mochiweb_request:get(method, MochiReq) of
% already an atom
Meth when is_atom(Meth) -> Meth;
@@ -285,7 +285,7 @@ handle_request_int(MochiReq, DefaultFun,
increment_method_stats(Method1),
% allow broken HTTP clients to fake a full method vocabulary with an X-HTTP-METHOD-OVERRIDE header
- MethodOverride = MochiReq:get_primary_header_value("X-HTTP-Method-Override"),
+ MethodOverride = mochiweb_request:get_primary_header_value("X-HTTP-Method-Override", MochiReq),
Method2 = case lists:member(MethodOverride, ["GET", "HEAD", "POST",
"PUT", "DELETE",
"TRACE", "CONNECT",
@@ -311,7 +311,7 @@ handle_request_int(MochiReq, DefaultFun,
HttpReq = #httpd{
mochi_req = MochiReq,
- peer = MochiReq:get(peer),
+ peer = mochiweb_request:get(peer, MochiReq),
method = Method,
requested_path_parts =
[?l2b(unquote(Part)) || Part <- string:tokens(RequestedPath, "/")],
@@ -487,19 +487,19 @@ partition(Path) ->
mochiweb_util:partition(Path, "/").
header_value(#httpd{mochi_req=MochiReq}, Key) ->
- MochiReq:get_header_value(Key).
+ mochiweb_request:get_header_value(Key, MochiReq).
header_value(#httpd{mochi_req=MochiReq}, Key, Default) ->
- case MochiReq:get_header_value(Key) of
+ case mochiweb_request:get_header_value(Key, MochiReq) of
undefined -> Default;
Value -> Value
end.
primary_header_value(#httpd{mochi_req=MochiReq}, Key) ->
- MochiReq:get_primary_header_value(Key).
+ mochiweb_request:get_primary_header_value(Key, MochiReq).
accepted_encodings(#httpd{mochi_req=MochiReq}) ->
- case MochiReq:accepted_encodings(["gzip", "identity"]) of
+ case mochiweb_request:accepted_encodings(["gzip", "identity"], MochiReq) of
bad_accept_encoding_value ->
throw(bad_accept_encoding_value);
[] ->
@@ -517,8 +517,8 @@ serve_file(#httpd{mochi_req=MochiReq}=Req, RelativePath, DocumentRoot,
ResponseHeaders = server_header()
++ couch_httpd_auth:cookie_auth_header(Req, [])
++ ExtraHeaders,
- {ok, MochiReq:serve_file(RelativePath, DocumentRoot,
- couch_httpd_cors:cors_headers(Req, ResponseHeaders))}.
+ {ok, mochiweb_request:serve_file(RelativePath, DocumentRoot,
+ couch_httpd_cors:cors_headers(Req, ResponseHeaders), MochiReq)}.
qs_value(Req, Key) ->
qs_value(Req, Key, undefined).
@@ -535,18 +535,18 @@ qs_json_value(Req, Key, Default) ->
end.
qs(#httpd{mochi_req=MochiReq}) ->
- MochiReq:parse_qs().
+ mochiweb_request:parse_qs(MochiReq).
path(#httpd{mochi_req=MochiReq}) ->
- MochiReq:get(path).
+ mochiweb_request:get(path, MochiReq).
host_for_request(#httpd{mochi_req=MochiReq}) ->
XHost = couch_config:get("httpd", "x_forwarded_host", "X-Forwarded-Host"),
- case MochiReq:get_header_value(XHost) of
+ case mochiweb_request:get_header_value(XHost, MochiReq) of
undefined ->
- case MochiReq:get_header_value("Host") of
+ case mochiweb_request:get_header_value("Host", MochiReq) of
undefined ->
- {ok, {Address, Port}} = case MochiReq:get(socket) of
+ {ok, {Address, Port}} = case mochiweb_request:get(socket, MochiReq) of
{ssl, SslSocket} -> ssl:sockname(SslSocket);
Socket -> inet:sockname(Socket)
end,
@@ -560,14 +560,14 @@ host_for_request(#httpd{mochi_req=MochiReq}) ->
absolute_uri(#httpd{mochi_req=MochiReq}=Req, Path) ->
Host = host_for_request(Req),
XSsl = couch_config:get("httpd", "x_forwarded_ssl", "X-Forwarded-Ssl"),
- Scheme = case MochiReq:get_header_value(XSsl) of
+ Scheme = case mochiweb_request:get_header_value(XSsl, MochiReq) of
"on" -> "https";
_ ->
XProto = couch_config:get("httpd", "x_forwarded_proto", "X-Forwarded-Proto"),
- case MochiReq:get_header_value(XProto) of
+ case mochiweb_request:get_header_value(XProto, MochiReq) of
%% Restrict to "https" and "http" schemes only
"https" -> "https";
- _ -> case MochiReq:get(scheme) of
+ _ -> case mochiweb_request:get(scheme, MochiReq) of
https -> "https";
http -> "http"
end
@@ -585,21 +585,21 @@ parse_form(#httpd{mochi_req=MochiReq}) ->
mochiweb_multipart:parse_form(MochiReq).
recv(#httpd{mochi_req=MochiReq}, Len) ->
- MochiReq:recv(Len).
+ mochiweb_request:recv(Len, MochiReq).
recv_chunked(#httpd{mochi_req=MochiReq}, MaxChunkSize, ChunkFun, InitState) ->
% Fun is called once with each chunk
% Fun({Length, Binary}, State)
% called with Length == 0 on the last time.
- MochiReq:stream_body(MaxChunkSize, ChunkFun, InitState).
+ mochiweb_request:stream_body(MaxChunkSize, ChunkFun, InitState, MochiReq).
body_length(#httpd{mochi_req=MochiReq}) ->
- MochiReq:get(body_length).
+ mochiweb_request:get(body_length, MochiReq).
body(#httpd{mochi_req=MochiReq, req_body=undefined}) ->
MaxSize = list_to_integer(
couch_config:get("couchdb", "max_document_size", "4294967296")),
- MochiReq:recv_body(MaxSize);
+ mochiweb_request:recv_body(MaxSize, MochiReq);
body(#httpd{req_body=ReqBody}) ->
ReqBody.
@@ -668,8 +668,8 @@ verify_is_server_admin(#user_ctx{roles=Roles}) ->
log_request(#httpd{mochi_req=MochiReq,peer=Peer}=Req, Code) ->
?LOG_INFO("~s - - ~s ~s ~B", [
Peer,
- MochiReq:get(method),
- MochiReq:get(raw_path),
+ mochiweb_request:get(method, MochiReq),
+ mochiweb_request:get(raw_path, MochiReq),
Code
]),
gen_event:notify(couch_plugin, {log_request, Req, Code}).
@@ -681,8 +681,8 @@ start_response_length(#httpd{mochi_req=MochiReq}=Req, Code, Headers, Length) ->
Headers1 = Headers ++ server_header() ++
couch_httpd_auth:cookie_auth_header(Req, Headers),
Headers2 = couch_httpd_cors:cors_headers(Req, Headers1),
- Resp = MochiReq:start_response_length({Code, Headers2, Length}),
- case MochiReq:get(method) of
+ Resp = mochiweb_request:start_response_length({Code, Headers2, Length}, MochiReq),
+ case mochiweb_request:get(method, MochiReq) of
'HEAD' -> throw({http_head_abort, Resp});
_ -> ok
end,
@@ -694,15 +694,15 @@ start_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers) ->
CookieHeader = couch_httpd_auth:cookie_auth_header(Req, Headers),
Headers1 = Headers ++ server_header() ++ CookieHeader,
Headers2 = couch_httpd_cors:cors_headers(Req, Headers1),
- Resp = MochiReq:start_response({Code, Headers2}),
- case MochiReq:get(method) of
+ Resp = mochiweb_request:start_response({Code, Headers2}, MochiReq),
+ case mochiweb_request:get(method, MochiReq) of
'HEAD' -> throw({http_head_abort, Resp});
_ -> ok
end,
{ok, Resp}.
send(Resp, Data) ->
- Resp:send(Data),
+ mochiweb_response:send(Data, Resp),
{ok, Resp}.
no_resp_conn_header([]) ->
@@ -714,8 +714,8 @@ no_resp_conn_header([{Hdr, _}|Rest]) ->
end.
http_1_0_keep_alive(Req, Headers) ->
- KeepOpen = Req:should_close() == false,
- IsHttp10 = Req:get(version) == {1, 0},
+ KeepOpen = mochiweb_request:should_close(Req) == false,
+ IsHttp10 = mochiweb_request:get(version, Req) == {1, 0},
NoRespHeader = no_resp_conn_header(Headers),
case KeepOpen andalso IsHttp10 andalso NoRespHeader of
true -> [{"Connection", "Keep-Alive"} | Headers];
@@ -729,8 +729,8 @@ start_chunked_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers) ->
Headers2 = Headers1 ++ server_header() ++
couch_httpd_auth:cookie_auth_header(Req, Headers1),
Headers3 = couch_httpd_cors:cors_headers(Req, Headers2),
- Resp = MochiReq:respond({Code, Headers3, chunked}),
- case MochiReq:get(method) of
+ Resp = mochiweb_request:respond({Code, Headers3, chunked}, MochiReq),
+ case mochiweb_request:get(method, MochiReq) of
'HEAD' -> throw({http_head_abort, Resp});
_ -> ok
end,
@@ -739,12 +739,12 @@ start_chunked_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers) ->
send_chunk(Resp, Data) ->
case iolist_size(Data) of
0 -> ok; % do nothing
- _ -> Resp:write_chunk(Data)
+ _ -> mochiweb_response:write_chunk(Data, Resp)
end,
{ok, Resp}.
last_chunk(Resp) ->
- Resp:write_chunk([]),
+ mochiweb_response:write_chunk([], Resp),
{ok, Resp}.
send_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers, Body) ->
@@ -761,7 +761,7 @@ send_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers, Body) ->
couch_httpd_auth:cookie_auth_header(Req, Headers1),
Headers3 = couch_httpd_cors:cors_headers(Req, Headers2),
- {ok, MochiReq:respond({Code, Headers3, Body})}.
+ {ok, mochiweb_request:respond({Code, Headers3, Body}, MochiReq)}.
send_method_not_allowed(Req, Methods) ->
send_error(Req, 405, [{"Allow", Methods}], <<"method_not_allowed">>, ?l2b("Only " ++ Methods ++ " allowed")).
@@ -919,7 +919,7 @@ error_info(Error) ->
error_headers(#httpd{mochi_req=MochiReq}=Req, Code, ErrorStr, ReasonStr) ->
if Code == 401 ->
% this is where the basic auth popup is triggered
- case MochiReq:get_header_value("X-CouchDB-WWW-Authenticate") of
+ case mochiweb_request:get_header_value("X-CouchDB-WWW-Authenticate", MochiReq) of
undefined ->
case couch_config:get("httpd", "WWW-Authenticate", nil) of
nil ->
@@ -935,17 +935,17 @@ error_headers(#httpd{mochi_req=MochiReq}=Req, Code, ErrorStr, ReasonStr) ->
% send the browser popup header no matter what if we are require_valid_user
{Code, [{"WWW-Authenticate", "Basic realm=\"server\""}]};
_False ->
- case MochiReq:accepts_content_type("application/json") of
+ case mochiweb_request:accepts_content_type("application/json", MochiReq) of
true ->
{Code, []};
false ->
- case MochiReq:accepts_content_type("text/html") of
+ case mochiweb_request:accepts_content_type("text/html", MochiReq) of
true ->
% Redirect to the path the user requested, not
% the one that is used internally.
- UrlReturnRaw = case MochiReq:get_header_value("x-couchdb-vhost-path") of
+ UrlReturnRaw = case mochiweb_request:get_header_value("x-couchdb-vhost-path", MochiReq) of
undefined ->
- MochiReq:get(path);
+ mochiweb_request:get(path, MochiReq);
VHostPath ->
VHostPath
end,
@@ -1018,7 +1018,7 @@ negotiate_content_type1(#httpd{mochi_req=MochiReq}) ->
%% depending on the Accept header in the request. A request that explicitly
%% lists the correct JSON MIME type will get that type, otherwise the
%% response will have the generic MIME type "text/plain"
- AcceptedTypes = case MochiReq:get_header_value("Accept") of
+ AcceptedTypes = case mochiweb_request:get_header_value("Accept", MochiReq) of
undefined -> [];
AcceptHeader -> string:tokens(AcceptHeader, ", ")
end,
diff --git a/src/couchdb/couch_httpd_auth.erl b/src/couchdb/couch_httpd_auth.erl
index 6001e1392..c9258ebee 100644
--- a/src/couchdb/couch_httpd_auth.erl
+++ b/src/couchdb/couch_httpd_auth.erl
@@ -160,7 +160,7 @@ proxy_auth_user(Req) ->
cookie_authentication_handler(#httpd{mochi_req=MochiReq}=Req) ->
- case MochiReq:get_cookie_value("AuthSession") of
+ case mochiweb_request:get_cookie_value("AuthSession", MochiReq) of
undefined -> Req;
[] -> Req;
Cookie ->
@@ -250,8 +250,8 @@ ensure_cookie_auth_secret() ->
% session handlers
% Login handler with user db
handle_session_req(#httpd{method='POST', mochi_req=MochiReq}=Req) ->
- ReqBody = MochiReq:recv_body(),
- Form = case MochiReq:get_primary_header_value("content-type") of
+ ReqBody = mochiweb_request:recv_body(MochiReq),
+ Form = case mochiweb_request:get_primary_header_value("content-type", MochiReq) of
% content type should be json
"application/x-www-form-urlencoded" ++ _ ->
mochiweb_util:parse_qs(ReqBody);
@@ -401,7 +401,7 @@ make_cookie_time() ->
cookie_scheme(#httpd{mochi_req=MochiReq}) ->
[{http_only, true}] ++
- case MochiReq:get(scheme) of
+ case mochiweb_request:get(scheme, MochiReq) of
http -> [];
https -> [{secure, true}]
end.
diff --git a/src/couchdb/couch_httpd_cors.erl b/src/couchdb/couch_httpd_cors.erl
index d9462d1a1..ac42c9b39 100644
--- a/src/couchdb/couch_httpd_cors.erl
+++ b/src/couchdb/couch_httpd_cors.erl
@@ -65,7 +65,7 @@ is_preflight_request(#httpd{mochi_req=MochiReq}=Req, true) ->
preflight_request(MochiReq) ->
- Origin = MochiReq:get_header_value("Origin"),
+ Origin = mochiweb_request:get_header_value("Origin", MochiReq),
preflight_request(MochiReq, Origin).
preflight_request(MochiReq, undefined) ->
@@ -128,7 +128,7 @@ handle_preflight_request(Origin, Host, MochiReq) ->
{"Access-Control-Allow-Methods",
string:join(SupportedMethods, ", ")}]),
- case MochiReq:get_header_value("Access-Control-Request-Method") of
+ case mochiweb_request:get_header_value("Access-Control-Request-Method", MochiReq) of
undefined ->
% If there is no Access-Control-Request-Method header
% or if parsing failed, do not set any additional headers
@@ -140,8 +140,8 @@ handle_preflight_request(Origin, Host, MochiReq) ->
case lists:member(Method, SupportedMethods) of
true ->
% method ok , check headers
- AccessHeaders = MochiReq:get_header_value(
- "Access-Control-Request-Headers"),
+ AccessHeaders = mochiweb_request:get_header_value(
+ "Access-Control-Request-Headers", MochiReq),
{FinalReqHeaders, ReqHeaders} = case AccessHeaders of
undefined -> {"", []};
Headers ->
@@ -178,7 +178,7 @@ send_preflight_response(#httpd{mochi_req=MochiReq}=Req, Headers) ->
Headers1 = couch_httpd:http_1_0_keep_alive(MochiReq, Headers),
Headers2 = Headers1 ++ couch_httpd:server_header() ++
couch_httpd_auth:cookie_auth_header(Req, Headers1),
- {ok, MochiReq:respond({204, Headers2, <<>>})}.
+ {ok, mochiweb_request:respond({204, Headers2, <<>>}, MochiReq)}.
% cors_headers/1
@@ -191,7 +191,7 @@ cors_headers(MochiReq, RequestHeaders) ->
do_cors_headers(#httpd{mochi_req=MochiReq}, true) ->
Host = couch_httpd_vhost:host(MochiReq),
AcceptedOrigins = get_accepted_origins(Host),
- case MochiReq:get_header_value("Origin") of
+ case mochiweb_request:get_header_value("Origin", MochiReq) of
undefined ->
% If the Origin header is not present terminate
% this set of steps. The request is outside the scope
diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl
index 8f8ba7ff9..93410f161 100644
--- a/src/couchdb/couch_httpd_db.erl
+++ b/src/couchdb/couch_httpd_db.erl
@@ -466,7 +466,7 @@ db_req(#httpd{path_parts=[_,<<"_revs_limit">>]}=Req, _Db) ->
% as slashes in document IDs must otherwise be URL encoded.
db_req(#httpd{method='GET',mochi_req=MochiReq, path_parts=[DbName,<<"_design/",_/binary>>|_]}=Req, _Db) ->
PathFront = "/" ++ couch_httpd:quote(binary_to_list(DbName)) ++ "/",
- [_|PathTail] = re:split(MochiReq:get(raw_path), "_design%2F",
+ [_|PathTail] = re:split(mochiweb_request:get(raw_path, MochiReq), "_design%2F",
[{return, list}]),
couch_httpd:send_redirect(Req, PathFront ++ "_design/" ++
mochiweb_util:join(PathTail, "_design%2F"));
@@ -531,7 +531,7 @@ db_doc_req(#httpd{method = 'GET', mochi_req = MochiReq} = Req, Db, DocId) ->
send_doc(Req, Doc, Options);
_ ->
{ok, Results} = couch_db:open_doc_revs(Db, DocId, Revs, Options),
- case MochiReq:accepts_content_type("multipart/mixed") of
+ case mochiweb_request:accepts_content_type("multipart/mixed", MochiReq) of
false ->
{ok, Resp} = start_json_response(Req, 200),
send_chunk(Resp, "["),
@@ -650,7 +650,7 @@ send_doc_efficiently(#httpd{mochi_req = MochiReq} = Req,
#doc{atts = Atts} = Doc, Headers, Options) ->
case lists:member(attachments, Options) of
true ->
- case MochiReq:accepts_content_type("multipart/related") of
+ case mochiweb_request:accepts_content_type("multipart/related", MochiReq) of
false ->
send_json(Req, 200, Headers, couch_doc:to_json_obj(Doc, Options));
true ->
@@ -923,7 +923,7 @@ db_attachment_req(#httpd{method='GET',mochi_req=MochiReq}=Req, Db, DocId, FileNa
AttFun(Att, fun(Seg, _) -> send_chunk(Resp, Seg) end, {ok, Resp}),
last_chunk(Resp);
_ ->
- Ranges = parse_ranges(MochiReq:get(range), Len),
+ Ranges = parse_ranges(mochiweb_request:get(range, MochiReq), Len),
case {Enc, Ranges} of
{identity, [{From, To}]} ->
Headers1 = [{"Content-Range", make_content_range(From, To, Len)}]
@@ -991,7 +991,7 @@ db_attachment_req(#httpd{method=Method,mochi_req=MochiReq}=Req, Db, DocId, FileN
end,
case Expect of
"100-continue" ->
- MochiReq:start_raw_response({100, gb_trees:empty()});
+ mochiweb_request:start_raw_response({100, gb_trees:empty()}, MochiReq);
_Else ->
ok
end,
diff --git a/src/couchdb/couch_httpd_external.erl b/src/couchdb/couch_httpd_external.erl
index 2036d252e..613eb3712 100644
--- a/src/couchdb/couch_httpd_external.erl
+++ b/src/couchdb/couch_httpd_external.erl
@@ -64,10 +64,10 @@ json_req_obj(#httpd{mochi_req=Req,
undefined ->
MaxSize = list_to_integer(
couch_config:get("couchdb", "max_document_size", "4294967296")),
- Req:recv_body(MaxSize);
+ mochiweb_request:recv_body(MaxSize, Req);
Else -> Else
end,
- ParsedForm = case Req:get_primary_header_value("content-type") of
+ ParsedForm = case mochiweb_request:get_primary_header_value("content-type", Req) of
"application/x-www-form-urlencoded" ++ _ ->
case Body of
undefined -> [];
@@ -76,7 +76,7 @@ json_req_obj(#httpd{mochi_req=Req,
_ ->
[]
end,
- Headers = Req:get(headers),
+ Headers = mochiweb_request:get(headers, Req),
Hlist = mochiweb_headers:to_list(Headers),
{ok, Info} = couch_db:get_db_info(Db),
@@ -87,13 +87,13 @@ json_req_obj(#httpd{mochi_req=Req,
{<<"method">>, Method},
{<<"requested_path">>, RequestedPath},
{<<"path">>, Path},
- {<<"raw_path">>, ?l2b(Req:get(raw_path))},
- {<<"query">>, json_query_keys(to_json_terms(Req:parse_qs()))},
+ {<<"raw_path">>, ?l2b(mochiweb_request:get(raw_path, Req))},
+ {<<"query">>, json_query_keys(to_json_terms(mochiweb_request:parse_qs(Req)))},
{<<"headers">>, to_json_terms(Hlist)},
{<<"body">>, Body},
- {<<"peer">>, ?l2b(Req:get(peer))},
+ {<<"peer">>, ?l2b(mochiweb_request:get(peer, Req))},
{<<"form">>, to_json_terms(ParsedForm)},
- {<<"cookie">>, to_json_terms(Req:parse_cookie())},
+ {<<"cookie">>, to_json_terms(mochiweb_request:parse_cookie(Req))},
{<<"userCtx">>, couch_util:json_user_ctx(Db)},
{<<"secObj">>, couch_db:get_security(Db)}]}.
diff --git a/src/couchdb/couch_httpd_oauth.erl b/src/couchdb/couch_httpd_oauth.erl
index 60a937cc5..abf9e4cde 100644
--- a/src/couchdb/couch_httpd_oauth.erl
+++ b/src/couchdb/couch_httpd_oauth.erl
@@ -40,7 +40,7 @@ oauth_auth_callback(Req, #callback_params{token_secret = undefined}) ->
Req, 400, <<"invalid_token">>, <<"Invalid OAuth token.">>);
oauth_auth_callback(#httpd{mochi_req = MochiReq} = Req, CbParams) ->
- Method = atom_to_list(MochiReq:get(method)),
+ Method = atom_to_list(mochiweb_request:get(method, MochiReq)),
#callback_params{
consumer = Consumer,
token = Token,
@@ -180,7 +180,7 @@ serve_oauth(#httpd{mochi_req=MochiReq}=Req, Fun, FailSilently) ->
% 1. In the HTTP Authorization header as defined in OAuth HTTP Authorization Scheme.
% 2. As the HTTP POST request body with a content-type of application/x-www-form-urlencoded.
% 3. Added to the URLs in the query part (as defined by [RFC3986] section 3).
- AuthHeader = case MochiReq:get_header_value("authorization") of
+ AuthHeader = case mochiweb_request:get_header_value("authorization", MochiReq) of
undefined ->
"";
Else ->
@@ -194,11 +194,11 @@ serve_oauth(#httpd{mochi_req=MochiReq}=Req, Fun, FailSilently) ->
%Realm = couch_util:get_value("realm", HeaderParams),
% get requested path
- RequestedPath = case MochiReq:get_header_value("x-couchdb-requested-path") of
+ RequestedPath = case mochiweb_request:get_header_value("x-couchdb-requested-path", MochiReq) of
undefined ->
- case MochiReq:get_header_value("x-couchdb-vhost-path") of
+ case mochiweb_request:get_header_value("x-couchdb-vhost-path", MochiReq) of
undefined ->
- MochiReq:get(raw_path);
+ mochiweb_request:get(raw_path, MochiReq);
VHostPath ->
VHostPath
end;
@@ -289,7 +289,7 @@ sig_method_1(_) ->
ok(#httpd{mochi_req=MochiReq}, Body) ->
- {ok, MochiReq:respond({200, [], Body})}.
+ {ok, mochiweb_request:respond({200, [], Body}, MochiReq)}.
oauth_credentials_info(Token, ConsumerKey) ->
diff --git a/src/couchdb/couch_httpd_proxy.erl b/src/couchdb/couch_httpd_proxy.erl
index eb037b447..56f69a2de 100644
--- a/src/couchdb/couch_httpd_proxy.erl
+++ b/src/couchdb/couch_httpd_proxy.erl
@@ -41,7 +41,7 @@ handle_proxy_req(Req, ProxyDest) ->
get_method(#httpd{mochi_req=MochiReq}) ->
- case MochiReq:get(method) of
+ case mochiweb_request:get(method, MochiReq) of
Method when is_atom(Method) ->
list_to_atom(string:to_lower(atom_to_list(Method)));
Method when is_list(Method) ->
@@ -59,7 +59,7 @@ get_url(#httpd{mochi_req=MochiReq}=Req, ProxyDest) ->
_ -> ProxyDest
end,
ProxyPrefix = "/" ++ ?b2l(hd(Req#httpd.path_parts)),
- RequestedPath = MochiReq:get(raw_path),
+ RequestedPath = mochiweb_request:get(raw_path, MochiReq),
case mochiweb_util:partition(RequestedPath, ProxyPrefix) of
{[], ProxyPrefix, []} ->
BaseUrl;
@@ -72,11 +72,11 @@ get_url(#httpd{mochi_req=MochiReq}=Req, ProxyDest) ->
end.
get_version(#httpd{mochi_req=MochiReq}) ->
- MochiReq:get(version).
+ mochiweb_request:get(version, MochiReq).
get_headers(#httpd{mochi_req=MochiReq}) ->
- to_ibrowse_headers(mochiweb_headers:to_list(MochiReq:get(headers)), []).
+ to_ibrowse_headers(mochiweb_headers:to_list(mochiweb_request:get(headers, MochiReq)), []).
to_ibrowse_headers([], Acc) ->
lists:reverse(Acc);
@@ -100,7 +100,7 @@ get_body(#httpd{method='HEAD'}) ->
get_body(#httpd{method='DELETE'}) ->
fun() -> eof end;
get_body(#httpd{mochi_req=MochiReq}) ->
- case MochiReq:get(body_length) of
+ case mochiweb_request:get(body_length, MochiReq) of
undefined ->
<<>>;
{unknown_transfer_encoding, Unknown} ->
@@ -159,7 +159,7 @@ stream_chunked_body({stream, MReq, CRem, Buf, BRem}) when BRem =< 0 ->
stream_chunked_body({stream, MReq, CRem, Buf, BRem}) ->
% Buffer some more data from the client.
Length = lists:min([CRem, BRem]),
- Socket = MReq:get(socket),
+ Socket = mochiweb_request:get(socket, MReq),
NewState = case mochiweb_socket:recv(Socket, Length, ?TIMEOUT) of
{ok, Data} when size(Data) == CRem ->
case mochiweb_socket:recv(Socket, 2, ?TIMEOUT) of
@@ -181,7 +181,7 @@ stream_chunked_body({trailers, MReq, Buf, BRem}) when BRem =< 0 ->
stream_chunked_body({trailers, MReq, Buf, BRem}) ->
% Read another trailer into the buffer or stop on an
% empty line.
- Socket = MReq:get(socket),
+ Socket = mochiweb_request:get(socket, MReq),
mochiweb_socket:setopts(Socket, [{packet, line}]),
case mochiweb_socket:recv(Socket, 0, ?TIMEOUT) of
{ok, <<"\r\n">>} ->
@@ -209,14 +209,14 @@ stream_length_body({stream, _MochiReq, 0}) ->
eof;
stream_length_body({stream, MochiReq, Length}) ->
BufLen = lists:min([Length, ?PKT_SIZE]),
- case MochiReq:recv(BufLen) of
+ case mochiweb_request:recv(BufLen, MochiReq) of
<<>> -> eof;
Bin -> {ok, Bin, {stream, MochiReq, Length-BufLen}}
end.
init_body_stream(MochiReq) ->
- Expect = case MochiReq:get_header_value("expect") of
+ Expect = case mochiweb_request:get_header_value("expect", MochiReq) of
undefined ->
undefined;
Value when is_list(Value) ->
@@ -224,14 +224,14 @@ init_body_stream(MochiReq) ->
end,
case Expect of
"100-continue" ->
- MochiReq:start_raw_response({100, gb_trees:empty()});
+ mochiweb_request:start_raw_response({100, gb_trees:empty()}, MochiReq);
_Else ->
ok
end.
read_chunk_length(MochiReq) ->
- Socket = MochiReq:get(socket),
+ Socket = mochiweb_request:get(socket, MochiReq),
mochiweb_socket:setopts(Socket, [{packet, line}]),
case mochiweb_socket:recv(Socket, 0, ?TIMEOUT) of
{ok, Header} ->
diff --git a/src/couchdb/couch_httpd_rewrite.erl b/src/couchdb/couch_httpd_rewrite.erl
index 4354215f0..1e9c76dad 100644
--- a/src/couchdb/couch_httpd_rewrite.erl
+++ b/src/couchdb/couch_httpd_rewrite.erl
@@ -174,20 +174,20 @@ handle_rewrite_req(#httpd{
% requested path. We use default so chained rewriting
% wont replace the original header.
Headers = mochiweb_headers:default("x-couchdb-requested-path",
- MochiReq:get(raw_path),
- MochiReq:get(headers)),
+ mochiweb_request:get(raw_path, MochiReq),
+ mochiweb_request:get(headers, MochiReq)),
?LOG_DEBUG("rewrite to ~p ~n", [RawPath1]),
% build a new mochiweb request
- MochiReq1 = mochiweb_request:new(MochiReq:get(socket),
- MochiReq:get(method),
+ MochiReq1 = mochiweb_request:new(mochiweb_request:get(socket, MochiReq),
+ mochiweb_request:get(method, MochiReq),
RawPath1,
- MochiReq:get(version),
+ mochiweb_request:get(version, MochiReq),
Headers),
% cleanup, It force mochiweb to reparse raw uri.
- MochiReq1:cleanup(),
+ mochiweb_request:cleanup(MochiReq1),
#httpd{
db_url_handlers = DbUrlHandlers,
diff --git a/src/couchdb/couch_httpd_vhost.erl b/src/couchdb/couch_httpd_vhost.erl
index 4c3ebfebe..74ef12692 100644
--- a/src/couchdb/couch_httpd_vhost.erl
+++ b/src/couchdb/couch_httpd_vhost.erl
@@ -95,7 +95,7 @@ dispatch_host(MochiReq) ->
vhosts = VHosts,
vhosts_fun=Fun} = get_state(),
- {"/" ++ VPath, Query, Fragment} = mochiweb_util:urlsplit_path(MochiReq:get(raw_path)),
+ {"/" ++ VPath, Query, Fragment} = mochiweb_util:urlsplit_path(mochiweb_request:get(raw_path, MochiReq)),
VPathParts = string:tokens(VPath, "/"),
VHost = host(MochiReq),
@@ -110,11 +110,11 @@ dispatch_host(MochiReq) ->
_Else ->
NewPath1 = mochiweb_util:urlunsplit_path({NewPath, Query,
Fragment}),
- MochiReq1 = mochiweb_request:new(MochiReq:get(socket),
- MochiReq:get(method),
+ MochiReq1 = mochiweb_request:new(mochiweb_request:get(socket, MochiReq),
+ mochiweb_request:get(method, MochiReq),
NewPath1,
- MochiReq:get(version),
- MochiReq:get(headers)),
+ mochiweb_request:get(version, MochiReq),
+ mochiweb_request:get(headers, MochiReq)),
Fun(MochiReq1, VhostTarget)
end
end,
@@ -127,29 +127,29 @@ append_path(Target, Path) ->
% default redirect vhost handler
redirect_to_vhost(MochiReq, VhostTarget) ->
- Path = MochiReq:get(raw_path),
+ Path = mochiweb_request:get(raw_path, MochiReq),
Target = append_path(VhostTarget, Path),
?LOG_DEBUG("Vhost Target: '~p'~n", [Target]),
Headers = mochiweb_headers:enter("x-couchdb-vhost-path", Path,
- MochiReq:get(headers)),
+ mochiweb_request:get(headers, MochiReq)),
% build a new mochiweb request
- MochiReq1 = mochiweb_request:new(MochiReq:get(socket),
- MochiReq:get(method),
+ MochiReq1 = mochiweb_request:new(mochiweb_request:get(socket, MochiReq),
+ mochiweb_request:get(method, MochiReq),
Target,
- MochiReq:get(version),
+ mochiweb_request:get(version, MochiReq),
Headers),
% cleanup, It force mochiweb to reparse raw uri.
- MochiReq1:cleanup(),
+ mochiweb_request:cleanup(MochiReq1),
MochiReq1.
%% if so, then it will not be rewritten, but will run as a normal couchdb request.
%* normally you'd use this for _uuids _utils and a few of the others you want to
%% keep available on vhosts. You can also use it to make databases 'global'.
vhost_global( VhostGlobals, MochiReq) ->
- RawUri = MochiReq:get(raw_path),
+ RawUri = mochiweb_request:get(raw_path, MochiReq),
{"/" ++ Path, _, _} = mochiweb_util:urlsplit_path(RawUri),
Front = case couch_httpd:partition(Path) of
@@ -239,9 +239,9 @@ bind_path(_, _) ->
host(MochiReq) ->
XHost = couch_config:get("httpd", "x_forwarded_host",
"X-Forwarded-Host"),
- case MochiReq:get_header_value(XHost) of
+ case mochiweb_request:get_header_value(XHost, MochiReq) of
undefined ->
- case MochiReq:get_header_value("Host") of
+ case mochiweb_request:get_header_value("Host", MochiReq) of
undefined -> [];
Value1 -> Value1
end;
diff --git a/test/couchdb/couchdb_http_proxy_tests.erl b/test/couchdb/couchdb_http_proxy_tests.erl
index 2f6e4159e..13a72630e 100644
--- a/test/couchdb/couchdb_http_proxy_tests.erl
+++ b/test/couchdb/couchdb_http_proxy_tests.erl
@@ -99,10 +99,10 @@ http_proxy_test_() ->
should_proxy_basic_request(_) ->
Remote = fun(Req) ->
- 'GET' = Req:get(method),
- "/" = Req:get(path),
- 0 = Req:get(body_length),
- <<>> = Req:recv_body(),
+ 'GET' = mochiweb_request:get(method, Req),
+ "/" = mochiweb_request:get(path, Req),
+ 0 = mochiweb_request:get(body_length, Req),
+ <<>> = mochiweb_request:recv_body(Req),
{ok, {200, [{"Content-Type", "text/plain"}], "ok"}}
end,
Local = fun
@@ -115,7 +115,7 @@ should_proxy_basic_request(_) ->
should_return_alternative_status(_) ->
Remote = fun(Req) ->
- "/alternate_status" = Req:get(path),
+ "/alternate_status" = mochiweb_request:get(path, Req),
{ok, {201, [], "ok"}}
end,
Local = fun
@@ -129,7 +129,7 @@ should_return_alternative_status(_) ->
should_respect_trailing_slash(_) ->
Remote = fun(Req) ->
- "/trailing_slash/" = Req:get(path),
+ "/trailing_slash/" = mochiweb_request:get(path, Req),
{ok, {200, [], "ok"}}
end,
Local = fun
@@ -143,8 +143,8 @@ should_respect_trailing_slash(_) ->
should_proxy_headers(_) ->
Remote = fun(Req) ->
- "/passes_header" = Req:get(path),
- "plankton" = Req:get_header_value("X-CouchDB-Ralph"),
+ "/passes_header" = mochiweb_request:get(path, Req),
+ "plankton" = mochiweb_request:get_header_value("X-CouchDB-Ralph", Req),
{ok, {200, [], "ok"}}
end,
Local = fun
@@ -161,8 +161,8 @@ should_proxy_headers(_) ->
should_proxy_host_header(_) ->
Remote = fun(Req) ->
- "/passes_host_header" = Req:get(path),
- "www.google.com" = Req:get_header_value("Host"),
+ "/passes_host_header" = mochiweb_request:get(path, Req),
+ "www.google.com" = mochiweb_request:get_header_value("Host", Req),
{ok, {200, [], "ok"}}
end,
Local = fun
@@ -179,7 +179,7 @@ should_proxy_host_header(_) ->
should_pass_headers_back(_) ->
Remote = fun(Req) ->
- "/passes_header_back" = Req:get(path),
+ "/passes_header_back" = mochiweb_request:get(path, Req),
{ok, {200, [{"X-CouchDB-Plankton", "ralph"}], "ok"}}
end,
Local = fun
@@ -193,8 +193,8 @@ should_pass_headers_back(_) ->
should_use_same_protocol_version(_) ->
Remote = fun(Req) ->
- "/uses_same_version" = Req:get(path),
- {1, 0} = Req:get(version),
+ "/uses_same_version" = mochiweb_request:get(path, Req),
+ {1, 0} = mochiweb_request:get(version, Req),
{ok, {200, [], "ok"}}
end,
Local = fun
@@ -211,9 +211,9 @@ should_use_same_protocol_version(_) ->
should_proxy_body(_) ->
Remote = fun(Req) ->
- 'PUT' = Req:get(method),
- "/passes_body" = Req:get(path),
- <<"Hooray!">> = Req:recv_body(),
+ 'PUT' = mochiweb_request:get(method, Req),
+ "/passes_body" = mochiweb_request:get(path, Req),
+ <<"Hooray!">> = mochiweb_request:recv_body(Req),
{ok, {201, [], "ok"}}
end,
Local = fun
@@ -232,8 +232,8 @@ should_proxy_body(_) ->
should_proxy_body_back(_) ->
BodyChunks = [<<"foo">>, <<"bar">>, <<"bazinga">>],
Remote = fun(Req) ->
- 'GET' = Req:get(method),
- "/passes_eof_body" = Req:get(path),
+ 'GET' = mochiweb_request:get(method, Req),
+ "/passes_eof_body" = mochiweb_request:get(path, Req),
{raw, {200, [{"Connection", "close"}], BodyChunks}}
end,
Local = fun
@@ -248,8 +248,8 @@ should_proxy_body_back(_) ->
should_proxy_chunked_body(_) ->
BodyChunks = [<<"foo">>, <<"bar">>, <<"bazinga">>],
Remote = fun(Req) ->
- 'POST' = Req:get(method),
- "/passes_chunked_body" = Req:get(path),
+ 'POST' = mochiweb_request:get(method, Req),
+ "/passes_chunked_body" = mochiweb_request:get(path, Req),
RecvBody = fun
({Length, Chunk}, [Chunk | Rest]) ->
Length = size(Chunk),
@@ -257,7 +257,7 @@ should_proxy_chunked_body(_) ->
({0, []}, []) ->
ok
end,
- ok = Req:stream_body(1024 * 1024, RecvBody, BodyChunks),
+ ok = mochiweb_request:stream_body(1024 * 1024, RecvBody, BodyChunks, Req),
{ok, {201, [], "ok"}}
end,
Local = fun
@@ -277,8 +277,8 @@ should_proxy_chunked_body(_) ->
should_proxy_chunked_body_back(_) ->
?_test(begin
Remote = fun(Req) ->
- 'GET' = Req:get(method),
- "/passes_chunked_body_back" = Req:get(path),
+ 'GET' = mochiweb_request:get(method, Req),
+ "/passes_chunked_body_back" = mochiweb_request:get(path, Req),
BodyChunks = [<<"foo">>, <<"bar">>, <<"bazinga">>],
{chunked, {200, [{"Transfer-Encoding", "chunked"}], BodyChunks}}
end,
@@ -368,7 +368,7 @@ do_rewrite_tests(Tests) ->
should_rewrite_header(Header, Location, Url) ->
Remote = fun(Req) ->
- "/rewrite_test" = Req:get(path),
+ "/rewrite_test" = mochiweb_request:get(path, Req),
{ok, {302, [{Header, Location}], "ok"}}
end,
Local = fun
diff --git a/test/couchdb/test_web.erl b/test/couchdb/test_web.erl
index e7e598497..5fe8f9703 100644
--- a/test/couchdb/test_web.erl
+++ b/test/couchdb/test_web.erl
@@ -35,22 +35,22 @@ loop(Req) ->
%?debugFmt("Handling request: ~p", [Req]),
case gen_server:call(?HANDLER, {check_request, Req}) of
{ok, RespInfo} ->
- {ok, Req:respond(RespInfo)};
+ {ok, mochiweb_request:respond(RespInfo, Req)};
{raw, {Status, Headers, BodyChunks}} ->
- Resp = Req:start_response({Status, Headers}),
- lists:foreach(fun(C) -> Resp:send(C) end, BodyChunks),
+ Resp = mochiweb_request:start_response({Status, Headers}, Req),
+ lists:foreach(fun(C) -> mochiweb_response:send(C, Resp) end, BodyChunks),
erlang:put(mochiweb_request_force_close, true),
{ok, Resp};
{chunked, {Status, Headers, BodyChunks}} ->
- Resp = Req:respond({Status, Headers, chunked}),
+ Resp = mochiweb_request:respond({Status, Headers, chunked}, Req),
timer:sleep(?DELAY),
- lists:foreach(fun(C) -> Resp:write_chunk(C) end, BodyChunks),
- Resp:write_chunk([]),
+ lists:foreach(fun(C) -> mochiweb_response:write_chunk(C, Resp) end, BodyChunks),
+ mochiweb_response:write_chunk([], Resp),
{ok, Resp};
{error, Reason} ->
?debugFmt("Error: ~p", [Reason]),
Body = lists:flatten(io_lib:format("Error: ~p", [Reason])),
- {ok, Req:respond({200, [], Body})}
+ {ok, mochiweb_request:respond({200, [], Body}, Req)}
end.
get_port() ->
@@ -83,7 +83,7 @@ handle_call({check_request, Req}, _From, State) when is_function(State, 1) ->
Error ->
{reply, {error, Error}, not_ok}
end,
- Req:cleanup(),
+ mochiweb_request:cleanup(Req),
Resp2;
handle_call({check_request, _Req}, _From, _State) ->
{reply, {error, no_assert_function}, not_ok};