Пример #1
0
 def test_not_strictly_good_requests(self):
     for request in _create_requests_with_lines(_NOT_STRICTLY_GOOD_REQUESTS):
         strict_handshaker = handshake.Handshaker(request,
                                                  mock.MockDispatcher(),
                                                  True)
         self.assertRaises(handshake.HandshakeError,
                           strict_handshaker.do_handshake)
Пример #2
0
def headerparserhandler(request):
    """Handle request.

    Args:
        request: mod_python request.

    This function is named headerparserhandler because it is the default name
    for a PythonHeaderParserHandler.
    """

    try:
        allowDraft75 = apache.main_server.get_options().get(
            _PYOPT_ALLOW_DRAFT75, None)
        handshaker = handshake.Handshaker(request,
                                          _dispatcher,
                                          allowDraft75=allowDraft75)
        handshaker.do_handshake()
        request.log_error(
            'mod_pywebsocket: resource: %r' % request.ws_resource,
            apache.APLOG_DEBUG)
        try:
            _dispatcher.transfer_data(request)
        except Exception, e:
            # Catch exception in transfer_data.
            # In this case, handshake has been successful, so just log the
            # exception and return apache.DONE
            request.log_error('mod_pywebsocket: %s' % e, apache.APLOG_WARNING)
    except handshake.HandshakeError, e:
        # Handshake for ws/wss failed.
        # But the request can be valid http/https request.
        request.log_error('mod_pywebsocket: %s' % e, apache.APLOG_INFO)
        return apache.DECLINED
Пример #3
0
 def test_good_request_default_no_protocol(self):
     request = _create_request(_GOOD_REQUEST_NO_PROTOCOL)
     handshaker = handshake.Handshaker(request,
                                       mock.MockDispatcher())
     handshaker.do_handshake()
     self.assertEqual(_GOOD_RESPONSE_NO_PROTOCOL,
                      request.connection.written_data())
     self.assertEqual(None, request.ws_protocol)
Пример #4
0
 def test_good_request_nondefault_port(self):
     request = _create_request(_GOOD_REQUEST_NONDEFAULT_PORT)
     handshaker = handshake.Handshaker(request,
                                       mock.MockDispatcher())
     handshaker.do_handshake()
     self.assertEqual(_GOOD_RESPONSE_NONDEFAULT_PORT,
                      request.connection.written_data())
     self.assertEqual('sample', request.ws_protocol)
Пример #5
0
 def test_good_request_optional_headers(self):
     request = _create_request(_GOOD_REQUEST_WITH_OPTIONAL_HEADERS)
     handshaker = handshake.Handshaker(request,
                                       mock.MockDispatcher())
     handshaker.do_handshake()
     self.assertEqual('AValue',
                      request.headers_in['AKey'])
     self.assertEqual('',
                      request.headers_in['EmptyValue'])
Пример #6
0
 def test_good_request_secure_default_port(self):
     request = _create_request(_GOOD_REQUEST)
     request.connection.local_addr = ('0.0.0.0', 443)
     request.is_https_ = True
     handshaker = handshake.Handshaker(request,
                                       mock.MockDispatcher())
     handshaker.do_handshake()
     self.assertEqual(_GOOD_RESPONSE_SECURE,
                      request.connection.written_data())
     self.assertEqual('sample', request.ws_protocol)
Пример #7
0
 def test_good_request_default_port(self):
     request = _create_request(_GOOD_REQUEST)
     handshaker = handshake.Handshaker(request,
                                       mock.MockDispatcher())
     handshaker.do_handshake()
     self.assertEqual(_GOOD_RESPONSE_DEFAULT_PORT,
                      request.connection.written_data())
     self.assertEqual('/demo', request.ws_resource)
     self.assertEqual('http://example.com', request.ws_origin)
     self.assertEqual('ws://example.com/demo', request.ws_location)
     self.assertEqual('sample', request.ws_protocol)
Пример #8
0
 def __init__(self, *args, **keywords):
     self._request = _StandaloneRequest(
             self, WebSocketRequestHandler.options.use_tls)
     self._dispatcher = WebSocketRequestHandler.options.dispatcher
     self._print_warnings_if_any()
     self._handshaker = handshake.Handshaker(
             self._request, self._dispatcher,
             allowDraft75=WebSocketRequestHandler.options.allow_draft75,
             strict=WebSocketRequestHandler.options.strict)
     CGIHTTPServer.CGIHTTPRequestHandler.__init__(
             self, *args, **keywords)
Пример #9
0
 def test_strictly_good_requests(self):
     for request in _create_requests_with_lines(_STRICTLY_GOOD_REQUESTS):
         strict_handshaker = handshake.Handshaker(request,
                                                  mock.MockDispatcher(),
                                                  True)
         strict_handshaker.do_handshake()
Пример #10
0
 def test_bad_requests(self):
     for request in map(_create_request, _BAD_REQUESTS):
         handshaker = handshake.Handshaker(request,
                                           mock.MockDispatcher())
         self.assertRaises(handshake.HandshakeError, handshaker.do_handshake)