rails_twirp 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 34fc8b4e84ba8c456ac2fa01c3c35dd0fd11224360d6e21b832b5d17ed1f57a5
4
- data.tar.gz: 9626b771c35bfdd034fa1dccad6ef5ed921aad0abdf3086bfe27a6b3b26f50b9
3
+ metadata.gz: 0ed88410115867b689de324aeaf99b91ba473d3aa573915d9bec5de1142b7986
4
+ data.tar.gz: dadc45ad3c6ed38f6791e8a45573127c69297772a7b0ae4861a2867dadf26d09
5
5
  SHA512:
6
- metadata.gz: e4621381feff50a031faf89079aa49054d246bd52f0e9d0fe4fe588f3014c2dd9a779f249aa16ac15340d9e259b61e273b393dd6a69ecaa15b5bf76c29578434
7
- data.tar.gz: e91d714d2ef9c5e6a45e34911a29de4c1927d2e8442c5bf3538c5c43f137c10010b0282d9a5f2d4c5901d9c1733191cd0e7ff4e2764d8ae546233798ef81d64b
6
+ metadata.gz: 976f3755035c22c65db62aa4b82e8019bf816e5e30cec968e19c5345630aa1b7c6d51d38439e267fde4d9696ce05667c5a2ed2566953bbe87a175ac2ea9df93f
7
+ data.tar.gz: f3c1460d7cd0ae988e8aabbb516afd1983b975e8aee872f295eb3017061a51500667ee1ecbd226f2260c03f179ad94560227710fc98095e0e60749288271d406
@@ -50,12 +50,12 @@ 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|
57
+ controller_name = mapping.controller.underscore
58
+ const_name = controller_name.camelize << "Controller"
59
59
  controller_class = ::ActiveSupport::Dependencies.constantize(const_name)
60
60
  controller_class.dispatch(action_name, req, response_class, env)
61
61
  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 :mount_path! :mount_path=
9
11
 
10
12
  def initialize(name)
11
13
  super
12
14
  reset!
13
15
  @before_rpc = []
14
- @mount_path = "/twirp"
16
+ end
17
+
18
+ def host
19
+ @host || DEFAULT_HOST
20
+ end
21
+ attr_writer :host
22
+ alias :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
- "HTTP_HOST" => "localhost",
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)
@@ -1,3 +1,3 @@
1
1
  module RailsTwirp
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  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://localhost/twirp BoukeBouke", response.double_name
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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_twirp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bouke van der Bijl