couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iil...@apache.org
Subject [14/50] couch-httpd commit: updated refs/heads/split_out_httpd_stack to e44a372
Date Tue, 01 Mar 2016 20:00:47 GMT
Merge start_chunked_response/3 and send_response/4


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/commit/38073bb9
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/tree/38073bb9
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/diff/38073bb9

Branch: refs/heads/split_out_httpd_stack
Commit: 38073bb988e47a40c50131d2fdbf597e11914db8
Parents: cf6dead
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Thu Feb 25 11:52:34 2016 -0800
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Tue Mar 1 08:35:07 2016 -0800

----------------------------------------------------------------------
 src/couch_httpd.erl          | 46 ++++++++++++++++++++++-----
 src/couch_httpd_original.erl | 65 +++------------------------------------
 2 files changed, 43 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/blob/38073bb9/src/couch_httpd.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd.erl b/src/couch_httpd.erl
index 90016f0..aff29fe 100644
--- a/src/couch_httpd.erl
+++ b/src/couch_httpd.erl
@@ -143,11 +143,13 @@ start_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers) ->
     {ok, Resp}.
 
 start_chunked_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers0) ->
+    log_request(Req, Code),
     couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
-    Headers1 = Headers0 ++ server_header() ++
-        couch_httpd_auth:cookie_auth_header(Req, Headers0),
-    Headers2 = couch_httpd_cors:headers(Req, Headers1),
-    Resp = MochiReq:respond({Code, Headers2, chunked}),
+    Headers1 = http_1_0_keep_alive(MochiReq, Headers0),
+    Headers2 = Headers1 ++ server_header() ++
+        couch_httpd_auth:cookie_auth_header(Req, Headers1),
+    Headers3 = couch_httpd_cors:headers(Req, Headers2),
+    Resp = MochiReq:respond({Code, Headers3, chunked}),
     case MochiReq:get(method) of
     'HEAD' -> throw({http_head_abort, Resp});
     _ -> ok
@@ -210,11 +212,21 @@ start_delayed_json_response(Req, Code, Headers, FirstChunk) ->
         headers = Headers,
         first_chunk = FirstChunk}}.
 
-send_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers0, Body) ->
+send_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers, Body) ->
+    log_request(Req, Code),
     couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
-    Headers = Headers0 ++ server_header() ++
-	[timing(), reqid() | couch_httpd_auth:cookie_auth_header(Req, Headers0)],
-    {ok, MochiReq:respond({Code, Headers, Body})}.
+    Headers1 = http_1_0_keep_alive(MochiReq, Headers),
+    if Code >= 500 ->
+        couch_log:error("httpd ~p error response:~n ~s", [Code, Body]);
+    Code >= 400 ->
+        couch_log:debug("httpd ~p error response:~n ~s", [Code, Body]);
+    true -> ok
+    end,
+    Headers2 = Headers1 ++ server_header() ++
+               [timing(), reqid() | couch_httpd_auth:cookie_auth_header(Req, Headers1)],
+    Headers3 = couch_httpd_cors:cors_headers(Req, Headers2),
+
+    {ok, MochiReq:respond({Code, Headers3, Body})}.
 
 send_json(Req, Value) ->
     send_json(Req, 200, Value).
@@ -822,6 +834,24 @@ end_jsonp() ->
         _ -> ");"
     end.
 
+http_1_0_keep_alive(Req, Headers) ->
+    KeepOpen = Req:should_close() == false,
+    IsHttp10 = Req:get(version) == {1, 0},
+    NoRespHeader = no_resp_conn_header(Headers),
+    case KeepOpen andalso IsHttp10 andalso NoRespHeader of
+        true -> [{"Connection", "Keep-Alive"} | Headers];
+        false -> Headers
+    end.
+
+no_resp_conn_header([]) ->
+    true;
+no_resp_conn_header([{Hdr, _} | Rest]) ->
+    case string:to_lower(Hdr) of
+        "connection" -> false;
+        _ -> no_resp_conn_header(Rest)
+    end.
+
+
 negotiate_content_type(_Req) ->
     case get(jsonp) of
         no_jsonp -> "application/json";

http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/blob/38073bb9/src/couch_httpd_original.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd_original.erl b/src/couch_httpd_original.erl
index 8195e46..29f9845 100644
--- a/src/couch_httpd_original.erl
+++ b/src/couch_httpd_original.erl
@@ -20,10 +20,9 @@
 -export([make_fun_spec_strs/1]).
 
 
--export([start_chunked_response/3]).
--export([send_response/4,send_error/2,send_error/4, send_chunked_error/2]).
+-export([send_error/2,send_error/4, send_chunked_error/2]).
 -export([accepted_encodings/1,handle_request_int/5,validate_referer/1]).
--export([http_1_0_keep_alive/2]).
+
 -export([validate_host/1]).
 -export([validate_bind_address/1]).
 
@@ -69,7 +68,9 @@
     start_reponse/3,
     start_response_length/4,
     send_chunk/2,
-    etag_maybe/2
+    etag_maybe/2,
+    send_response/4,
+    start_chunked_response/3
 ]).
 
 -define(HANDLER_NAME_IN_MODULE_POS, 6).
@@ -487,62 +488,6 @@ verify_is_server_admin(#user_ctx{roles=Roles}) ->
     false -> throw({unauthorized, <<"You are not a server admin.">>})
     end.
 
-
-no_resp_conn_header([]) ->
-    true;
-no_resp_conn_header([{Hdr, _}|Rest]) ->
-    case string:to_lower(Hdr) of
-        "connection" -> false;
-        _ -> no_resp_conn_header(Rest)
-    end.
-
-http_1_0_keep_alive(Req, Headers) ->
-    KeepOpen = Req:should_close() == false,
-    IsHttp10 = Req:get(version) == {1, 0},
-    NoRespHeader = no_resp_conn_header(Headers),
-    case KeepOpen andalso IsHttp10 andalso NoRespHeader of
-        true -> [{"Connection", "Keep-Alive"} | Headers];
-        false -> Headers
-    end.
-
-start_chunked_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers) ->
-    log_request(Req, Code),
-    couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
-    Headers1 = http_1_0_keep_alive(MochiReq, 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
-    'HEAD' -> throw({http_head_abort, Resp});
-    _ -> ok
-    end,
-    {ok, Resp}.
-
-
-send_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers, Body) ->
-    log_request(Req, Code),
-    couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
-    Headers1 = http_1_0_keep_alive(MochiReq, Headers),
-    if Code >= 500 ->
-        couch_log:error("httpd ~p error response:~n ~s", [Code, Body]);
-    Code >= 400 ->
-        couch_log:debug("httpd ~p error response:~n ~s", [Code, Body]);
-    true -> ok
-    end,
-    Headers2 = Headers1 ++ server_header() ++
-               couch_httpd_auth:cookie_auth_header(Req, Headers1),
-    Headers3 = couch_httpd_cors:cors_headers(Req, Headers2),
-
-    {ok, MochiReq:respond({Code, Headers3, Body})}.
-
-
-
-
-
-
-
-
 error_info({Error, Reason}) when is_list(Reason) ->
     error_info({Error, ?l2b(Reason)});
 error_info(bad_request) ->


Mime
View raw message