rack-passthrough 0.0.1 → 0.0.3

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
  SHA1:
3
- metadata.gz: d6c695fa461abb08160fffec592f524048c58268
4
- data.tar.gz: e9925d22ce1008edc22ced025893f86120e3ac32
3
+ metadata.gz: 8de2ce20df94b731c3f4e9c54764b7b2a7178f42
4
+ data.tar.gz: 4194ae3062eb676b1372f4b3f7f96c64176c5060
5
5
  SHA512:
6
- metadata.gz: a6daf856391430902151aae308b5d9e10bf6542e955151e6dcb9d433c628839b8a5d6e99e5a1c36a5a3c7b8479b16a61d12fb9bb06d28a22203d83408a8dd6f1
7
- data.tar.gz: 43af2ff888d8a051df1c9083f5e898f020b57e0335a5b93c238f18fdb8108c64f18a01c1fffebcc10f2eb93f004864b8983d972dfa3833fe5e3da7481eca6032
6
+ metadata.gz: 2d029af9fa12c8e7bcefe5379c5adbf8e7763bb93aec6b8ec0949ab8daa81c5e8cd746520a893b0acb49a3f0413fb33b3d39ca7f441aaaa6612c1338f55f809a
7
+ data.tar.gz: 75089a8a04fadb512d9349af5a79109f4e63cfb907b71a7d37356584b918d42cc5fb112e480db9283ae49f511f1251a27c992a5399c583f8bb058530069fa483
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module Passthrough
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -10,19 +10,45 @@ module Rack
10
10
  @endpoint = endpoint
11
11
  end
12
12
 
13
+ def to_normal_string(data)
14
+ if data.class == Array
15
+ data = data.join
16
+ else
17
+ data
18
+ end
19
+
20
+ data
21
+ end
22
+
13
23
  def call(env)
14
24
  request = Rack::Request.new(env)
15
25
  full_path = URI::join( @endpoint, request.path )
16
26
  # Set Query String
17
27
  full_path.query = request.query_string
18
28
  data = request.body.read
19
- body_data = JSON.parse( data ) unless data.blank?
29
+ # body_data = JSON.parse( data ) unless data.blank?
30
+ # body_data = Rack::Utils.parse_query( data ) unless data.blank?
20
31
  conn = HTTParty.method( request.request_method.downcase.to_sym )
21
32
 
22
- # Request to endpoint
23
- response = conn.call( full_path.to_s, { body: body_data } )
33
+ # Handle form-encoded or application/json
34
+ if env["action_dispatch.request.request_parameters"].blank?
35
+ body = Rack::Utils.parse_query( data ) unless data.blank?
36
+ else
37
+ body = env["action_dispatch.request.request_parameters"] unless data.blank?
38
+ end
39
+
40
+ response = conn.call( full_path.to_s, { body: body } )
41
+ headers = {}
42
+
43
+ response.headers.each do |key,value|
44
+ headers.merge!({ key => to_normal_string(value) })
45
+ end
46
+
47
+ puts "*******************"
48
+ puts response.body.inspect
49
+ puts "*******************"
24
50
 
25
- [ response.code , response.headers , [response.body] ]
51
+ [ response.code , headers , [response.body] ]
26
52
  end
27
53
  end
28
54
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-passthrough
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jo