Skip to content

Commit ba32539

Browse files
committed
Add Faraday Typhoeus adapter for HTTP/2 support
Updated Faraday to version 2.8 and added the faraday-typhoeus gem to enable HTTP/2 support and better mimic curl behavior, bypassing WAF/bot detection. Modified HttpClient to use the Typhoeus adapter. Updated Gemfile and Gemfile.lock dependencies accordingly.
1 parent ea349e4 commit ba32539

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

Gemfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ gem 'activesupport', '6.0.0'
1717
gem 'actionpack', '6.0.0'
1818
gem 'rails-html-sanitizer'
1919
gem "rack-timeout"
20-
gem "faraday"
20+
gem "faraday", "~> 2.7"
2121
gem 'faraday-retry'
2222
gem "autoprefixer-rails"
2323
gem "flutie"
@@ -46,6 +46,8 @@ gem 'airbrake'
4646
gem 'parallel'
4747
gem 'ruby-progressbar'
4848
gem "aws-sdk-s3", require: false
49+
# Faraday adapter using libcurl (HTTP/2 support, bypasses WAF/bot detection)
50+
gem 'faraday-typhoeus'
4951

5052
# deployment to server
5153
gem 'capistrano', '~> 3.8'

Gemfile.lock

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ GEM
8686
aws-sigv4 (~> 1.4)
8787
aws-sigv4 (1.4.0)
8888
aws-eventstream (~> 1, >= 1.0.2)
89+
base64 (0.3.0)
8990
builder (3.2.4)
9091
bullet (7.0.1)
9192
activesupport (>= 3.0.0)
@@ -131,18 +132,25 @@ GEM
131132
enumerize (2.5.0)
132133
activesupport (>= 3.2)
133134
erubi (1.10.0)
135+
ethon (0.15.0)
136+
ffi (>= 1.15.0)
134137
execjs (2.8.1)
135138
factory_bot (6.2.0)
136139
activesupport (>= 5.0.0)
137140
factory_bot_rails (6.2.0)
138141
factory_bot (~> 6.2.0)
139142
railties (>= 5.0.0)
140-
faraday (2.1.0)
141-
faraday-net_http (~> 2.0)
143+
faraday (2.8.1)
144+
base64
145+
faraday-net_http (>= 2.0, < 3.1)
142146
ruby2_keywords (>= 0.0.4)
143-
faraday-net_http (2.0.1)
147+
faraday-net_http (3.0.2)
144148
faraday-retry (2.2.1)
145149
faraday (~> 2.0)
150+
faraday-typhoeus (1.1.0)
151+
faraday (~> 2.0)
152+
typhoeus (~> 1.4)
153+
ffi (1.17.2)
146154
flutie (2.2.0)
147155
font-awesome-rails (4.7.0.8)
148156
railties (>= 3.2, < 8.0)
@@ -355,6 +363,8 @@ GEM
355363
thread_safe (0.3.6)
356364
tilt (2.0.10)
357365
timecop (0.9.4)
366+
typhoeus (1.5.0)
367+
ethon (>= 0.9.0, < 0.16.0)
358368
tzinfo (1.2.10)
359369
thread_safe (~> 0.1)
360370
unf (0.1.4)
@@ -395,8 +405,9 @@ DEPENDENCIES
395405
enumerize
396406
execjs
397407
factory_bot_rails
398-
faraday
408+
faraday (~> 2.7)
399409
faraday-retry
410+
faraday-typhoeus
400411
flutie
401412
font-awesome-rails
402413
formulaic

app/services/http_client.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ def setup_connection(base_url, timeout: 10, open_timeout: 5, retries: 3)
2323
f.response :raise_error # 40x, 50x errors -> Faraday::ClientError, Faraday::ServerError
2424
# convert JSON string to Ruby hash inside body if header is application/json
2525
f.response :json # fails with Faraday::ParsingError
26-
f.adapter Faraday.default_adapter # keep for clarity
26+
# Use Typhoeus adapter with HTTP/2 support to mimic curl behavior
27+
f.adapter :typhoeus, http_version: :httpv2_0
2728
f.options.timeout = timeout # max timeout for request
2829
f.options.open_timeout = open_timeout # for connection to open
2930
end

0 commit comments

Comments
 (0)