add a proxy websocket test
git-svn-id: https://svn.apache.org/repos/asf/httpd/test/framework/trunk@1885580 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/README b/README
index 24d2ab6..e91d983 100644
--- a/README
+++ b/README
@@ -41,6 +41,8 @@
- IO::Socket::IP
- IO::Select
- LWP::Protocol::https
+- AnyEvent::WebSocket::Client;
+
Quick Start
-----------
diff --git a/t/conf/proxy.conf.in b/t/conf/proxy.conf.in
index ac87bb6..63bf338 100644
--- a/t/conf/proxy.conf.in
+++ b/t/conf/proxy.conf.in
@@ -167,6 +167,9 @@
</VirtualHost>
+
+ ProxyPass /proxy/wsoc ws://@SERVERNAME@:@PORT@/modules/lua/websockets.lua
+
</IfModule>
<IfModule mod_rewrite.c>
diff --git a/t/htdocs/modules/lua/websockets.lua b/t/htdocs/modules/lua/websockets.lua
new file mode 100644
index 0000000..1acd91b
--- /dev/null
+++ b/t/htdocs/modules/lua/websockets.lua
@@ -0,0 +1,13 @@
+function handle(r)
+if r:wsupgrade() then -- if we can upgrade:
+ while true do
+ local line, isFinal = r:wsread()
+ r:wswrite(line)
+ if line == "quit" then
+ r:wsclose() -- goodbye!
+ break
+ end
+
+ end
+end
+end
diff --git a/t/modules/proxy_wss.t b/t/modules/proxy_wss.t
new file mode 100644
index 0000000..eccce90
--- /dev/null
+++ b/t/modules/proxy_wss.t
@@ -0,0 +1,53 @@
+use strict;
+use warnings FATAL => 'all';
+
+use Apache::Test;
+use Apache::TestRequest;
+use Apache::TestUtil;
+use Apache::TestConfig ();
+
+use AnyEvent;
+use AnyEvent::WebSocket::Client;
+
+my $total_tests = 1;
+
+plan tests => $total_tests, need 'AnyEvent', need_module 'proxy_http', need_module 'lua', need_min_apache_version('2.5.1');
+;
+
+my $config = Apache::Test::config();
+my $hostport = Apache::TestRequest::hostport();
+
+my $client = AnyEvent::WebSocket::Client->new;
+
+my $quit_program = AnyEvent->condvar;
+
+my $pingok = 0;
+
+$client->connect("ws://$hostport/proxy/wsoc")->cb(sub {
+ our $connection = eval { shift->recv };
+ t_debug("connected");
+ if($@) {
+ # handle error...
+ warn $@;
+ return;
+ }
+
+
+ $connection->send('ping');
+
+ # recieve message from the websocket...
+ $connection->on(each_message => sub {
+ # $connection is the same connection object
+ # $message isa AnyEvent::WebSocket::Message
+ my($connection, $message) = @_;
+ t_debug("msg received: " . $message->body);
+ if ("ping" eq $message->body) {
+ $pingok = 1;
+ }
+ $connection->send('quit');
+ $quit_program->send();
+ });
+});
+
+$quit_program->recv;
+ok t_cmp($pingok, 1);