Esempio n. 1
0
    def test_ignore_length(self):
        self.connection = Connection(
            ('localhost', self._port),
            params=ConnectionParams(keep_alive=False, ignore_length=True))

        response = yield self.connection.fetch(Request.new(
            self.get_url('/underrun')),
                                               recorder=DebugPrintRecorder())

        self.assertEqual(50, response.body.content_size)
Esempio n. 2
0
    def test_no_content(self):
        http_client = Client(recorder=DebugPrintRecorder())
        proxy = HTTPProxyServer(http_client, io_loop=self.io_loop)
        proxy_socket, proxy_port = tornado.testing.bind_unused_port()
        proxy.add_socket(proxy_socket)

        _logger.debug('Proxy on port {0}'.format(proxy_port))

        test_client = tornado.curl_httpclient.CurlAsyncHTTPClient()

        request = tornado.httpclient.HTTPRequest(
            self.get_url('/no_content'),
            proxy_host='localhost',
            proxy_port=proxy_port
        )

        response = yield test_client.fetch(request)

        self.assertEqual(204, response.code)
Esempio n. 3
0
    def test_client_exception_recovery(self):
        connection_factory = functools.partial(Connection, read_timeout=0.2)
        host_connection_pool_factory = functools.partial(
            HostConnectionPool, connection_factory=connection_factory)
        connection_pool = ConnectionPool(host_connection_pool_factory)
        client = Client(connection_pool)

        for dummy in range(7):
            try:
                yield client.fetch(
                    Request.new(self.get_url('/header_early_close')),
                    recorder=DebugPrintRecorder()
                )
            except NetworkError:
                pass
            else:
                self.fail()

        for dummy in range(7):
            response = yield client.fetch(Request.new(self.get_url('/')))
            self.assertEqual(200, response.status_code)
Esempio n. 4
0
    def test_post(self):
        http_client = Client(recorder=DebugPrintRecorder())
        proxy = HTTPProxyServer(http_client, io_loop=self.io_loop)
        proxy_socket, proxy_port = tornado.testing.bind_unused_port()
        proxy.add_socket(proxy_socket)

        _logger.debug('Proxy on port {0}'.format(proxy_port))

        test_client = tornado.curl_httpclient.CurlAsyncHTTPClient()

        request = tornado.httpclient.HTTPRequest(
            self.get_url('/post/'),
            proxy_host='localhost',
            proxy_port=proxy_port,
            body='text=blah',
            method='POST'
        )

        response = yield test_client.fetch(request)

        self.assertEqual(200, response.code)
        self.assertIn(b'OK', response.body)
Esempio n. 5
0
 def test_head_no_content(self):
     yield self.connection.fetch(
         Request.new(self.get_url('/no_content'), method='HEAD'),
         DebugPrintRecorder()
     )
Esempio n. 6
0
 def fetch(self, path):
     response = yield self.connection.fetch(Request.new(self.get_url(path)),
                                            DebugPrintRecorder())
     raise tornado.gen.Return(response)