示例#1
0
def index(application, message):
    name = message.get_argument('name', 'dude')
    context = {
        'name': name,
    }
    body = application.render_template('success.html', **context)
    return http_response(body, 200, 'OK', {})
示例#2
0
    def websocket_handshake(self):
        """Does initial handshake. This is a good place to register the websocket 
           connection in some memory database
        """
        headers = {}
        headers['Content-Type'] = 'text/plain'
        headers['Upgrade'] = 'websocket'
        headers['Connection'] = 'Upgrade'
        headers['Sec-WebSocket-Accept'] = self.message.body

        logging.info('%s %s %s (%s)' % (
             '101', self.message.method, self.message.path, self.message.remote_addr))
        return http_response('', '101', 'Switching Protocols', headers)
示例#3
0
    def process_message(self, application, message):
        """This coroutine looks at the message, determines which handler will
        be used to process it, and then begins processing.
        
        The application is responsible for handling misconfigured routes.
        """
        request = Request.parse_msg(message)
        if request.is_disconnect():
            return  # Ignore disconnect msgs. Dont have areason to do otherwise
        handler = application.route_message(request)
        result = handler()

        http_content = http_response(result['body'], result['status_code'],
                                     result['status_msg'], result['headers'])

        application.msg_conn.reply(request, http_content)
 def test_build_http_response(self):
     response = http_response(FIXTURES.TEST_BODY_OBJECT_HANDLER, 200, 'OK',
                              dict())
     self.assertEqual(FIXTURES.HTTP_RESPONSE_OBJECT_ROOT, response)
示例#5
0
def new_name_handler(application, message, name):
    return http_response('Take five, %s!' % (name), 200, 'OK', {})
示例#6
0
def foo(application, message):
    name = message.get_argument("name", "dude")
    body = "Take five, %s!" % name
    return http_response(body, 200, "OK", {})
示例#7
0
def foo(application, message):
    name = message.get_argument('name', 'dude')
    body = 'Take five, %s!' % name
    return http_response(body, 200, 'OK', {})
示例#8
0
 def test_handler_prepare_hook(self):
     # create a handler that sets the expected body in the prepare hook
     handler = PrepareHookWebHandlerObject(self.app, Request.parse_msg(FIXTURES.HTTP_REQUEST_ROOT))
     result = handler()
     response = http_response(result['body'], result['status_code'], result['status_msg'], result['headers'])
     self.assertEqual(response, FIXTURES.HTTP_RESPONSE_OBJECT_ROOT)
示例#9
0
 def test_build_http_response(self):
     response = http_response(FIXTURES.TEST_BODY_OBJECT_HANDLER, 200, 'OK', dict())
     self.assertEqual(FIXTURES.HTTP_RESPONSE_OBJECT_ROOT, response)
示例#10
0
 def test_request_without_cookie_response_with_cookie_handling_with_object(self):
     self.app.add_route_rule(r'^/$',CookieAddWebHandlerObject)
     result = route_message(self.app, Request.parse_msg(FIXTURES.HTTP_REQUEST_ROOT))
     response = http_response(result['body'], result['status_code'], result['status_msg'], result['headers'])
     self.assertEqual(FIXTURES.HTTP_RESPONSE_OBJECT_ROOT_WITH_COOKIE, response)
示例#11
0
 def test_json_request_handling_with_object(self):
     self.app.add_route_rule(r'^/$',SimpleJSONHandlerObject)
     result = route_message(self.app, Request.parse_msg(FIXTURES.HTTP_REQUEST_ROOT))
     response = http_response(result['body'], result['status_code'], result['status_msg'], result['headers'])
     self.assertEqual(FIXTURES.HTTP_RESPONSE_JSON_OBJECT_ROOT, response)
示例#12
0
 def test_web_request_handling_with_object(self):
     self.setup_route_with_object()
     result = route_message(self.app, Request.parse_msg(FIXTURES.HTTP_REQUEST_ROOT))
     response = http_response(result['body'], result['status_code'], result['status_msg'], result['headers'])
     self.assertEqual(FIXTURES.HTTP_RESPONSE_OBJECT_ROOT, response)
示例#13
0
def simple_handler_method(self, application, *args):
    """" dummy request action """
    return http_response(
        file('./fixtures/test_body_method_handler.txt',
             'r').read().rstrip('\n'), 200, 'OK', dict())
示例#14
0
def new_name_handler(application, message, name):
    return http_response('Take five, %s!' % (name), 200, 'OK', {})
示例#15
0
def simple_handler_method(self, application, *args):
    """" dummy request action """
    return http_response(file('./fixtures/test_body_method_handler.txt','r').read().rstrip('\n'), 200, 'OK', dict())