-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changing headers should be an option #34
Comments
What happens if you modify request.headers directly before they get proxied out? |
I think you understood me wrong. It would be better if i could specify if I want to keep the original headers or change them. |
Here? https://github.com/nodejitsu/node-http-proxy/blob/master/lib/node-http-proxy.js#L589 I'm not sure if this is by design due to the websocket protocol or not. I will reread that part of the spec and follow-up on this. |
@indexzero - I think I'm running into a related issue here without websockets. I think the disconnect is in the fact that http-proxy acts as a proxy server by default. This means that the receiving server can tell the request has been proxied. In other words, it's not transparent. The proxy should act in this mode by default, but we should probably expose an API option to enable "transparent" proxying. I'm not sure if there is a better name for that. Here is a more clear illustration of the problem:
Does that make any sense? |
I ran into an issue with this recently. In my client (Google Chrome 10), I was getting this while attempting to make a connection to a websocket server behind node-http-proxy: Error during WebSocket handshake: origin mismatch: http://127.0.0.1:8071 != http://127.0.0.1 It turns out this was due to the issue mentioned here of changing the request headers. After this patch: --- /tmp/orig // Change headers
outgoing = { the error stops and the websocket connections work fine. |
This is why I posted this issue. I had the same problem. |
The websocket support was originally written by @donnerjack13589 and later updated by @davglass. Maybe they can chime in on the reasoning behind changing the outgoing headers. I will kill those lines in |
If you're going to kill those lines, please have a look a little further down. There is code to replace the host and origin which wouldn't need to happen. Also, this section currently does not support ports other than 80. |
Updates on this? I'm getting an origin mismatch when proxying https => http |
@olauzon can you take a look at this ticket? I'd like to get this resolved this week if possible. |
@Marak definitely, will investigate. |
Thanks @olauzon! Feel free to post your status in this thread. |
Great! Should be a pretty simple fix in there. Maybe we can summon @miksago or @donnerjack13589 to help shed some light on the underlying websocket spec and why these headers need to be changed (or don't) @donnerjack13589 wrote the original implementation here, it's like 4am in Russia tho so he might not be around |
So what's the issue? Most websocket implementations will be reading the headers of origin and host, as well as the various sec- ones. If you're proxying websockets and adding, say, a "x-" to the front of these headers, then the websocket implementations will break. I think it's probably best not to modify headers on websocket requests. As for the specification, I don't think it defines as to how proxies should interact with headers, @donnerjack13589 may know otherwise. I might also ask the guys I work with as to whether they can shed light, but they're in BST / GMT timezone. |
@miksago Thanks. The problem is that currently Based on what you said, I guess we should just not be rewriting these headers at all? |
I still think it would be best, if ther was an option. For example when someone tries to forward wss:// to an internal ws:// server. Then we would have an origin mismatch. |
how would wss to ws work? that isn't to say changing headers is never necessary the code to change headers and replace host and origin in the handshake is very deliberate code i'm referring to:
...
|
@jfis Again, this is a symptom of a larger problem. I am working on something in the experimental branch, but I'm not sure if we can actually write a websocket proxy on top of the existing http.Agent APIs without event emitter leaks. |
@indexzero i don't see how changing the headers and replacing host and origin in the handshake relates to http.Agent but I'll take your word for it. I do see the problem with http.Agent in the other thread (#50) though. |
@jfis They are only related in that they both have to do with websockets. If this gets fixed, that is still a problem and websockets is still broken. |
@indexzero :) ok gotcha. |
This is fixed in 9c6c4b9. WebSockets (ws://) and Secure WebSockets (wss://) should be 100% now. Added new functional tests, but if anyone wants to do a benchmark that would be awesome. |
just double-checking: it's currently not possible to proxy could we add this to the docs? |
This is actually possible. See the docs under "Proxying HTTPS to HTTP" ... this also works for websockets |
In a https://github.com/nodejitsu/node-http-proxy/blob/master/lib/node-http-proxy.js#L632 All possible values for the protocol in |
Hmm maybe not Origin, but location. This is what I get in the console: |
also, as noted somewhere above, |
@frank06 Can you provide sample code to reproduce the problem? |
It tries to replace remoteHost with options.host during the handshake.
This replacement only needs to happen when the newly introduced changeOrigin parameter is true. fail conditions:
wasteful conditions:
to demonstrate |
|
@olauzon ... Any progress on this issue today? Ping me if you're blocked. |
Ping. Is this still an issue? |
Yes. @olauzon do you want to take a look? |
I wanted to tack on this issue I had that's possibly related: The host wasn't being modified by http-proxy, the repercussion being that Heroku couldn't redirect you to the correct app. I had to set the Would be useful to note in the readme that transparent proxies aren't enabled by default. |
I looked into the source a little and there -is- an option to change the host header by setting the option
This could definitely be an error somewhere on my part though. |
@lezhang If that code sample fixed your issue, this is not related to |
changing the headers "location" & "origin" when proxying websocket request should be an option, because this is important to make the proxying behave like "not happened".
The text was updated successfully, but these errors were encountered: