rails_twirp 0.6.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/lib/rails_twirp/log_subscriber.rb +3 -1
- data/lib/rails_twirp/route_set.rb +3 -3
- data/lib/rails_twirp/testing/integration_test.rb +26 -3
- data/lib/rails_twirp/version.rb +1 -1
- data/rails_twirp.gemspec +1 -1
- data/test/dummy/config/twirp/routes.rb +1 -1
- data/test/ping_controller_test.rb +10 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 394816fb648167ae3e089e6e16e93c72f985b5eb540182ff026b8bb283bfa8d8
|
4
|
+
data.tar.gz: a86a22b695b81fcaf0d93e5df2c33dff327c4fe0c2b54a2cc36c8a5c9a5a4eba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d0c19ce26c7e5bf06cd9172b9e257dda0ac87f1dec2b6ba6c2b3ecda3aa26664c2319097dc7cf584e3e59316291ec5b7fef59be33ad0564719e2c59aba41ba9
|
7
|
+
data.tar.gz: 878e8240c50b77f737df1e0d950a4c74d16f06e5fdcd58edccaf00c8471f4f11d645c3e4f8eb5322a500426b4c259ebb028fb389d96608accc74e570e3843866
|
data/Gemfile
CHANGED
@@ -17,7 +17,9 @@ module RailsTwirp
|
|
17
17
|
info do
|
18
18
|
code = payload.fetch(:code, :internal)
|
19
19
|
|
20
|
-
message = +"Completed #{code}
|
20
|
+
message = +"Completed #{code}"
|
21
|
+
message << ": #{payload[:msg]}" if payload[:msg]
|
22
|
+
message << " in #{event.duration.round}ms (Allocations: #{event.allocations})"
|
21
23
|
message << "\n\n" if defined?(Rails.env) && Rails.env.development?
|
22
24
|
|
23
25
|
message
|
@@ -50,13 +50,13 @@ module RailsTwirp
|
|
50
50
|
method_name = rpc_info[:ruby_method]
|
51
51
|
|
52
52
|
# Stolen from Rails in ActionDispatch::Request#controller_class_for
|
53
|
-
controller_name = mapping.controller.underscore
|
54
|
-
const_name = controller_name.camelize << "Controller"
|
55
53
|
action_name = mapping.action
|
56
54
|
response_class = rpc_info[:output_class]
|
57
55
|
|
58
56
|
handler.define_method(method_name) do |req, env|
|
59
|
-
|
57
|
+
controller_name = mapping.controller.underscore
|
58
|
+
const_name = controller_name.camelize << "Controller"
|
59
|
+
controller_class = const_name.constantize
|
60
60
|
controller_class.dispatch(action_name, req, response_class, env)
|
61
61
|
end
|
62
62
|
end
|
@@ -2,21 +2,40 @@ require "twirp/encoding"
|
|
2
2
|
|
3
3
|
module RailsTwirp
|
4
4
|
class IntegrationTest < ActiveSupport::TestCase
|
5
|
+
DEFAULT_HOST = "www.example.com"
|
5
6
|
Response = Struct.new(:status, :body, :headers)
|
6
7
|
|
7
8
|
attr_reader :response, :request, :controller
|
8
9
|
attr_writer :mount_path
|
10
|
+
alias_method :mount_path!, :mount_path=
|
9
11
|
|
10
12
|
def initialize(name)
|
11
13
|
super
|
12
14
|
reset!
|
13
15
|
@before_rpc = []
|
14
|
-
|
16
|
+
end
|
17
|
+
|
18
|
+
def host
|
19
|
+
@host || DEFAULT_HOST
|
20
|
+
end
|
21
|
+
attr_writer :host
|
22
|
+
alias_method :host!, :host=
|
23
|
+
|
24
|
+
def https?
|
25
|
+
@https
|
26
|
+
end
|
27
|
+
|
28
|
+
def https!(value = true)
|
29
|
+
@https = value
|
15
30
|
end
|
16
31
|
|
17
32
|
def reset!
|
18
33
|
@request = nil
|
19
34
|
@response = nil
|
35
|
+
@host = nil
|
36
|
+
@host = nil
|
37
|
+
@https = false
|
38
|
+
@mount_path = "/twirp"
|
20
39
|
end
|
21
40
|
|
22
41
|
def before_rpc(&block)
|
@@ -47,9 +66,13 @@ module RailsTwirp
|
|
47
66
|
def build_rack_env(service, rpc, request, headers)
|
48
67
|
env = {
|
49
68
|
"CONTENT_TYPE" => request_content_type,
|
50
|
-
"
|
69
|
+
"HTTPS" => https? ? "on" : "off",
|
70
|
+
"HTTP_HOST" => host,
|
51
71
|
"PATH_INFO" => "#{@mount_path}/#{service.service_full_name}/#{rpc}",
|
52
|
-
"REQUEST_METHOD" => "POST"
|
72
|
+
"REQUEST_METHOD" => "POST",
|
73
|
+
"SERVER_NAME" => host,
|
74
|
+
"SERVER_PORT" => https? ? "443" : "80",
|
75
|
+
"rack.url_scheme" => https? ? "https" : "http"
|
53
76
|
}
|
54
77
|
if headers.present?
|
55
78
|
http_request = ActionDispatch::Request.new(env)
|
data/lib/rails_twirp/version.rb
CHANGED
data/rails_twirp.gemspec
CHANGED
@@ -12,6 +12,6 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.files = `git ls-files`.split("\n")
|
13
13
|
spec.test_files = `git ls-files -- test/*`.split("\n")
|
14
14
|
|
15
|
-
spec.add_dependency "rails", "
|
15
|
+
spec.add_dependency "rails", ">= 6.1.3"
|
16
16
|
spec.add_dependency "twirp", "~> 1.7.2"
|
17
17
|
end
|
@@ -11,7 +11,16 @@ class PingControllerTest < RailsTwirp::IntegrationTest
|
|
11
11
|
req = RPC::DummyAPI::PingRequest.new(name: "Bouke")
|
12
12
|
rpc RPC::DummyAPI::DummyService, "PingRender", req
|
13
13
|
refute_instance_of Twirp::Error, response
|
14
|
-
assert_equal "http://
|
14
|
+
assert_equal "http://www.example.com/twirp BoukeBouke", response.double_name
|
15
|
+
end
|
16
|
+
|
17
|
+
test "you can ping render with host and https" do
|
18
|
+
host! "localhost"
|
19
|
+
https!
|
20
|
+
req = RPC::DummyAPI::PingRequest.new(name: "Bouke")
|
21
|
+
rpc RPC::DummyAPI::DummyService, "PingRender", req
|
22
|
+
refute_instance_of Twirp::Error, response
|
23
|
+
assert_equal "https://localhost/twirp BoukeBouke", response.double_name
|
15
24
|
end
|
16
25
|
|
17
26
|
test "you can ping template" do
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_twirp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bouke van der Bijl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 6.1.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 6.1.3
|
27
27
|
- !ruby/object:Gem::Dependency
|