senthor_rails 1.0.0 → 1.2.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: c17882a5becfec10b1da9566cb6986acfa956b725cd5e0e6a4d1d7d540efbd57
4
- data.tar.gz: a654e11764da1434a21168b0bea121f4c13fd6932016af46b0393d995875b941
3
+ metadata.gz: 4c1aaf0c693429c26f975492d67cd0ca30222ecabb42dc6ca70a624eec3f0c13
4
+ data.tar.gz: 0a94dee8c603bc14801399ff0a9a07188003c723e3031f6ed908950dda96ac44
5
5
  SHA512:
6
- metadata.gz: d7765d120b15fb8924e855cbdac5df24ad62675f8f13dcc3615e6db0d916d9d786e736dc5f4ccc740b28e699f7eff211f75b5ecd8a04fef923e95f78da16cd2c
7
- data.tar.gz: 200f3cdf3b39492d8daeaf44029fc24cd7ef03718e2590b31cce0f11c8483810c134faf6015219dae5757bf0f6fd706c4e98ec59c732f524d6003d1eec329961
6
+ metadata.gz: a8e761fc23c5d86eac01798264b67fdae11aa6edd7e57c47f5e48d8c39fde9639b54f3cd76bcd7a44f32bf7aa2d30d79c174a2596284ed6122047b6ad031ffe0
7
+ data.tar.gz: 51ba9c14fe98ec007001aa5c4f0b63a203ef200cccd86d676bc1aad38246a4e5eaab73b9c70bdda841b42883a505b6ba84eba83b567a515f9a0fdcc8eb9054c1
@@ -55,7 +55,7 @@ module Senthor
55
55
  }
56
56
 
57
57
  # Call Senthor API fo check GET request authorization
58
- uri = URI('https://waf-api.senthor.io/api/check-request')
58
+ uri = URI('https://waf-api.senthor.io/api/verify-request')
59
59
  http = Net::HTTP.new(uri.host, uri.port)
60
60
  http.use_ssl = true
61
61
 
@@ -72,15 +72,49 @@ module Senthor
72
72
 
73
73
  response = http.request(request)
74
74
 
75
- # Handle 402 response like in JS
75
+ hop_by_hop = %w[
76
+ transfer-encoding connection keep-alive proxy-authenticate
77
+ proxy-authorization te trailers upgrade status
78
+ ].freeze
79
+
80
+ rack_headers = {}
81
+ response.each_header do |key, value|
82
+ next if hop_by_hop.include?(key.downcase)
83
+ rack_headers[key] = value
84
+ end
85
+ # Ensure Content-Type is always set
86
+ rack_headers['Content-Type'] ||= response['Content-Type'] || 'text/plain'
87
+
88
+ # Handle 403 - blocked request
89
+ if response.code.to_i == 403
90
+ return [
91
+ 403,
92
+ rack_headers,
93
+ [response.body]
94
+ ]
95
+ end
96
+
97
+ # Handle 402 - monetization
76
98
  if response.code.to_i == 402
77
99
  return [
78
100
  402,
79
- { 'Content-Type' => response['Content-Type'] || 'text/plain' },
101
+ rack_headers,
80
102
  [response.body]
81
103
  ]
82
104
  end
83
105
 
106
+ # Add payment response if needed
107
+ if response.code.to_i == 200
108
+ payment_header = response.each_header.find { |key, _| key.downcase == 'payment-response' }
109
+
110
+ if payment_header
111
+ # Continue through the stack, then append the header to the response
112
+ status, headers, body = @app.call(env)
113
+ headers['Payment-Response'] = payment_header[1]
114
+ return [status, headers, body]
115
+ end
116
+ end
117
+
84
118
  # Otherwise continue as normal
85
119
  @app.call(env)
86
120
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SenthorRails
4
- VERSION = "1.0.0"
4
+ VERSION = "1.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: senthor_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Senthor
@@ -23,7 +23,6 @@ files:
23
23
  - lib/senthor_rails.rb
24
24
  - lib/senthor_rails/middleware.rb
25
25
  - lib/senthor_rails/version.rb
26
- - senthor_rails-0.1.0.gem
27
26
  - sig/senthor_rails.rbs
28
27
  homepage: https://www.senthor.io
29
28
  licenses:
Binary file