couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject [13/13] git commit: Use the traditional http_proxy for non-vhosted requests (to avoid connection re-use)
Date Wed, 13 Feb 2013 13:17:14 GMT
Updated Branches:
  refs/heads/nodejs_couchdb 5f1f41832 -> f5ada5967


Use the traditional http_proxy for non-vhosted requests (to avoid connection re-use)


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

Branch: refs/heads/nodejs_couchdb
Commit: f5ada596732a1d2aca1cc230da6cd1f5a950ff52
Parents: 7b7dedb
Author: Jason Smith (work) <jhs@iriscouch.com>
Authored: Wed Feb 13 13:13:50 2013 +0000
Committer: Jason Smith (work) <jhs@iriscouch.com>
Committed: Wed Feb 13 13:13:50 2013 +0000

----------------------------------------------------------------------
 src/couchdb/couch_httpd_nodejs.erl |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/f5ada596/src/couchdb/couch_httpd_nodejs.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd_nodejs.erl b/src/couchdb/couch_httpd_nodejs.erl
index 5dfdbec..4793c98 100644
--- a/src/couchdb/couch_httpd_nodejs.erl
+++ b/src/couchdb/couch_httpd_nodejs.erl
@@ -25,7 +25,24 @@ handle_node_req(#httpd{}=Req) -> ok
         of nil -> ok
             , couch_httpd:send_json(Req, 502, {[ {error,no_app}, {name,AppName} ]})
         ; AppPort -> ok
-            %, io:format("Relay to :~p\n", [AppPort])
+            , handle_node_req(AppPort, Req)
+        end
+    .
+
+handle_node_req(AppPort, #httpd{mochi_req=MochiReq, path_parts=[Node_js | _Rest]}=Req) ->
ok
+    % Forward the request to Node.js. TCP relay is preferred for requests for a
+    % vhost, because socket.io works. However TCP cannot be used for direct
+    % requests (/_nodejs) because the client may re-use the connection for
+    % subsequent CouchDB requests, but they would go to Node instead.
+    %, io:format("Node req:\n~p\n", [Req])
+    , case MochiReq:get_header_value("x-couchdb-vhost-path")
+        of undefined -> ok
+            , Url = "http://127.0.0.1:" ++ integer_to_list(AppPort)
+                    ++ "/" ++ ?b2l(Node_js)
+            %, io:format("Manual proxy: ~p\n", [Url])
+            , couch_httpd_proxy:handle_proxy_req(Req, ?l2b(Url))
+        ; _Found -> ok
+            %, io:format("TCP relay: ~p\n", [AppPort])
             , relay(Req, AppPort)
         end
     .


Mime
View raw message