codegl / tracegl

traceGL support repository
84 stars 5 forks source link

Send correct hostname when in proxy mode #49

Open vyrus opened 11 years ago

vyrus commented 11 years ago

When traceGL proxyfies requests to some backend server, it transparently sends something like http://localhost:2080 in Host header of http request. This behaviour may be confusing for your backend if it was configured to use virtual hosts. So we need to add one line to send correct headers:

diff --git a/tracegl.js b/tracegl.js
index 1d6c2f2..4fd8823 100644
--- a/tracegl.js
+++ b/tracegl.js
@@ -4646,6 +4646,10 @@ define('/core/io_server',function(require){
            delete opt.headers['if-modified-since']
            delete opt.headers['content-security-policy']
            //}
+
+           // Send correct hostname to proxified server instead of "http://localhost:2080"
+           opt.headers['host'] = hs.proxy.hostname
+
            req.on('data', function(d){
                p_req.write(d)
            })
codegl commented 11 years ago

Thanks! I'll incorporate this in the next update today or tomorrow

JaapRood commented 11 years ago

Has this made it in yet? I work with virtual hosts and shit is hitting the fan

bermi commented 11 years ago

This patch introduced other issues when working in proxy mode, like sending websocket requests to the proxied hostname when they should be handled by tracegl.

andrezsanchez commented 11 years ago

I am also having this issue, which is preventing me from using tracegl where I would like to. I tried this patch, but it makes tracegl crash (right after it loads the site!).