当前位置: 首页>>代码示例>>Python>>正文


Python httpclient.HTTPRequest方法代码示例

本文整理汇总了Python中tornado.httpclient.HTTPRequest方法的典型用法代码示例。如果您正苦于以下问题:Python httpclient.HTTPRequest方法的具体用法?Python httpclient.HTTPRequest怎么用?Python httpclient.HTTPRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tornado.httpclient的用法示例。


在下文中一共展示了httpclient.HTTPRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: raw_fetch

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPRequest [as 别名]
def raw_fetch(self, headers, body):
        with closing(Resolver(io_loop=self.io_loop)) as resolver:
            with closing(SimpleAsyncHTTPClient(self.io_loop,
                                               resolver=resolver)) as client:
                conn = RawRequestHTTPConnection(
                    self.io_loop, client,
                    httpclient._RequestProxy(
                        httpclient.HTTPRequest(self.get_url("/")),
                        dict(httpclient.HTTPRequest._DEFAULTS)),
                    None, self.stop,
                    1024 * 1024, resolver)
                conn.set_request(
                    b"\r\n".join(headers +
                                 [utf8("Content-Length: %d\r\n" % len(body))]) +
                    b"\r\n" + body)
                response = self.wait()
                response.rethrow()
                return response 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:20,代码来源:httpserver_test.py

示例2: connect_kernel

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPRequest [as 别名]
def connect_kernel():
    # TODO check status busy/idle
    run_sync(manager.list_kernels())
    kernels = {
        kernel_id: dateparser.parse(kernel["last_activity"])
        for kernel_id, kernel in manager._kernels.items()
    }
    kernel_id = url_escape(sorted(kernels, key=kernels.get)[0])
    client = GatewayClient.instance()
    url = url_path_join(client.ws_url, client.kernels_endpoint, kernel_id, "channels")
    ws_req = HTTPRequest(url=url)
    return run_sync(websocket_connect(ws_req)) 
开发者ID:materialsproject,项目名称:MPContribs,代码行数:14,代码来源:views.py

示例3: get

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPRequest [as 别名]
def get(self, callback, path, params=None, headers=None):
        uri = self.uri(path, params)
        request = httpclient.HTTPRequest(uri,
                                         method='GET',
                                         validate_cert=self.verify,
                                         headers=headers)
        return self._request(callback, request) 
开发者ID:poppyred,项目名称:python-consul2,代码行数:9,代码来源:tornado.py

示例4: put

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPRequest [as 别名]
def put(self, callback, path, params=None, data='', headers=None):
        uri = self.uri(path, params)
        request = httpclient.HTTPRequest(uri,
                                         method='PUT',
                                         body='' if data is None else data,
                                         validate_cert=self.verify,
                                         headers=headers)
        return self._request(callback, request) 
开发者ID:poppyred,项目名称:python-consul2,代码行数:10,代码来源:tornado.py

示例5: delete

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPRequest [as 别名]
def delete(self, callback, path, params=None, data='', headers=None):
        uri = self.uri(path, params)
        request = httpclient.HTTPRequest(uri,
                                         method='DELETE',
                                         body='' if data is None else data,
                                         validate_cert=self.verify,
                                         headers=headers)
        request.allow_nonstandard_methods = True
        return self._request(callback, request) 
开发者ID:poppyred,项目名称:python-consul2,代码行数:11,代码来源:tornado.py

示例6: post

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPRequest [as 别名]
def post(self, callback, path, params=None, data='', headers=None):
        uri = self.uri(path, params)
        request = httpclient.HTTPRequest(uri,
                                         method='POST',
                                         body=data,
                                         validate_cert=self.verify,
                                         headers=headers)
        return self._request(callback, request) 
开发者ID:poppyred,项目名称:python-consul2,代码行数:10,代码来源:tornado.py

示例7: test_websocket_headers

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPRequest [as 别名]
def test_websocket_headers(self):
        # Ensure that arbitrary headers can be passed through websocket_connect.
        ws = yield websocket_connect(
            HTTPRequest('ws://127.0.0.1:%d/header' % self.get_http_port(),
                        headers={'X-Test': 'hello'}))
        response = yield ws.read_message()
        self.assertEqual(response, 'hello')
        yield self.close(ws) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:10,代码来源:websocket_test.py

