示例#1
0
class HostnameMappingTestCase(AsyncHTTPTestCase):
    def setUp(self):
        super(HostnameMappingTestCase, self).setUp()
        self.http_client = SimpleAsyncHTTPClient(self.io_loop,
                                                 hostname_mapping={
                                                     'www.example.com':
                                                     '127.0.0.1',
                                                     ('foo.example.com', 8000):
                                                     ('127.0.0.1',
                                                      self.get_http_port()),
                                                 })

    def get_app(self):
        return Application([
            url("/hello", HelloWorldHandler),
        ])

    def test_hostname_mapping(self):
        self.http_client.fetch(
            'http://www.example.com:%d/hello' % self.get_http_port(),
            self.stop)
        response = self.wait()
        response.rethrow()
        self.assertEqual(response.body, b'Hello world!')

    def test_port_mapping(self):
        self.http_client.fetch('http://foo.example.com:8000/hello', self.stop)
        response = self.wait()
        response.rethrow()
        self.assertEqual(response.body, b'Hello world!')
示例#2
0
 def setUp(self):
     super(HostnameMappingTestCase, self).setUp()
     self.http_client = SimpleAsyncHTTPClient(self.io_loop,
                                              hostname_mapping={
                                                  'www.example.com':
                                                  '127.0.0.1',
                                                  ('foo.example.com', 8000):
                                                  ('127.0.0.1',
                                                   self.get_http_port()),
                                              })
示例#3
0
    def setUp(self):
        # Dummy Resolver subclass that never invokes its callback.
        class BadResolver(Resolver):
            def resolve(self, *args, **kwargs):
                pass

        super(ResolveTimeoutTestCase, self).setUp()
        self.http_client = SimpleAsyncHTTPClient(self.io_loop,
                                                 resolver=BadResolver())
示例#4
0
def main():
    parse_command_line()
    app = Application([('/', ChunkHandler)])
    app.listen(options.port, address='127.0.0.1')

    def callback(response):
        response.rethrow()
        assert len(response.body) == (options.num_chunks * options.chunk_size)
        logging.warning("fetch completed in %s seconds", response.request_time)
        IOLoop.current().stop()

    logging.warning("Starting fetch with curl client")
    curl_client = CurlAsyncHTTPClient()
    curl_client.fetch('http://localhost:%d/' % options.port, callback=callback)
    IOLoop.current().start()

    logging.warning("Starting fetch with simple client")
    simple_client = SimpleAsyncHTTPClient()
    simple_client.fetch('http://localhost:%d/' % options.port,
                        callback=callback)
    IOLoop.current().start()
示例#5
0
 def test_singleton(self):
     # Class "constructor" reuses objects on the same IOLoop
     self.assertTrue(
         SimpleAsyncHTTPClient(self.io_loop) is SimpleAsyncHTTPClient(
             self.io_loop))
     # unless force_instance is used
     self.assertTrue(
         SimpleAsyncHTTPClient(self.io_loop) is not SimpleAsyncHTTPClient(
             self.io_loop, force_instance=True))
     # different IOLoops use different objects
     with closing(IOLoop()) as io_loop2:
         self.assertTrue(
             SimpleAsyncHTTPClient(self.io_loop)
             is not SimpleAsyncHTTPClient(io_loop2))
示例#6
0
 def get_http_client(self):
     # body_producer doesn't work on curl_httpclient, so override the
     # configured AsyncHTTPClient implementation.
     return SimpleAsyncHTTPClient(io_loop=self.io_loop)
示例#7
0
 def get_http_client(self):
     return SimpleAsyncHTTPClient()
示例#8
0
 def get_http_client(self):
     # 100KB body with 64KB buffer
     return SimpleAsyncHTTPClient(io_loop=self.io_loop,
                                  max_body_size=1024 * 100,
                                  max_buffer_size=1024 * 64)
示例#9
0
 def get_http_client(self):
     return SimpleAsyncHTTPClient(io_loop=self.io_loop,
                                  max_body_size=1024 * 64)
示例#10
0
 def get_http_client(self):
     return SimpleAsyncHTTPClient(io_loop=self.io_loop,
                                  max_header_size=1024)
示例#11
0
 def create_client(self, **kwargs):
     return SimpleAsyncHTTPClient(self.io_loop,
                                  force_instance=True,
                                  defaults=dict(validate_cert=False),
                                  **kwargs)
示例#12
0
 def create_client(self, **kwargs):
     return SimpleAsyncHTTPClient(self.io_loop,
                                  force_instance=True,
                                  **kwargs)
示例#13
0
 def get_http_client(self):
     client = SimpleAsyncHTTPClient(io_loop=self.io_loop,
                                    force_instance=True)
     self.assertTrue(isinstance(client, SimpleAsyncHTTPClient))
     return client