コード例 #1
0
ファイル: test_requests.py プロジェクト: sthagen/starlette
        "headers": {
            "host": "example.org",
            "user-agent": "testclient",
            "accept-encoding": "gzip, deflate",
            "accept": "*/*",
            "connection": "keep-alive",
        }
    }


@pytest.mark.parametrize(
    "scope,expected_client",
    [
        ({
            "client": ["client", 42]
        }, Address("client", 42)),
        ({
            "client": None
        }, None),
        ({}, None),
    ],
)
def test_request_client(scope: Scope, expected_client: Optional[Address]):
    scope.update({"type": "http"})  # required by Request's constructor
    client = Request(scope).client
    assert client == expected_client


def test_request_body(test_client_factory):
    async def app(scope, receive, send):
        request = Request(scope, receive)
コード例 #2
0
 def client(self) -> Address:
     host, port = self._scope.get("client") or (None, None)
     return Address(host=host, port=port)
コード例 #3
0
ファイル: requests.py プロジェクト: encode/starlette
 def client(self) -> typing.Optional[Address]:
     # client is a 2 item tuple of (host, port), None or missing
     host_port = self.scope.get("client")
     if host_port is not None:
         return Address(*host_port)
     return None