rnewson commented on code in PR #6063:
URL: https://github.com/apache/couchdb/pull/6063#discussion_r3613742857


##########
src/chttpd/src/chttpd.erl:
##########
@@ -840,6 +841,29 @@ body(#httpd{mochi_req = MochiReq, req_body = ReqBody}) ->
 validate_ctype(Req, Ctype) ->
     couch_httpd:validate_ctype(Req, Ctype).
 
+peer(#httpd{} = Req) ->
+    peer(Req#httpd.mochi_req);
+peer(MochiReq) ->
+    case config:get("chttpd", "peer_header") of
+        undefined ->
+            peer_from_socket(MochiReq);
+        PeerHeader ->
+            case MochiReq:get_header_value(PeerHeader) of
+                undefined ->
+                    peer_from_socket(MochiReq);
+                Peer ->
+                    Peer
+            end
+    end.
+
+peer_from_socket(MochiReq) ->
+    case MochiReq:get(socket) of
+        {remote, _Pid, _} ->
+            nopeer;
+        _ ->
+            MochiReq:get(peer)
+    end.

Review Comment:
   I don't love the (near-) duplication but also mindful that requests through 
5986 are rare. There might be users where that happens in a meaningful way (and 
they might want to choose a custom peer header), but I figure almost everyone 
would set the chttpd config variable only, so I wanted to leave the slightly 
different handling in couch_httpd alone by default.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to