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 +4 -4
- data/README.md +16 -19
- data/lib/senthor_rails/middleware.rb +15 -11
- 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: 72949fb011639389349af1ee48b2efb477c196cb1ccf759a686df3add5375cd3
|
|
4
|
+
data.tar.gz: f28f441a5023edbda0951f7d5eb6f2f8290ebf76182b00caaa3cc8578b25d391
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4e9851d50ec89342657036d6d04f96ffb3fad3ce58ca5f93fcd71879c15efad980fcf4a038a1acef0ffb802b827dcbedb1929b5b0120f71b4bcec0a7c10e0ddc
|
|
7
|
+
data.tar.gz: be14ef902ba19642a84978921673fbfc5a239303b699efec340b8508eb234db1961c33e9d0359420b3e250077280986537c1cb4116c9073b5769efa51c014527
|
data/README.md
CHANGED
|
@@ -1,39 +1,36 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Senthor_rails
|
|
2
2
|
|
|
3
|
-
|
|
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
|
|
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
|
|
16
|
+
gem install senthor_rails
|
|
21
17
|
```
|
|
22
18
|
|
|
23
19
|
## Usage
|
|
24
20
|
|
|
25
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
```
|
|
24
|
+
class Application < Rails::Application
|
|
25
|
+
(...)
|
|
26
|
+
config.middleware.use Senthor::Middleware
|
|
27
|
+
end
|
|
28
|
+
```
|
|
34
29
|
|
|
35
|
-
|
|
30
|
+
This middleware will :
|
|
36
31
|
|
|
37
|
-
|
|
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
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
80
|
-
[
|
|
83
|
+
rack_headers,
|
|
84
|
+
[response.body]
|
|
81
85
|
]
|
|
82
86
|
end
|
|
83
87
|
|