senthor_rails_legacy 0.2.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_legacy/middleware.rb +39 -5
- data/lib/senthor_rails_legacy/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: ce6e06c456ede8a3575dc2a1609863cd7f88bcbe04429f25d2b31119bc6ea96c
|
|
4
|
+
data.tar.gz: 90ee9e4bfc18e4a10c04b046ed6156d831f138ec90e45295a3a947ea26c0d5d1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 42a06ead245c8df5b99bd64f35f2ab439b7b8fbc34a78ee0c5d850e12712929d4f260aa60007230e47ee764026bb0b41b13007cdc0b734ea104c6cea379cce4e
|
|
7
|
+
data.tar.gz: 8c530b713e8bf740ac1eeb40e63142fa802e97abb3915931323cee6825ce950ed821997771a4e4c31841f245daf07766fc98a456fc288bc6d417229fa0ffed32
|
|
@@ -46,7 +46,7 @@ module Senthor
|
|
|
46
46
|
client_ip: client_ip
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
uri = URI('https://waf-api.senthor.io/api/
|
|
49
|
+
uri = URI('https://waf-api.senthor.io/api/verify-request')
|
|
50
50
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
51
51
|
http.use_ssl = true
|
|
52
52
|
|
|
@@ -63,16 +63,50 @@ module Senthor
|
|
|
63
63
|
|
|
64
64
|
response = http.request(request)
|
|
65
65
|
|
|
66
|
-
#
|
|
66
|
+
# Set headers
|
|
67
|
+
hop_by_hop = %w[
|
|
68
|
+
transfer-encoding connection keep-alive proxy-authenticate
|
|
69
|
+
proxy-authorization te trailers upgrade status
|
|
70
|
+
].freeze
|
|
71
|
+
|
|
72
|
+
rack_headers = {}
|
|
73
|
+
response.each_header do |key, value|
|
|
74
|
+
next if hop_by_hop.include?(key.downcase)
|
|
75
|
+
rack_headers[key] = value
|
|
76
|
+
end
|
|
77
|
+
# Ensure Content-Type is always set
|
|
78
|
+
rack_headers['Content-Type'] ||= response['Content-Type'] || 'text/plain'
|
|
79
|
+
|
|
80
|
+
# Handle 403 - blocked request
|
|
81
|
+
if response.code.to_i == 403
|
|
82
|
+
return [
|
|
83
|
+
403,
|
|
84
|
+
rack_headers,
|
|
85
|
+
[response.body]
|
|
86
|
+
]
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Handle 402 - monetization
|
|
67
90
|
if response.code.to_i == 402
|
|
68
91
|
return [
|
|
69
92
|
402,
|
|
70
|
-
|
|
71
|
-
[
|
|
93
|
+
rack_headers,
|
|
94
|
+
[response.body]
|
|
72
95
|
]
|
|
73
96
|
end
|
|
74
97
|
|
|
75
|
-
|
|
98
|
+
# Add payment response if needed
|
|
99
|
+
if response.code.to_i == 200
|
|
100
|
+
payment_header = response.each_header.find { |key, _| key.downcase == 'payment-response' }
|
|
101
|
+
|
|
102
|
+
if payment_header
|
|
103
|
+
# Continue through the stack, then append the header to the response
|
|
104
|
+
status, headers, body = @app.call(env)
|
|
105
|
+
headers['Payment-Response'] = payment_header[1]
|
|
106
|
+
return [status, headers, body]
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
76
110
|
# Otherwise continue as normal
|
|
77
111
|
@app.call(env)
|
|
78
112
|
end
|