You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by jh...@apache.org on 2013/02/13 14:17:14 UTC
[13/13] git commit: Use the traditional http_proxy for non-vhosted
requests (to avoid connection re-use)
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) <jh...@iriscouch.com>
Authored: Wed Feb 13 13:13:50 2013 +0000
Committer: Jason Smith (work) <jh...@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
.