Skip to content

Instantly share code, notes, and snippets.

@arthurnn
Created January 10, 2023 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arthurnn/0adbb19cfa5db8001826eb73d50fc5ad to your computer and use it in GitHub Desktop.
Save arthurnn/0adbb19cfa5db8001826eb73d50fc5ad to your computer and use it in GitHub Desktop.
diff -ruN twirp-1.8.0.7.ga1a8eb9/README.md twirp-1.10.0/README.md
--- twirp-1.8.0.7.ga1a8eb9/README.md 2023-01-10 12:01:35.000000000 -0500
+++ twirp-1.10.0/README.md 2023-01-10 12:07:42.000000000 -0500
@@ -1,6 +1,8 @@
# Twirp-Ruby
-[Twirp is a protocol](https://twitchtv.github.io/twirp/docs/spec_v5.html) for routing and serialization of services defined in a [.proto file](https://developers.google.com/protocol-buffers/docs/proto3), allowing easy implementation of RPC services with auto-generated clients in different languages.
+[![Run Tests](https://github.com/github/twirp-ruby/actions/workflows/tests.yml/badge.svg)](https://github.com/github/twirp-ruby/actions/workflows/tests.yml)
+
+[Twirp is a protocol](https://github.github.io/twirp/docs/spec_v5.html) for routing and serialization of services defined in a [.proto file](https://developers.google.com/protocol-buffers/docs/proto3), allowing easy implementation of RPC services with auto-generated clients in different languages.
The [canonical implementation](https://github.com/twitchtv/twirp) is in Golang. The Twirp-Ruby project is the official implementation in Ruby for both server and clients.
@@ -9,14 +11,18 @@
Add `gem "twirp"` to your Gemfile, or install with `gem install twirp`.
-To auto-generate Ruby code from a proto file, use the `protoc` plugin and the `--ruby_out` option ([see Wiki page](https://github.com/twitchtv/twirp-ruby/wiki/Code-Generation)).
+To auto-generate Ruby code from a proto file, use the `protoc` plugin and the `--ruby_out` option ([see Wiki page](https://github.com/github/twirp-ruby/wiki/Code-Generation)).
## Documentation
-[On the wiki](https://github.com/twitchtv/twirp-ruby/wiki).
+[On the wiki](https://github.com/github/twirp-ruby/wiki).
## Contributing
[On the CONTRIBUTING file](CONTRIBUTING.md).
+
+## Releases and changes
+
+See the [releases](https://github.com/github/twirp-ruby/releases) page for latest information about released versions.
diff -ruN twirp-1.8.0.7.ga1a8eb9/lib/twirp/client.rb twirp-1.10.0/lib/twirp/client.rb
--- twirp-1.8.0.7.ga1a8eb9/lib/twirp/client.rb 2023-01-10 12:01:35.000000000 -0500
+++ twirp-1.10.0/lib/twirp/client.rb 2023-01-10 12:07:42.000000000 -0500
@@ -151,7 +151,7 @@
def rpc(rpc_method, input, req_opts=nil)
rpcdef = self.class.rpcs[rpc_method.to_s]
if !rpcdef
- return ClientResp.new(nil, Twirp::Error.bad_route("rpc not defined on this client"))
+ return ClientResp.new(error: Twirp::Error.bad_route("rpc not defined on this client"))
end
content_type = (req_opts && req_opts[:headers] && req_opts[:headers]['Content-Type']) || @content_type
@@ -186,15 +186,15 @@
def rpc_response_to_clientresp(resp, content_type, rpcdef)
if resp.status != 200
- return ClientResp.new(nil, self.class.error_from_response(resp))
+ return ClientResp.new(error: self.class.error_from_response(resp))
end
if resp.headers['Content-Type'] != content_type
- return ClientResp.new(nil, Twirp::Error.internal("Expected response Content-Type #{content_type.inspect} but found #{resp.headers['Content-Type'].inspect}"))
+ return ClientResp.new(error: Twirp::Error.internal("Expected response Content-Type #{content_type.inspect} but found #{resp.headers['Content-Type'].inspect}"))
end
data = Encoding.decode(resp.body, rpcdef[:output_class], content_type)
- return ClientResp.new(data, nil)
+ return ClientResp.new(data: data, body: resp.body)
end
end
diff -ruN twirp-1.8.0.7.ga1a8eb9/lib/twirp/client_json.rb twirp-1.10.0/lib/twirp/client_json.rb
--- twirp-1.8.0.7.ga1a8eb9/lib/twirp/client_json.rb 2023-01-10 12:01:35.000000000 -0500
+++ twirp-1.10.0/lib/twirp/client_json.rb 2023-01-10 12:07:42.000000000 -0500
@@ -46,11 +46,11 @@
def rpc_response_to_clientresp(resp)
if resp.status != 200
- return ClientResp.new(nil, self.class.error_from_response(resp))
+ return ClientResp.new(error: self.class.error_from_response(resp))
end
data = Encoding.decode_json(resp.body)
- return ClientResp.new(data, nil)
+ return ClientResp.new(data: data, body: resp.body)
end
end
diff -ruN twirp-1.8.0.7.ga1a8eb9/lib/twirp/client_resp.rb twirp-1.10.0/lib/twirp/client_resp.rb
--- twirp-1.8.0.7.ga1a8eb9/lib/twirp/client_resp.rb 2023-01-10 12:01:35.000000000 -0500
+++ twirp-1.10.0/lib/twirp/client_resp.rb 2023-01-10 12:07:42.000000000 -0500
@@ -14,11 +14,13 @@
module Twirp
class ClientResp
attr_accessor :data
+ attr_accessor :body
attr_accessor :error
- def initialize(data, error)
+ def initialize(data: nil, body: nil, error: nil)
@data = data
@error = error
+ @body = body
end
end
end
diff -ruN twirp-1.8.0.7.ga1a8eb9/lib/twirp/service.rb twirp-1.10.0/lib/twirp/service.rb
--- twirp-1.8.0.7.ga1a8eb9/lib/twirp/service.rb 2023-01-10 12:01:35.000000000 -0500
+++ twirp-1.10.0/lib/twirp/service.rb 2023-01-10 12:07:42.000000000 -0500
@@ -14,6 +14,7 @@
require_relative 'encoding'
require_relative 'error'
require_relative 'service_dsl'
+require 'rack/request'
module Twirp
@@ -122,7 +123,7 @@
end
env[:content_type] = content_type
- path_parts = rack_request.fullpath.split("/")
+ path_parts = rack_request.path.split("/")
if path_parts.size < 3 || path_parts[-2] != self.full_name
return route_err(:bad_route, "Invalid route. Expected format: POST {BaseURL}/#{self.full_name}/{Method}", rack_request)
end
@@ -137,7 +138,7 @@
input = nil
begin
body_str = rack_request.body.read
- rack_request.body.rewind # allow other middleware to read again (https://github.com/twitchtv/twirp-ruby/issues/50)
+ rack_request.body.rewind # allow other middleware to read again (https://github.com/github/twirp-ruby/issues/50)
input = Encoding.decode(body_str, env[:input_class], content_type)
rescue => e
error_msg = "Invalid request body for rpc method #{method_name.inspect} with Content-Type=#{content_type}"
@@ -153,7 +154,7 @@
end
def route_err(code, msg, req)
- Twirp::Error.new code, msg, twirp_invalid_route: "#{req.request_method} #{req.fullpath}"
+ Twirp::Error.new code, msg, twirp_invalid_route: "#{req.request_method} #{req.path}"
end
diff -ruN twirp-1.8.0.7.ga1a8eb9/lib/twirp/version.rb twirp-1.10.0/lib/twirp/version.rb
--- twirp-1.8.0.7.ga1a8eb9/lib/twirp/version.rb 2023-01-10 12:01:35.000000000 -0500
+++ twirp-1.10.0/lib/twirp/version.rb 2023-01-10 12:07:42.000000000 -0500
@@ -12,5 +12,5 @@
# permissions and limitations under the License.
module Twirp
- VERSION = "1.8.0"
+ VERSION = "1.10.0"
end
diff -ruN twirp-1.8.0.7.ga1a8eb9/test/client_test.rb twirp-1.10.0/test/client_test.rb
--- twirp-1.8.0.7.ga1a8eb9/test/client_test.rb 2023-01-10 12:01:35.000000000 -0500
+++ twirp-1.10.0/test/client_test.rb 2023-01-10 12:07:42.000000000 -0500
@@ -17,7 +17,7 @@
def test_new_with_invalid_url
assert_raises URI::InvalidURIError do
- EmptyClient.new("lulz")
+ EmptyClient.new("invalid uri with unescaped spaces")
end
end
diff -ruN twirp-1.8.0.7.ga1a8eb9/test/service_test.rb twirp-1.10.0/test/service_test.rb
--- twirp-1.8.0.7.ga1a8eb9/test/service_test.rb 2023-01-10 12:01:35.000000000 -0500
+++ twirp-1.10.0/test/service_test.rb 2023-01-10 12:07:42.000000000 -0500
@@ -188,6 +188,15 @@
}, JSON.parse(body[0]))
end
+ def test_route_with_query_string
+ rack_env = json_req "/example.Haberdasher/MakeHat?extra=1", inches: 10
+ status, headers, body = haberdasher_service.call(rack_env)
+
+ assert_equal 200, status
+ assert_equal 'application/json', headers['Content-Type']
+ assert_equal({"inches" => 10, "color" => "white"}, JSON.parse(body[0]))
+ end
+
def test_json_request_ignores_unknown_fields
rack_env = json_req "/example.Haberdasher/MakeHat", inches: 10, fake: 3
status, headers, body = haberdasher_service.call(rack_env)
diff -ruN twirp-1.8.0.7.ga1a8eb9/twirp.gemspec twirp-1.10.0/twirp.gemspec
--- twirp-1.8.0.7.ga1a8eb9/twirp.gemspec 2023-01-10 12:01:35.000000000 -0500
+++ twirp-1.10.0/twirp.gemspec 2023-01-10 12:07:42.000000000 -0500
@@ -11,7 +11,7 @@
spec.email = ["forbescyrus@gmail.com", "tothemario@gmail.com"]
spec.summary = %q{Twirp services in Ruby.}
spec.description = %q{Twirp is a simple RPC framework with protobuf service definitions. The Twirp gem provides native support for Ruby.}
- spec.homepage = "https://github.com/twitchtv/twirp-ruby"
+ spec.homepage = "https://github.com/github/twirp-ruby"
spec.license = "MIT"
spec.files = Dir['lib/**/*'] + %w(Gemfile LICENSE README.md twirp.gemspec)
@@ -20,7 +20,7 @@
spec.required_ruby_version = '>= 1.9'
spec.add_runtime_dependency 'google-protobuf', '~> 3.0', '>= 3.7.0'
- spec.add_runtime_dependency 'faraday', '< 2' # for clients
+ spec.add_runtime_dependency 'faraday', '< 3' # for clients
spec.add_development_dependency 'bundler', '~> 2'
spec.add_development_dependency 'minitest', '>= 5'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment