Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow passing arbitrary headers #157

Closed
wants to merge 1 commit into from

3 participants

@mrunalp

We are using ws library for our websocket proxy server in openshift - https://github.com/openshift/origin-server/tree/master/node-proxy

With the way things are today, there isn't a way to pass down headers such as "Cookie".
Adding this code will make it easier to use ws within proxy servers.

@einaros
Owner

I'd love to see some tests around this, other than that I will merge.

@einaros einaros closed this
@3rd-Eden 3rd-Eden reopened this
@3rd-Eden
Owner

Just a heads up, i'm gonna take your pull request and a small test for it. So this will be in the next release so people can send proper cookie headers.

@3rd-Eden 3rd-Eden closed this
@3rd-Eden 3rd-Eden referenced this pull request from a commit
@3rd-Eden 3rd-Eden [fix] Allow custom headers. 43a0b2b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 30, 2013
  1. @mrunalp

    Allow passing custom headers.

    mrunalp authored
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 1 deletion.
  1. +10 −1 lib/WebSocket.js
View
11 lib/WebSocket.js
@@ -393,7 +393,8 @@ function initAsClient(address, options) {
origin: null,
protocolVersion: protocolVersion,
host: null,
- protocol: null
+ protocol: null,
+ headers: null
}).merge(options);
if (options.value.protocolVersion != 8 && options.value.protocolVersion != 13) {
throw new Error('unsupported protocol version');
@@ -445,6 +446,14 @@ function initAsClient(address, options) {
requestOptions.headers['Host'] = options.value.host;
}
+ if (options.value.headers) {
+ for (var key in options.value.headers) {
+ if (!requestOptions.headers.hasOwnProperty(key)) {
+ requestOptions.headers[key] = options.value.headers[key];
+ }
+ }
+ }
+
if (isNodeV4) {
requestOptions.path = (serverUrl.pathname || '/') + (serverUrl.search || '');
requestOptions.agent = agent;
Something went wrong with that request. Please try again.