senthor_rails 1.1.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 +4 -4
- data/lib/senthor_rails/middleware.rb +34 -4
- data/lib/senthor_rails/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4c1aaf0c693429c26f975492d67cd0ca30222ecabb42dc6ca70a624eec3f0c13
|
|
4
|
+
data.tar.gz: 0a94dee8c603bc14801399ff0a9a07188003c723e3031f6ed908950dda96ac44
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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/
|
|
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,11 +72,29 @@ module Senthor
|
|
|
72
72
|
|
|
73
73
|
response = http.request(request)
|
|
74
74
|
|
|
75
|
-
|
|
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 = {}
|
|
76
81
|
response.each_header do |key, value|
|
|
77
|
-
|
|
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
|
+
]
|
|
78
95
|
end
|
|
79
|
-
|
|
96
|
+
|
|
97
|
+
# Handle 402 - monetization
|
|
80
98
|
if response.code.to_i == 402
|
|
81
99
|
return [
|
|
82
100
|
402,
|
|
@@ -85,6 +103,18 @@ module Senthor
|
|
|
85
103
|
]
|
|
86
104
|
end
|
|
87
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
|
+
|
|
88
118
|
# Otherwise continue as normal
|
|
89
119
|
@app.call(env)
|
|
90
120
|
end
|