示例8: test_check_origin_valid_no_path

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPRequest [as 别名]
def test_check_origin_valid_no_path(self):
        port = self.get_http_port()

        url = 'ws://127.0.0.1:%d/echo' % port
        headers = {'Origin': 'http://127.0.0.1:%d' % port}

        ws = yield websocket_connect(HTTPRequest(url, headers=headers),
                                     io_loop=self.io_loop)
        ws.write_message('hello')
        response = yield ws.read_message()
        self.assertEqual(response, 'hello')
        yield self.close(ws) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:14,代码来源:websocket_test.py

示例9: test_check_origin_valid_with_path

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPRequest [as 别名]
def test_check_origin_valid_with_path(self):
        port = self.get_http_port()

        url = 'ws://127.0.0.1:%d/echo' % port
        headers = {'Origin': 'http://127.0.0.1:%d/something' % port}

        ws = yield websocket_connect(HTTPRequest(url, headers=headers),
                                     io_loop=self.io_loop)
        ws.write_message('hello')
        response = yield ws.read_message()
        self.assertEqual(response, 'hello')
        yield self.close(ws) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:14,代码来源:websocket_test.py

示例10: test_check_origin_invalid_partial_url

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPRequest [as 别名]
def test_check_origin_invalid_partial_url(self):
        port = self.get_http_port()

        url = 'ws://127.0.0.1:%d/echo' % port
        headers = {'Origin': '127.0.0.1:%d' % port}

        with self.assertRaises(HTTPError) as cm:
            yield websocket_connect(HTTPRequest(url, headers=headers),
                                    io_loop=self.io_loop)
        self.assertEqual(cm.exception.code, 403) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:12,代码来源:websocket_test.py

示例11: test_check_origin_invalid_subdomains

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPRequest [as 别名]
def test_check_origin_invalid_subdomains(self):
        port = self.get_http_port()

        url = 'ws://localhost:%d/echo' % port
        # Subdomains should be disallowed by default.  If we could pass a
        # resolver to websocket_connect we could test sibling domains as well.
        headers = {'Origin': 'http://subtenant.localhost'}

        with self.assertRaises(HTTPError) as cm:
            yield websocket_connect(HTTPRequest(url, headers=headers),
                                    io_loop=self.io_loop)

        self.assertEqual(cm.exception.code, 403) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:15,代码来源:websocket_test.py

示例12: test_reuse_request_from_response

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPRequest [as 别名]
def test_reuse_request_from_response(self):
        # The response.request attribute should be an HTTPRequest, not
        # a _RequestProxy.
        # This test uses self.http_client.fetch because self.fetch calls
        # self.get_url on the input unconditionally.
        url = self.get_url('/hello')
        response = yield self.http_client.fetch(url)
        self.assertEqual(response.request.url, url)
        self.assertTrue(isinstance(response.request, HTTPRequest))
        response2 = yield self.http_client.fetch(response.request)
        self.assertEqual(response2.body, b'Hello world!') 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:13,代码来源:httpclient_test.py

示例13: test_request_set

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPRequest [as 别名]
def test_request_set(self):
        proxy = _RequestProxy(HTTPRequest('http://example.com/',
                                          user_agent='foo'),
                              dict())
        self.assertEqual(proxy.user_agent, 'foo') 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:7,代码来源:httpclient_test.py

示例14: test_default_set

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPRequest [as 别名]
def test_default_set(self):
        proxy = _RequestProxy(HTTPRequest('http://example.com/'),
                              dict(network_interface='foo'))
        self.assertEqual(proxy.network_interface, 'foo') 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:6,代码来源:httpclient_test.py

示例15: test_both_set

# 需要导入模块: from tornado import httpclient [as 别名]
# 或者: from tornado.httpclient import HTTPRequest [as 别名]
def test_both_set(self):
        proxy = _RequestProxy(HTTPRequest('http://example.com/',
                                          proxy_host='foo'),
                              dict(proxy_host='bar'))
        self.assertEqual(proxy.proxy_host, 'foo') 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:7,代码来源:httpclient_test.py


注:本文中的tornado.httpclient.HTTPRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。