Skip to content

Commit 33cbf1c

Browse files
Fix aio channel
1 parent ac01936 commit 33cbf1c

1 file changed

Lines changed: 24 additions & 7 deletions

File tree

tilebox-grpc/_tilebox/grpc/aio/channel.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from collections.abc import Callable, Sequence
22
from typing import TypeVar
33

4-
from _tilebox.grpc.channel import CHANNEL_OPTIONS, ChannelInfo, add_metadata, parse_channel_info
5-
from grpc import ssl_channel_credentials
4+
from _tilebox.grpc.channel import CHANNEL_OPTIONS, ChannelInfo, ChannelProtocol, add_metadata, parse_channel_info
5+
from grpc import Compression, ssl_channel_credentials
66
from grpc.aio import (
77
Channel,
88
ClientCallDetails,
@@ -34,11 +34,28 @@ def open_channel(url: str, auth_token: str | None = None) -> Channel:
3434

3535

3636
def _open_channel(channel_info: ChannelInfo, interceptors: Sequence[ClientInterceptor]) -> Channel:
37-
if channel_info.use_ssl:
38-
return secure_channel(
39-
channel_info.address, ssl_channel_credentials(), CHANNEL_OPTIONS, interceptors=interceptors
40-
)
41-
return insecure_channel(channel_info.address, CHANNEL_OPTIONS, interceptors=interceptors)
37+
match channel_info.protocol:
38+
case ChannelProtocol.HTTPS:
39+
return secure_channel(
40+
f"{channel_info.address}:{channel_info.port}",
41+
ssl_channel_credentials(),
42+
CHANNEL_OPTIONS,
43+
compression=Compression.Gzip,
44+
interceptors=interceptors,
45+
)
46+
case ChannelProtocol.HTTP:
47+
return insecure_channel(
48+
f"{channel_info.address}:{channel_info.port}",
49+
CHANNEL_OPTIONS,
50+
compression=Compression.NoCompression,
51+
interceptors=interceptors,
52+
)
53+
case ChannelProtocol.UNIX:
54+
return insecure_channel(
55+
channel_info.address, CHANNEL_OPTIONS, compression=Compression.NoCompression, interceptors=interceptors
56+
)
57+
case _:
58+
raise ValueError(f"Unsupported channel protocol: {channel_info.protocol}")
4259

4360

4461
RequestType = TypeVar("RequestType")

0 commit comments

Comments
 (0)