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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbbbb985926e92df46b0a0e97096b82bb9764a585d207b43cf07d93a163ab52f
4
- data.tar.gz: c8b9a5c430c06656a56ef664c27bfd491b8653719345c8d9235c78e4add1fe04
3
+ metadata.gz: ce6e06c456ede8a3575dc2a1609863cd7f88bcbe04429f25d2b31119bc6ea96c
4
+ data.tar.gz: 90ee9e4bfc18e4a10c04b046ed6156d831f138ec90e45295a3a947ea26c0d5d1
5
5
  SHA512:
6
- metadata.gz: fa62bd96695d7e71d900617fbe2925f52a5f12808161da3749ea83aa9c7e0b1f6aa2f8f8fadb19d0a5b44768df1fc1bbd4169b6fdadfb7f5d5c85e46ea6990c6
7
- data.tar.gz: c19152f2d750c014c086d7824f6b77ce516beb71287cde790986448e19d7ddd0ca9596b44e605ede809a56c3e25f66a98cd909a20aaf88b62a1283f72c63bf52
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,16 +63,50 @@ module Senthor
63
63
 
64
64
  response = http.request(request)
65
65
 
66
- # Handle 402 response
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
- { 'Content-Type' => 'text/plain' },
71
- ['This content is protected by a paywall. Visit https://senthor.io to find out how to access the content.']
93
+ rack_headers,
94
+ [response.body]
72
95
  ]
73
96
  end
74
97
 
75
- puts "Continue"
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
@@ -1,3 +1,3 @@
1
1
  module SenthorRailsLegacy
2
- VERSION = "0.2.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: 0.2.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Senthor