You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by co...@apache.org on 2021/01/16 21:10:12 UTC

svn commit: r1885580 - in /httpd/test/framework/trunk: README t/conf/proxy.conf.in t/htdocs/modules/lua/websockets.lua t/modules/proxy_wss.t

Author: covener
Date: Sat Jan 16 21:10:12 2021
New Revision: 1885580

URL: http://svn.apache.org/viewvc?rev=1885580&view=rev
Log:
add a proxy websocket test


Added:
    httpd/test/framework/trunk/t/htdocs/modules/lua/websockets.lua
    httpd/test/framework/trunk/t/modules/proxy_wss.t
Modified:
    httpd/test/framework/trunk/README
    httpd/test/framework/trunk/t/conf/proxy.conf.in

Modified: httpd/test/framework/trunk/README
URL: http://svn.apache.org/viewvc/httpd/test/framework/trunk/README?rev=1885580&r1=1885579&r2=1885580&view=diff
==============================================================================
--- httpd/test/framework/trunk/README (original)
+++ httpd/test/framework/trunk/README Sat Jan 16 21:10:12 2021
@@ -41,6 +41,8 @@ that you have up to date versions of eac
 - IO::Socket::IP
 - IO::Select
 - LWP::Protocol::https
+- AnyEvent::WebSocket::Client;
+
 
 Quick Start 
 ----------- 

Modified: httpd/test/framework/trunk/t/conf/proxy.conf.in
URL: http://svn.apache.org/viewvc/httpd/test/framework/trunk/t/conf/proxy.conf.in?rev=1885580&r1=1885579&r2=1885580&view=diff
==============================================================================
--- httpd/test/framework/trunk/t/conf/proxy.conf.in (original)
+++ httpd/test/framework/trunk/t/conf/proxy.conf.in Sat Jan 16 21:10:12 2021
@@ -167,6 +167,9 @@
 
 
   </VirtualHost>
+
+   ProxyPass /proxy/wsoc ws://@SERVERNAME@:@PORT@/modules/lua/websockets.lua
+ 
 </IfModule>
 
 <IfModule mod_rewrite.c>

Added: httpd/test/framework/trunk/t/htdocs/modules/lua/websockets.lua
URL: http://svn.apache.org/viewvc/httpd/test/framework/trunk/t/htdocs/modules/lua/websockets.lua?rev=1885580&view=auto
==============================================================================
--- httpd/test/framework/trunk/t/htdocs/modules/lua/websockets.lua (added)
+++ httpd/test/framework/trunk/t/htdocs/modules/lua/websockets.lua Sat Jan 16 21:10:12 2021
@@ -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

Added: httpd/test/framework/trunk/t/modules/proxy_wss.t
URL: http://svn.apache.org/viewvc/httpd/test/framework/trunk/t/modules/proxy_wss.t?rev=1885580&view=auto
==============================================================================
--- httpd/test/framework/trunk/t/modules/proxy_wss.t (added)
+++ httpd/test/framework/trunk/t/modules/proxy_wss.t Sat Jan 16 21:10:12 2021
@@ -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);