Ejemplo n.º 1
0
    def _create_context(self, scope):
        timeout = None
        metadata = []

        for header, value in scope["headers"]:
            if timeout is None and header == b"grpc-timeout":
                timeout = protocol.parse_timeout(value)
            else:
                if header.endswith(b"-bin"):
                    value = base64.b64decode(value)
                else:
                    value = value.decode("ascii")

                metadata.append((header.decode("ascii"), value))

        return ServicerContext(timeout, metadata)
Ejemplo n.º 2
0
    def _create_context(self, environ):
        try:
            timeout = protocol.parse_timeout(environ["HTTP_GRPC_TIMEOUT"])
        except KeyError:
            timeout = None

        metadata = []
        for key, value in environ.items():
            if key.startswith("HTTP_"):
                header = key[5:].lower().replace("_", "-")

                if header.endswith("-bin"):
                    value = base64.b64decode(value)

                metadata.append((header, value))

        return ServicerContext(timeout, metadata)
Ejemplo n.º 3
0
def test_timeout_serdes(timeout):
    ser = protocol.serialize_timeout(timeout).encode("ascii")
    des = protocol.parse_timeout(ser)
    assert abs(timeout - des) < 1e-9, (timeout, ser)