senthor_rails 0.1.0 → 1.1.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: e4f7db43a175a1dde7949f2fa93c2f114566545168d430fc1ab1187357799a6d
4
- data.tar.gz: 858c4bb3b2d4b0341c341e5fe58b82c0a27ec726030c4aaa587b2170be5a2523
3
+ metadata.gz: 72949fb011639389349af1ee48b2efb477c196cb1ccf759a686df3add5375cd3
4
+ data.tar.gz: f28f441a5023edbda0951f7d5eb6f2f8290ebf76182b00caaa3cc8578b25d391
5
5
  SHA512:
6
- metadata.gz: 990e9b1c4dc5fb7780cca279bfbab6b81f57fd0ced9d4e709b47c244f0b2ceb9766dacf285fbbb587049e4e13a4cef2c9f84dca219acafec925bb417c7e473ed
7
- data.tar.gz: e79a5da49b9ac08bce8a03e2f35203f9b48426a070f3d45c09ace588a663540ffc3bc2cd731199cdabd7babda30c7df015add6e8f61c2798fc2036a4e9ac2874
6
+ metadata.gz: 4e9851d50ec89342657036d6d04f96ffb3fad3ce58ca5f93fcd71879c15efad980fcf4a038a1acef0ffb802b827dcbedb1929b5b0120f71b4bcec0a7c10e0ddc
7
+ data.tar.gz: be14ef902ba19642a84978921673fbfc5a239303b699efec340b8508eb234db1961c33e9d0359420b3e250077280986537c1cb4116c9073b5769efa51c014527
data/README.md CHANGED
@@ -1,39 +1,36 @@
1
- # SenthorRails
1
+ # Senthor_rails
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
4
-
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/senthor_rails`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Drop-in Senthor middleware for Ruby on Rails
6
4
 
7
5
  ## Installation
8
6
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
-
11
7
  Install the gem and add to the application's Gemfile by executing:
12
8
 
13
9
  ```bash
14
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
10
+ bundle add senthor_rails
15
11
  ```
16
12
 
17
13
  If bundler is not being used to manage dependencies, install the gem by executing:
18
14
 
19
15
  ```bash
20
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
16
+ gem install senthor_rails
21
17
  ```
22
18
 
23
19
  ## Usage
24
20
 
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
21
+ In `config/application.rb`, activate the middleware
30
22
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
23
+ ```
24
+ class Application < Rails::Application
25
+ (...)
26
+ config.middleware.use Senthor::Middleware
27
+ end
28
+ ```
34
29
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/senthor_rails.
30
+ This middleware will :
36
31
 
37
- ## License
32
+ - Intercept GET requests
33
+ - Call the Senthor API
34
+ - Detect if it's from AI and act accordingly based on your Senthor settings
38
35
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
36
+ If your website isn't configured on Senthor, all requests will pass through.
@@ -27,15 +27,15 @@ module Senthor
27
27
  # Collect all headers
28
28
  headers = {}
29
29
  excluded_headers = %w[
30
- AUTHORIZATION
31
- COOKIE
32
- SET_COOKIE
33
- PROXY_AUTHORIZATION
34
- X_CSRF_TOKEN
35
- X_XSRF_TOKEN
36
- X_API_KEY
37
- X_ACCESS_TOKEN
38
- ]
30
+ AUTHORIZATION
31
+ COOKIE
32
+ SET_COOKIE
33
+ PROXY_AUTHORIZATION
34
+ X_CSRF_TOKEN
35
+ X_XSRF_TOKEN
36
+ X_API_KEY
37
+ X_ACCESS_TOKEN
38
+ ]
39
39
  env.each do |key, value|
40
40
  if key.start_with?('HTTP_')
41
41
  header_name = key.sub(/^HTTP_/, '').upcase
@@ -72,12 +72,16 @@ module Senthor
72
72
 
73
73
  response = http.request(request)
74
74
 
75
+ rack_headers = { 'Content-Type' => response['Content-Type'] || 'text/plain' }
76
+ response.each_header do |key, value|
77
+ rack_headers[key] = value if key.downcase.start_with?('crawler-')
78
+ end
75
79
  # Handle 402 response like in JS
76
80
  if response.code.to_i == 402
77
81
  return [
78
82
  402,
79
- { 'Content-Type' => 'text/plain' },
80
- ['This content is protected by a paywall. Visit https://senthor.io to find out how to access the content.']
83
+ rack_headers,
84
+ [response.body]
81
85
  ]
82
86
  end
83
87
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SenthorRails
4
- VERSION = "0.1.0"
4
+ VERSION = "1.1.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: 0.1.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Senthor