Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
node-http-proxy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
node-http-proxy
Commits
4d18ac1a
Commit
4d18ac1a
authored
Apr 16, 2011
by
indexzero
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[test] Add WebSocket tests
parent
7cbf4473
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
115 additions
and
30 deletions
+115
-30
examples/web-socket-proxy.js
examples/web-socket-proxy.js
+1
-1
test/helpers.js
test/helpers.js
+3
-3
test/node-http-proxy-test.js
test/node-http-proxy-test.js
+0
-26
test/web-socket-proxy-test.js
test/web-socket-proxy-test.js
+111
-0
No files found.
examples/web-socket-proxy.js
View file @
4d18ac1a
...
...
@@ -26,7 +26,7 @@
var
sys
=
require
(
'
sys
'
),
http
=
require
(
'
http
'
),
websocket
=
require
(
'
./websocket
'
),
websocket
=
require
(
'
./
../vendor/
websocket
'
),
utils
=
require
(
'
socket.io/lib/socket.io/utils
'
),
io
=
require
(
'
socket.io
'
),
httpProxy
=
require
(
'
./../lib/node-http-proxy
'
);
...
...
test/helpers.js
View file @
4d18ac1a
...
...
@@ -90,7 +90,7 @@ TestRunner.prototype.startProxyServer = function (port, targetPort, host, callba
proxyServer
.
listen
(
port
,
function
()
{
that
.
testServers
.
push
(
proxyServer
);
callback
();
callback
(
null
,
proxyServer
);
});
};
...
...
@@ -160,7 +160,7 @@ TestRunner.prototype.startProxyServerWithForwarding = function (port, targetPort
var
that
=
this
,
proxyServer
=
httpProxy
.
createServer
(
targetPort
,
host
,
options
);
proxyServer
.
listen
(
port
,
function
()
{
that
.
testServers
.
push
(
proxyServer
);
callback
();
callback
(
null
,
proxyServer
);
});
};
...
...
@@ -176,7 +176,7 @@ TestRunner.prototype.startTargetServer = function (port, output, callback) {
targetServer
.
listen
(
port
,
function
()
{
that
.
testServers
.
push
(
targetServer
);
callback
();
callback
(
null
,
targetServer
);
});
};
...
...
test/node-http-proxy-test.js
View file @
4d18ac1a
...
...
@@ -80,32 +80,6 @@ vows.describe('node-http-proxy').addBatch({
}
}
}
}).
addBatch
({
"
When using server created by httpProxy.createServer()
"
:
{
"
an incoming WebSocket request to the helloNode server
"
:
{
"
with no latency
"
:
{
// Remark: This test is not working
/*topic: function () {
runner.startProxyServer(8086, 8087, 'localhost'),
runner.startTargetServer(8087, 'hello world');
var options = {
method: 'GET',
uri: 'http://localhost:8086',
headers: {
'Upgrade': 'WebSocket',
'Connection': 'WebSocket',
'Host': 'localhost'
}
};
request(options, this.callback);
},
"should receive 'hello world'": function (err, res, body) {
assert.equal(body, 'hello world');
}*/
}
}
}
}).
addBatch
({
"
When the tests are over
"
:
{
topic
:
function
()
{
...
...
test/web-socket-proxy-test.js
0 → 100644
View file @
4d18ac1a
/*
node-http-proxy-test.js: http proxy for node.js
Copyright (c) 2010 Charlie Robbins, Marak Squires and Fedor Indutny
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var
vows
=
require
(
'
vows
'
),
util
=
require
(
'
util
'
),
request
=
require
(
'
request
'
),
assert
=
require
(
'
assert
'
),
io
=
require
(
'
socket.io
'
),
utils
=
require
(
'
socket.io/lib/socket.io/utils
'
),
websocket
=
require
(
'
./../vendor/websocket
'
),
helpers
=
require
(
'
./helpers
'
);
var
runner
=
new
helpers
.
TestRunner
();
vows
.
describe
(
'
node-http-proxy/websocket
'
).
addBatch
({
"
When using server created by httpProxy.createServer()
"
:
{
"
with no latency
"
:
{
"
when an inbound message is sent from a WebSocket client
"
:
{
topic
:
function
()
{
var
that
=
this
;
runner
.
startTargetServer
(
8130
,
'
hello websocket
'
,
function
(
err
,
target
)
{
var
socket
=
io
.
listen
(
target
);
socket
.
on
(
'
connection
'
,
function
(
client
)
{
client
.
on
(
'
message
'
,
function
(
msg
)
{
that
.
callback
(
null
,
msg
);
});
});
runner
.
startProxyServer
(
8131
,
8130
,
'
localhost
'
,
function
(
err
,
proxy
)
{
//
// Setup the web socket against our proxy
//
var
ws
=
new
websocket
.
WebSocket
(
'
ws://localhost:8131/socket.io/websocket/
'
,
'
borf
'
);
ws
.
on
(
'
open
'
,
function
()
{
ws
.
send
(
utils
.
encode
(
'
from client
'
));
});
});
})
},
"
the target server should receive the message
"
:
function
(
err
,
msg
)
{
assert
.
equal
(
msg
,
'
from client
'
);
}
},
"
when an outbound message is sent from the target server
"
:
{
topic
:
function
()
{
var
that
=
this
;
runner
.
startTargetServer
(
8132
,
'
hello websocket
'
,
function
(
err
,
target
)
{
var
socket
=
io
.
listen
(
target
);
socket
.
on
(
'
connection
'
,
function
(
client
)
{
socket
.
broadcast
(
'
from server
'
);
});
runner
.
startProxyServer
(
8133
,
8132
,
'
localhost
'
,
function
(
err
,
proxy
)
{
//
// Setup the web socket against our proxy
//
var
ws
=
new
websocket
.
WebSocket
(
'
ws://localhost:8133/socket.io/websocket/
'
,
'
borf
'
);
ws
.
on
(
'
message
'
,
function
(
msg
)
{
msg
=
utils
.
decode
(
msg
);
if
(
!
/
\d
+/
.
test
(
msg
))
{
that
.
callback
(
null
,
msg
);
}
});
});
})
},
"
the client should receive the message
"
:
function
(
err
,
msg
)
{
assert
.
equal
(
msg
,
'
from server
'
);
}
}
}
}
}).
addBatch
({
"
When the tests are over
"
:
{
topic
:
function
()
{
return
runner
.
closeServers
();
},
"
the servers should clean up
"
:
function
()
{
assert
.
isTrue
(
true
);
}
}
}).
export
(
module
);
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment