Skip to content

Commit 123ee51

Browse files
authored
fix: update accepted_compressors to use channel's accepted_compressors (#445)
Signed-off-by: Yordis Prieto <[email protected]>
1 parent 008df0e commit 123ee51

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

lib/grpc/stub.ex

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,11 @@ defmodule GRPC.Stub do
309309
end
310310

311311
compressor = Keyword.get(opts, :compressor, channel.compressor)
312-
accepted_compressors = Keyword.get(opts, :accepted_compressors, [])
312+
accepted_compressors = Keyword.get(opts, :accepted_compressors, channel.accepted_compressors)
313+
314+
if not is_list(accepted_compressors) do
315+
raise ArgumentError, "accepted_compressors is not a list"
316+
end
313317

314318
accepted_compressors =
315319
if compressor do
@@ -321,7 +325,7 @@ defmodule GRPC.Stub do
321325
stream = %{
322326
stream
323327
| codec: Keyword.get(opts, :codec, channel.codec),
324-
compressor: Keyword.get(opts, :compressor, channel.compressor),
328+
compressor: compressor,
325329
accepted_compressors: accepted_compressors
326330
}
327331

test/grpc/integration/compressor_test.exs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ defmodule GRPC.Integration.CompressorTest do
3636
end
3737
end
3838

39+
defmodule AcceptCompressServer do
40+
use GRPC.Server,
41+
service: Helloworld.Greeter.Service
42+
43+
def say_hello(_, stream) do
44+
GRPC.Server.set_compressor(stream, GRPC.Compressor.Gzip)
45+
%Helloworld.HelloReply{message: "Hola, Mundo! Olá, Mundo!"}
46+
end
47+
end
48+
3949
defmodule HelloStub do
4050
use GRPC.Stub, service: Helloworld.Greeter.Service
4151
end
@@ -108,4 +118,28 @@ defmodule GRPC.Integration.CompressorTest do
108118
|> HelloStub.say_hello(req, compressor: GRPC.Compressor.Gzip, return_headers: true)
109119
end)
110120
end
121+
122+
test "error when accepted_compressors is not a list" do
123+
run_server(AcceptCompressServer, fn port ->
124+
{:ok, channel} = GRPC.Stub.connect("localhost:#{port}")
125+
126+
assert_raise ArgumentError, "accepted_compressors is not a list", fn ->
127+
HelloStub.say_hello(channel, %Helloworld.HelloRequest{name: ""},
128+
accepted_compressors: nil
129+
)
130+
end
131+
end)
132+
end
133+
134+
test "fallback to channel's accepted_compressors" do
135+
run_server(AcceptCompressServer, fn port ->
136+
{:ok, channel} =
137+
GRPC.Stub.connect("localhost:#{port}", accepted_compressors: [GRPC.Compressor.Gzip])
138+
139+
req = %Helloworld.HelloRequest{name: ""}
140+
141+
{:ok, _reply, headers} = HelloStub.say_hello(channel, req, return_headers: true)
142+
assert headers[:headers]["grpc-encoding"]
143+
end)
144+
end
111145
end

0 commit comments

Comments
 (0)