Commits

Jeffrey Gelens committed 01cfe4d

Tweaking response

Comments (0)

Files changed (2)

geventwebsocket/handler.py

 
         return self.server.logger
 
+    def start_response(self, status, headers, exc_info=None):
+        """
+        Called when the handler is ready to send a response back to the remote
+        endpoint. A websocket connection may have not been created.
+        """
+        writer = super(WebSocketHandler, self).start_response(
+            status, headers, exc_info=exc_info)
+
+        self._prepare_response()
+
+        return writer
+
+    def _prepare_response(self):
+        """
+        Sets up the ``pywsgi.Handler`` to work with a websocket response.
+
+        This is used by other projects that need to support WebSocket connections
+        as part of a larger effort.
+        """
+        assert not self.headers_sent
+
+        if not self.environ.get('wsgi.websocket'):
+            # a WebSocket connection is not established, do nothing
+            return
+
+        # so that `finalize_headers` doesn't write a Content-Length header
+        self.provided_content_length = False
+        # the websocket is now controlling the response
+        self.response_use_chunked = False
+        # once the request is over, the connection must be closed
+        self.close_connection = True
+        # prevents the Date header from being written
+        self.provided_date = True
+
 
 
 #class MessageHandler(object):
 #                break
 #            else:
 #                self.active_interface.on_message(message)
+

tests/run_autobahn_tests.py

 http://autobahn.ws/testsuite
 """
 import sys
-import os
 import subprocess
 import time
 import urllib2
 from twisted.internet import reactor
 from autobahntestsuite.fuzzing import FuzzingClientFactory
 
-
 spec = {
    "options": {"failByDrop": False},
    "enable-ssl": False,
    "servers": []}
 
 
-default_args = ["*",
-         "x7.5.1",
-         "x7.9.3",
-         "x7.9.4",
-         "x7.9.5",
-         "x7.9.6",
-         "x7.9.7",
-         "x7.9.8",
-         "x7.9.9",
-         "x7.9.10",
-         "x7.9.11",
-         "x7.9.12",
-         "x7.9.13"]
+default_args = ['*']
 # We ignore 7.5.1 because it checks that close frame has valid utf-8 message
 # we do not validate utf-8.
 
     import optparse
     parser = optparse.OptionParser()
     parser.add_option('--geventwebsocket', default='../examples/echoserver.py')
-    parser.add_option('--autobahn', default='../../src/Autobahn/testsuite/websockets/servers/test_autobahn.py')
     options, args = parser.parse_args()
 
+    # Load cases
     cases = []
     exclude_cases = []
 
     spec['cases'] = cases
     spec['exclude-cases'] = exclude_cases
 
-    if options.autobahn and not os.path.exists(options.autobahn):
-        print 'Ignoring %s (not found)' % options.autobahn
-        options.autobahn = None
-
     pool = ProcessPool()
 
     try:
         if options.geventwebsocket:
             pool.spawn([sys.executable, options.geventwebsocket])
-        if options.autobahn:
-            pool.spawn([sys.executable, options.autobahn])
 
         pool.wait(1)
 
         if options.geventwebsocket:
             agent = urllib2.urlopen('http://127.0.0.1:8000/version').read().strip()
+
             assert agent and '\n' not in agent and 'gevent-websocket' in agent, agent
+
             spec['servers'].append({"url": "ws://localhost:8000",
                                     "agent": agent,
-                                    "options": {"version": 17}})
-        if options.autobahn:
-            spec['servers'].append({'url': 'ws://localhost:8000/',
-                                    'agent': 'AutobahnServer',
-                                    'options': {'version': 17}})
+                                    "options": {"version": 18}})
 
         log.startLogging(sys.stdout)
+
+        # Start testing the server using the FuzzingClient
         FuzzingClientFactory(spec)
+
         reactor.run()
     finally:
         pool.kill()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.