aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ruby
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2017-01-05 13:14:23 -0800
committerGravatar Craig Tiller <ctiller@google.com>2017-01-05 13:14:23 -0800
commit78e4bf629c259ba3e0d523296a23910dedc6676b (patch)
tree70a7b23dbea50bbd2d86815f15245d4d70560bd1 /src/ruby
parent94c2647333252624d44ce45586a240968c53f511 (diff)
parent3a35f7ecbcef2f762a86a5874ecfc680bb870aaa (diff)
Merge github.com:grpc/grpc into metadata_filter
Diffstat (limited to 'src/ruby')
-rwxr-xr-xsrc/ruby/pb/test/server.rb27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/ruby/pb/test/server.rb b/src/ruby/pb/test/server.rb
index 3f1e0a1ccf..cc9b872648 100755
--- a/src/ruby/pb/test/server.rb
+++ b/src/ruby/pb/test/server.rb
@@ -129,6 +129,27 @@ def nulls(l)
[].pack('x' * l).force_encoding('ascii-8bit')
end
+def maybe_echo_metadata(_call)
+
+ # these are consistent for all interop tests
+ initial_metadata_key = "x-grpc-test-echo-initial"
+ trailing_metadata_key = "x-grpc-test-echo-trailing-bin"
+
+ if _call.metadata.has_key?(initial_metadata_key)
+ _call.metadata_to_send[initial_metadata_key] = _call.metadata[initial_metadata_key]
+ end
+ if _call.metadata.has_key?(trailing_metadata_key)
+ _call.output_metadata[trailing_metadata_key] = _call.metadata[trailing_metadata_key]
+ end
+end
+
+def maybe_echo_status_and_message(req)
+ unless req.response_status.nil?
+ fail GRPC::BadStatus.new_status_exception(
+ req.response_status.code, req.response_status.message)
+ end
+end
+
# A FullDuplexEnumerator passes requests to a block and yields generated responses
class FullDuplexEnumerator
include Grpc::Testing
@@ -143,6 +164,7 @@ class FullDuplexEnumerator
begin
cls = StreamingOutputCallResponse
@requests.each do |req|
+ maybe_echo_status_and_message(req)
req.response_parameters.each do |params|
resp_size = params.size
GRPC.logger.info("read a req, response size is #{resp_size}")
@@ -170,6 +192,8 @@ class TestTarget < Grpc::Testing::TestService::Service
end
def unary_call(simple_req, _call)
+ maybe_echo_metadata(_call)
+ maybe_echo_status_and_message(simple_req)
req_size = simple_req.response_size
SimpleResponse.new(payload: Payload.new(type: :COMPRESSABLE,
body: nulls(req_size)))
@@ -189,7 +213,8 @@ class TestTarget < Grpc::Testing::TestService::Service
end
end
- def full_duplex_call(reqs)
+ def full_duplex_call(reqs, _call)
+ maybe_echo_metadata(_call)
# reqs is a lazy Enumerator of the requests sent by the client.
FullDuplexEnumerator.new(reqs).each_item
end