senthor_rails_legacy 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6afd4a0504d904f25bcedb1e35ccb0669332f6b9b3aaf4d4c0d7fbda3b0dfab
4
- data.tar.gz: 653b1bd312052d3ea4816d116b5cec0247d5924d7808c3ffe13d491a1f3d0ac2
3
+ metadata.gz: ce6e06c456ede8a3575dc2a1609863cd7f88bcbe04429f25d2b31119bc6ea96c
4
+ data.tar.gz: 90ee9e4bfc18e4a10c04b046ed6156d831f138ec90e45295a3a947ea26c0d5d1
5
5
  SHA512:
6
- metadata.gz: 22e5f758e1b84afcb0dbea0ecedb83a4d814c74689c268ca1aa01b3b821f81cf2c1712b9119b1ec984aa3255636822f3632a7e151eed0398fbd349bd72f9ed2c
7
- data.tar.gz: 6a8b501cbec87cdcead2a415fb3a3e50b9a2dcfe639f9cbfdf20cf075ebc6503dcb559669445b950be5900f88e32a9ae8ac693f551570b0359f013a0518d4e08
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/check-request')
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,12 +63,30 @@ module Senthor
63
63
 
64
64
  response = http.request(request)
65
65
 
66
- rack_headers = { 'Content-Type' => response['Content-Type'] || 'text/plain' }
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 = {}
67
73
  response.each_header do |key, value|
68
- rack_headers[key] = value if key.downcase.start_with?('crawler-')
74
+ next if hop_by_hop.include?(key.downcase)
75
+ rack_headers[key] = value
69
76
  end
77
+ # Ensure Content-Type is always set
78
+ rack_headers['Content-Type'] ||= response['Content-Type'] || 'text/plain'
70
79
 
71
- # Handle 402 response
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
72
90
  if response.code.to_i == 402
73
91
  return [
74
92
  402,
@@ -77,6 +95,18 @@ module Senthor
77
95
  ]
78
96
  end
79
97
 
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
+
80
110
  # Otherwise continue as normal
81
111
  @app.call(env)
82
112
  end
@@ -1,3 +1,3 @@
1
1
  module SenthorRailsLegacy
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: senthor_rails_legacy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Senthor