summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Smith (work) <jhs@iriscouch.com>2013-02-13 13:13:50 +0000
committerJason Smith (work) <jhs@iriscouch.com>2013-02-13 13:13:50 +0000
commitf5ada596732a1d2aca1cc230da6cd1f5a950ff52 (patch)
tree54b96309ba09b73041155596f2ba513dd352b8bd
parent7b7dedb2786a1db5f322da00a578fb74c677c3e9 (diff)
downloadcouchdb-nodejs_couchdb.tar.gz
Use the traditional http_proxy for non-vhosted requests (to avoid connection re-use)nodejs_couchdb
-rw-r--r--src/couchdb/couch_httpd_nodejs.erl19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/couchdb/couch_httpd_nodejs.erl b/src/couchdb/couch_httpd_nodejs.erl
index 5dfdbece0..4793c989d 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
.