Esempio n. 1
0
    def test_headers_passthrough(self):
        """Test that we correctly send RFC-defined headers and merge them with user defined ones"""
        @asyncio.coroutine
        def handler(request):
            return aiohttp.web.Response(
                text='{"jsonrpc": "2.0", "result": true, "id": 1}',
                content_type='application/json')

        self.handler = handler

        def callback(method, path, *args, **kwargs):
            expected_headers = {
                'Content-Type': 'application/json',
                'Accept': 'application/json-rpc',
                'X-TestCustomHeader': '1'
            }
            self.assertTrue(
                set(expected_headers.items()).issubset(
                    set(kwargs['headers'].items())))

        self.client.request_callback = callback
        s = Server('/xmlrpc',
                   session=self.client,
                   headers={'X-TestCustomHeader': '1'})
        yield from s.foo()