wreq 1.0.0-aarch64-linux

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3a0259c5fea235b2274124cf621972c235d25326a05b5c588094b56c7ed02786
4
+ data.tar.gz: a2909c511ae39920ea58ebca509ed664651f0738bb725b227555ebcaf6292da9
5
+ SHA512:
6
+ metadata.gz: f0808ac3123808feb4e8ada109dac13acd15723edb927c612ae0ea038ad5510bc525ef1fd3eab37b3785d83272b5cee7e490c39712040892457e211f0341dd16
7
+ data.tar.gz: fb4d6ef7a0cd7eeef7d5ee61a323f22f09a85429add8cb35c4a7226984cb689926586e9a8cb1cf37e9cc43b0121a3eadb842cd8045611c21a5812b5a7ba9ef1f
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Includes runtime dependencies from wreq.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem "rake", ">= 13.2"
8
+ gem "rb_sys", "~> 0.9.110" # for Makefile generation in extconf.rb
9
+ gem "rake-compiler", "~> 1.2.9" # to build a debug build
10
+ gem "minitest", "~> 6.0" # test library
11
+ gem "activesupport", "~> 8.0.1" # testing support
12
+ gem "standard", "~> 1.52" # linter with pre-specified rules
13
+ gem "redcarpet", "~> 3.6" # for documentation markdown parsing
14
+ gem "ruby-lsp", "~> 0.22" # Ruby language server for IDE support
15
+ gem "racc", "~> 1.8.1" # for parsing
16
+ gem "observer", "~> 0.1.2" # for parsing
17
+ end
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 SearchApi <support@searchapi.io>
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,150 @@
1
+ # wreq-ruby
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/wreq.svg)](https://rubygems.org/gems/wreq)
4
+ [![CI](https://github.com/SearchApi/wreq-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/SearchApi/wreq-ruby/actions/workflows/ci.yml)
5
+
6
+ An easy and powerful Ruby HTTP client with advanced browser fingerprinting that accurately emulates **Chrome**, **Edge**, **Firefox**, **Safari**, **Opera**, and **OkHttp**, with precise **TLS/HTTP2** signatures, and powered by [wreq](https://github.com/0x676e67/wreq).
7
+
8
+ ## Features
9
+
10
+ - Plain bodies, JSON, urlencoded
11
+ - Cookie Store
12
+ - Redirect Policy
13
+ - Original Headers
14
+ - Rotating Proxies
15
+ - Connection Pooling
16
+ - Streaming Transfers
17
+ - HTTPS via BoringSSL
18
+ - Free-Threaded Safety
19
+ - Automatic Decompression
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ gem install wreq
25
+ ```
26
+
27
+ Or add to your Gemfile:
28
+
29
+ ```ruby
30
+ gem "wreq"
31
+ ```
32
+
33
+ Pre-compiled native gems are available for:
34
+ - Linux (x86_64, aarch64)
35
+ - macOS (arm64)
36
+
37
+ ## Example
38
+
39
+ ```ruby
40
+ require "wreq"
41
+
42
+ # Build a client
43
+ client = Wreq::Client.new(emulation: Wreq::Emulation.new(
44
+ device: Wreq::EmulationDevice::Chrome145,
45
+ os: Wreq::EmulationOS::MacOS,
46
+ skip_http2: false,
47
+ skip_headers: false
48
+ ))
49
+
50
+ # Use the API you're already familiar with
51
+ resp = client.get("https://tls.peet.ws/api/all")
52
+ puts resp.text
53
+ ```
54
+
55
+ Additional learning resources include:
56
+
57
+ - [API Documentation](https://github.com/SearchApi/wreq-ruby/tree/main/lib)
58
+ - [Repository Tests](https://github.com/SearchApi/wreq-ruby/tree/main/test)
59
+ - [Repository Examples](https://github.com/SearchApi/wreq-ruby/tree/main/examples)
60
+
61
+ ## Browser Emulation
62
+
63
+ 1. **HTTP/2 over TLS**
64
+
65
+ Due to the complexity of TLS encryption and the widespread adoption of HTTP/2, browser fingerprints such as **JA3**, **JA4**, and **Akamai** cannot be reliably emulated using simple fingerprint strings. Instead of parsing and emulating these string-based fingerprints, `wreq` provides fine-grained control over TLS and HTTP/2 extensions and settings for precise browser behavior emulation.
66
+
67
+ 2. **Device Emulation**
68
+
69
+ Most browser device models share identical TLS and HTTP/2 configurations, differing only in the `User-Agent` string.
70
+
71
+ - <details>
72
+ <summary>Available OS emulations</summary>
73
+
74
+ | **OS** | **Description** |
75
+ | ----------- | ------------------------------ |
76
+ | **Windows** | Windows (any version) |
77
+ | **MacOS** | macOS (any version) |
78
+ | **Linux** | Linux (any distribution) |
79
+ | **Android** | Android (mobile) |
80
+ | **iOS** | iOS (iPhone/iPad) |
81
+
82
+ </details>
83
+
84
+ <!-- Emulation profiles sourced from src/emulation.rs - keep in sync -->
85
+
86
+ - <details>
87
+ <summary>Available browser emulations</summary>
88
+
89
+ | **Browser** | **Versions** |
90
+ | ----------- | ------------ |
91
+ | **Chrome** | `Chrome100`, `Chrome101`, `Chrome104`, `Chrome105`, `Chrome106`, `Chrome107`, `Chrome108`, `Chrome109`, `Chrome110`, `Chrome114`, `Chrome116`, `Chrome117`, `Chrome118`, `Chrome119`, `Chrome120`, `Chrome123`, `Chrome124`, `Chrome126`, `Chrome127`, `Chrome128`, `Chrome129`, `Chrome130`, `Chrome131`, `Chrome132`, `Chrome133`, `Chrome134`, `Chrome135`, `Chrome136`, `Chrome137`, `Chrome138`, `Chrome139`, `Chrome140`, `Chrome141`, `Chrome142`, `Chrome143`, `Chrome144`, `Chrome145` |
92
+ | **Edge** | `Edge101`, `Edge122`, `Edge127`, `Edge131`, `Edge134`, `Edge135`, `Edge136`, `Edge137`, `Edge138`, `Edge139`, `Edge140`, `Edge141`, `Edge142`, `Edge143`, `Edge144`, `Edge145` |
93
+ | **Firefox** | `Firefox109`, `Firefox117`, `Firefox128`, `Firefox133`, `Firefox135`, `FirefoxPrivate135`, `FirefoxAndroid135`, `Firefox136`, `FirefoxPrivate136`, `Firefox139`, `Firefox142`, `Firefox143`, `Firefox144`, `Firefox145`, `Firefox146`, `Firefox147` |
94
+ | **Safari** | `Safari15_3`, `Safari15_5`, `Safari15_6_1`, `Safari16`, `Safari16_5`, `Safari17_0`, `Safari17_2_1`, `Safari17_4_1`, `Safari17_5`, `Safari17_6`, `Safari18`, `Safari18_2`, `Safari18_3`, `Safari18_3_1`, `Safari18_5`, `Safari26`, `Safari26_1`, `Safari26_2`, `SafariIos16_5`, `SafariIos17_2`, `SafariIos17_4_1`, `SafariIos18_1_1`, `SafariIos26`, `SafariIos26_2`, `SafariIPad18`, `SafariIPad26`, `SafariIpad26_2` |
95
+ | **OkHttp** | `OkHttp3_9`, `OkHttp3_11`, `OkHttp3_13`, `OkHttp3_14`, `OkHttp4_9`, `OkHttp4_10`, `OkHttp4_12`, `OkHttp5` |
96
+ | **Opera** | `Opera116`, `Opera117`, `Opera118`, `Opera119` |
97
+
98
+ </details>
99
+
100
+ ## Building
101
+
102
+ Install the BoringSSL build environment by referring to [boring](https://github.com/cloudflare/boring/blob/master/.github/workflows/ci.yml) and [boringssl](https://github.com/google/boringssl/blob/master/BUILDING.md#build-prerequisites).
103
+
104
+ ```bash
105
+ # Prerequisites: Install build dependencies
106
+ # on ubuntu or debian
107
+ sudo apt install -y build-essential cmake perl pkg-config libclang-dev musl-tools git
108
+ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
109
+
110
+ # Install dependencies
111
+ bundle install
112
+
113
+ # Option 1: Build source gem (requires compilation during install)
114
+ # This approach requires users to have Rust toolchain and build environment.
115
+ # Installation will show "Building native extensions. This could take a while..."
116
+ gem build wreq.gemspec
117
+ gem install wreq-*.gem
118
+
119
+ # Option 2: Build pre-compiled platform gem (recommended for distribution)
120
+ # This creates a platform-specific gem (e.g., wreq-0.1.0-arm64-darwin.gem)
121
+ # with pre-compiled binaries. Users can install quickly without build environment.
122
+ bundle exec rake compile
123
+ bundle exec rake native gem
124
+ gem install pkg/wreq-*.gem
125
+
126
+ # Development workflow
127
+ bundle exec rake compile # Compile for development/testing
128
+ bundle exec rake test # Run tests
129
+ bundle exec ruby examples/body.rb # Run examples without installing
130
+ ```
131
+
132
+ ## License
133
+
134
+ Licensed under either of Apache License, Version 2.0 ([LICENSE](./LICENSE) or http://www.apache.org/licenses/LICENSE-2.0).
135
+
136
+ ## Contributing
137
+
138
+ Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the [Apache-2.0](./LICENSE) license, shall be licensed as above, without any additional terms or conditions.
139
+
140
+ ## Maintained by
141
+
142
+ <a href="https://www.searchapi.io">
143
+ <picture>
144
+ <source media="(prefers-color-scheme: dark)" srcset="https://www.searchapi.io/press/v2/svg/searchapi_logo_white_h.svg">
145
+ <source media="(prefers-color-scheme: light)" srcset="https://www.searchapi.io/press/v2/svg/searchapi_logo_black_h.svg">
146
+ <img alt="SearchAPI" src="https://www.searchapi.io/press/v2/svg/searchapi_logo_black_h.svg" height="40px" style="vertical-align: middle;">
147
+ </picture>
148
+ </a>
149
+
150
+ [SearchApi](https://www.searchapi.io) - real-time low-latency SERP API with 100+ scrapers. Trusted by Fortune 500 and leading AI companies.
data/Rakefile ADDED
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+ require "rb_sys/extensiontask"
6
+
7
+ begin
8
+ require "standard/rake"
9
+ rescue LoadError
10
+ # standard gem not available in cross-compilation environment
11
+ end
12
+
13
+ GEMSPEC = Gem::Specification.load("wreq.gemspec") || abort("Could not load wreq.gemspec")
14
+ CRATE_PACKAGE_NAME = "wreq-ruby"
15
+
16
+ RbSys::ExtensionTask.new(CRATE_PACKAGE_NAME, GEMSPEC) do |ext|
17
+ ext.name = "wreq_ruby"
18
+ ext.ext_dir = "."
19
+ ext.lib_dir = "lib/wreq_ruby"
20
+ ext.cross_compile = true
21
+ # arm64-darwin is built natively on macOS (see .github/workflows/release.yml)
22
+ ext.cross_platform = %w[
23
+ x86_64-linux
24
+ aarch64-linux
25
+ ]
26
+
27
+ # Override Ruby version for native gems (keep in sync with wreq.gemspec)
28
+ ext.cross_compiling do |spec|
29
+ spec.required_ruby_version = ">= 3.3", "< 4.1.dev"
30
+ end
31
+ end
32
+
33
+ Rake::TestTask.new(:ruby_test) do |t|
34
+ t.libs << "lib"
35
+ t.libs << "test"
36
+ t.pattern = "test/**/*_test.rb"
37
+ end
38
+
39
+ desc "Run Rust tests"
40
+ task :cargo_test do
41
+ sh "cargo test"
42
+ end
43
+
44
+ desc "Format Rust code"
45
+ task :fmt do
46
+ sh "cargo fmt"
47
+ end
48
+
49
+ desc "Run Clippy linter"
50
+ task :lint do
51
+ sh "cargo clippy -- -D warnings"
52
+ end
53
+
54
+ desc "Build native gem for platform (e.g., rake 'native[x86_64-linux]')"
55
+ task :native, [:platform] do |_t, args|
56
+ abort "Usage: rake 'native[PLATFORM]' (e.g., x86_64-linux, aarch64-linux)" unless args[:platform]
57
+ sh "bundle", "exec", "rb-sys-dock", "--platform", args[:platform], "--build"
58
+ end
59
+
60
+ task purge: %i[clean clobber]
61
+
62
+ desc "Print gem version"
63
+ task :version do
64
+ print GEMSPEC.version
65
+ end
66
+
67
+ task test: %i[compile ruby_test cargo_test]
68
+ task default: %i[compile test]
69
+
70
+ # Override bundler's release to push all platform gems
71
+ Rake::Task["release"].clear
72
+ Rake::Task["release:rubygem_push"].clear if Rake::Task.task_defined?("release:rubygem_push")
73
+
74
+ desc "Release all platform gems to RubyGems"
75
+ task release: ["release:guard_clean", "release:rubygem_push"]
76
+
77
+ namespace :release do
78
+ task :rubygem_push do
79
+ gem_files = Dir.glob("pkg/#{GEMSPEC.name}-*.gem").sort
80
+ abort "No gems found in pkg/" if gem_files.empty?
81
+
82
+ puts "Pushing #{gem_files.length} gem(s):"
83
+ gem_files.each { |f| puts " - #{File.basename(f)}" }
84
+
85
+ gem_files.each do |gem_file|
86
+ puts "\nPushing #{File.basename(gem_file)}..."
87
+ sh "gem push #{gem_file}"
88
+ end
89
+ end
90
+ end
data/examples/body.rb ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Example: Using Wreq::Response headers methods
4
+ # Demonstrates the different ways to access HTTP response headers
5
+
6
+ require_relative "../lib/wreq"
7
+
8
+ # Make a request
9
+ client = Wreq::Client.new
10
+ response = client.post("https://httpbin.io/anything",
11
+ json: {foo: "bar", baz: "qux"},
12
+ headers: {"Content-Type" => "application/json"},
13
+ cookies: {"session_id" => "abc123",
14
+ "user" => "test_user"})
15
+
16
+ puts "\n=== Iterating Over All Headers ==="
17
+ response.headers.each do |name, value|
18
+ puts "#{name}: #{value}"
19
+ end
20
+
21
+ puts "\n=== Response Summary ==="
22
+ puts "Status: #{response.code}"
23
+ puts "Version: #{response.version}"
24
+ puts "URI: #{response.url}"
25
+ puts "Content Length: #{response.content_length || "Unknown"}"
26
+
27
+ if response.local_addr
28
+ puts "Local Address: #{response.local_addr}"
29
+ end
30
+
31
+ if response.remote_addr
32
+ puts "Remote Address: #{response.remote_addr}"
33
+ end
34
+
35
+ puts "\n=== Response Body as Text ==="
36
+ puts response.text
37
+
38
+ puts "\n=== Response Body as JSON ==="
39
+ json = response.json
40
+ puts json
41
+ puts json["json"]
42
+ puts json["headers"]["Content-Type"]
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../lib/wreq"
4
+
5
+ puts "--- Example 1: Invalid Proxy URL ---"
6
+ begin
7
+ client = Wreq::Client.new(
8
+ user_agent: "WreqClient/1.0",
9
+ headers: {
10
+ "User-Agent" => "WreqClient/1.0",
11
+ "Accept" => "application/json",
12
+ "App" => "WreqExample",
13
+ "Cookie2" => "sessionid=abc123",
14
+ "Cookie" => "preferences=darkmode"
15
+ },
16
+ timeout: 10,
17
+ gzip: true,
18
+ brotli: true,
19
+ proxy: "http:://localhost:8080"
20
+ )
21
+ puts "Client created successfully: #{client.inspect}"
22
+ s = client.get("https://httpbin.io/anything", headers: {"Custom-Header" => "CustomValue"}, basic_auth: ["user", "pass"])
23
+ code = s.code
24
+ puts "Response code: #{code}"
25
+ rescue Wreq::BuilderError => e
26
+ puts "❌ BuilderError caught!"
27
+ puts "Error message: #{e.message}"
28
+ puts "Error class: #{e.class}"
29
+ puts "Backtrace (first 3 lines):"
30
+ puts e.backtrace.first(3).map { |line| " #{line}" }
31
+ rescue => e
32
+ puts "❌ Unexpected error: #{e.class} - #{e.message}"
33
+ end
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../lib/wreq"
4
+
5
+ # Example: How to use Emulation options in Wreq requests
6
+ #
7
+ # Emulation can be set globally on the client (applies to all requests),
8
+ # or per-request (overrides client default for that call).
9
+ #
10
+ # Global client emulation:
11
+ # Set when creating the Wreq::Client instance.
12
+ # All requests from this client will use the specified emulation unless overridden.
13
+ client = Wreq::Client.new(emulation: Wreq::Emulation.new(
14
+ device: Wreq::EmulationDevice::Chrome142,
15
+ os: Wreq::EmulationOS::MacOS,
16
+ skip_http2: false,
17
+ skip_headers: false
18
+ ))
19
+
20
+ resp = client.get("https://tls.peet.ws/api/all")
21
+ puts resp.text
22
+
23
+ # Per-request emulation:
24
+ # Pass the emulation option to a single request method.
25
+ # This allows you to override the client default for specific calls.
26
+ resp = client.get(
27
+ "https://tls.peet.ws/api/all",
28
+ emulation: Wreq::Emulation.new(
29
+ device: Wreq::EmulationDevice::Safari26,
30
+ os: Wreq::EmulationOS::MacOS,
31
+ skip_http2: false,
32
+ skip_headers: false
33
+ ),
34
+ # Skip client default headers for this request
35
+ default_headers: false
36
+ )
37
+ puts resp.text
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../lib/wreq"
4
+
5
+ # Make a request
6
+ client = Wreq::Client.new
7
+ response = client.get("https://httpbin.io/headers")
8
+
9
+ puts "\n=== Iterating Over All Headers ==="
10
+ response.headers.each do |name, value|
11
+ puts "#{name}: #{value}"
12
+ end
13
+
14
+ puts "\n=== Response Summary ==="
15
+ puts "Status: #{response.code}"
16
+ puts "Version: #{response.version}"
17
+ puts "URI: #{response.url}"
18
+ puts "Content Length: #{response.content_length || "Unknown"}"
19
+ puts response.headers
20
+
21
+ if response.local_addr
22
+ puts "Local Address: #{response.local_addr}"
23
+ end
24
+
25
+ if response.remote_addr
26
+ puts "Remote Address: #{response.remote_addr}"
27
+ end