Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sonora/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ async def _do_unary_response(
else:
message_data = b""

trailers = [(b"grpc-status", str(context.code.value[0]).encode())]
trailers = [("grpc-status", str(context.code.value[0]))]

if context.details:
trailers.append(
(b"grpc-message", quote(context.details.encode("utf8")).encode("ascii"))
("grpc-message", quote(context.details))
)

if context._trailing_metadata:
Expand Down
9 changes: 6 additions & 3 deletions sonora/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,14 @@ async def unwrap_message_asgi(receive, decoder=None):


def pack_trailers(trailers):
message = []
data = bytearray()
for k, v in trailers:
k = k.lower()
message.append(f"{k}: {v}\r\n".encode("ascii"))
return b"".join(message)
data.extend(k.encode('utf8'))
data.extend(b': ')
data.extend(v.encode('utf8'))
data.extend(b'\r\n')
return bytes(data)


def unpack_trailers(message):
Expand Down
2 changes: 1 addition & 1 deletion sonora/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def _do_unary_response(
trailers = [("grpc-status", str(context.code.value[0]))]

if context.details:
trailers.append(("grpc-message", quote(context.details.encode("utf8"))))
trailers.append(("grpc-message", quote(context.details)))

if context._trailing_metadata:
trailers.extend(context._trailing_metadata)
Expand Down