proxied_request 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5590485b177d091030b6ef71d5966c6dc5933e6267a0ce5e067ee03021b2c316
4
+ data.tar.gz: 4f1eb2de2674174e61b106e7031f8c797e4e9d0063f771727e8c7f8874d6c830
5
+ SHA512:
6
+ metadata.gz: b143ad0e824660f7485514680fc20728374dc3a56dfd789e5db2492f9ec204ac8d2bce2a7a19d44b02ebd38c0ccc0c81272a142d6bfdcf19acd682d6c53678f0
7
+ data.tar.gz: 2036d716fd5caa09a47031d746945398df8223d2afa2469d8975f6e07ec76319114e2e97887a22f68b8f9f5f855e4e081b1d0182a3286b6e6d30bc50e2cabe29
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
3
+ ruby_version: 2.6
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in proxied_request.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+ gem 'rspec'
10
+ gem "standard", "~> 1.3"
11
+ gem 'socksify', '~> 1.7'
data/Gemfile.lock ADDED
@@ -0,0 +1,81 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ proxied_request (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ base64 (0.1.1)
11
+ diff-lcs (1.5.0)
12
+ json (2.6.3)
13
+ language_server-protocol (3.17.0.3)
14
+ lint_roller (1.1.0)
15
+ parallel (1.23.0)
16
+ parser (3.2.2.4)
17
+ ast (~> 2.4.1)
18
+ racc
19
+ racc (1.7.1)
20
+ rainbow (3.1.1)
21
+ rake (13.0.6)
22
+ regexp_parser (2.8.1)
23
+ rexml (3.2.6)
24
+ rspec (3.12.0)
25
+ rspec-core (~> 3.12.0)
26
+ rspec-expectations (~> 3.12.0)
27
+ rspec-mocks (~> 3.12.0)
28
+ rspec-core (3.12.2)
29
+ rspec-support (~> 3.12.0)
30
+ rspec-expectations (3.12.3)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.12.0)
33
+ rspec-mocks (3.12.6)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.12.0)
36
+ rspec-support (3.12.1)
37
+ rubocop (1.56.4)
38
+ base64 (~> 0.1.1)
39
+ json (~> 2.3)
40
+ language_server-protocol (>= 3.17.0)
41
+ parallel (~> 1.10)
42
+ parser (>= 3.2.2.3)
43
+ rainbow (>= 2.2.2, < 4.0)
44
+ regexp_parser (>= 1.8, < 3.0)
45
+ rexml (>= 3.2.5, < 4.0)
46
+ rubocop-ast (>= 1.28.1, < 2.0)
47
+ ruby-progressbar (~> 1.7)
48
+ unicode-display_width (>= 2.4.0, < 3.0)
49
+ rubocop-ast (1.29.0)
50
+ parser (>= 3.2.1.0)
51
+ rubocop-performance (1.19.1)
52
+ rubocop (>= 1.7.0, < 2.0)
53
+ rubocop-ast (>= 0.4.0)
54
+ ruby-progressbar (1.13.0)
55
+ socksify (1.7.1)
56
+ standard (1.31.1)
57
+ language_server-protocol (~> 3.17.0.2)
58
+ lint_roller (~> 1.0)
59
+ rubocop (~> 1.56.2)
60
+ standard-custom (~> 1.0.0)
61
+ standard-performance (~> 1.2)
62
+ standard-custom (1.0.2)
63
+ lint_roller (~> 1.0)
64
+ rubocop (~> 1.50)
65
+ standard-performance (1.2.0)
66
+ lint_roller (~> 1.1)
67
+ rubocop-performance (~> 1.19.0)
68
+ unicode-display_width (2.5.0)
69
+
70
+ PLATFORMS
71
+ x64-mingw-ucrt
72
+
73
+ DEPENDENCIES
74
+ proxied_request!
75
+ rake (~> 13.0)
76
+ rspec
77
+ socksify (~> 1.7)
78
+ standard (~> 1.3)
79
+
80
+ BUNDLED WITH
81
+ 2.4.12
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 AdomasDauda
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Proxied request
2
+
3
+ Make requests through tor.
4
+
5
+ ## Installation
6
+
7
+ Locate your torrc (**Tor Browser\Browser\TorBrowser\Data\Tor**) file and add the following line:
8
+
9
+ ```
10
+ SocksPort 127.0.0.1:9050
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ 1. Start tor
16
+
17
+ ```ruby
18
+ require 'proxied_request'
19
+
20
+ # Make a request through tor
21
+ response = ProxiedRequest::HTTP.request('https://api.ipify.org')
22
+ puts response.body # =>
23
+
24
+ # Make a request through tor with a custom user agent
25
+ config = ProxiedRequest::Config.new
26
+ config.set_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0')
27
+ config.type = MethodType::POST
28
+ response = ProxiedRequest::HTTP.request('https://api.ipify.org', config)
29
+ puts response.body # =>
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "standard/rake"
5
+
6
+ task default: :standard
7
+
8
+ require 'rake/testtask'
9
+
10
+ Rake::TestTask.new(:test) do |test|
11
+ test.ruby_opts << '-r./test/simplecov_start.rb' if RUBY_VERSION >= '1.9'
12
+ test.pattern = 'test/**/test_*.rb'
13
+ test.verbose = true
14
+ end
15
+
16
+ task :default => :test
@@ -0,0 +1,58 @@
1
+ require_relative 'types.rb'
2
+
3
+ module ProxiedRequest
4
+ class Error < StandardError; end
5
+
6
+ class Config
7
+
8
+ def initialize
9
+ @proxy = "127.0.0.1"
10
+ @port = 9050
11
+ @type = MethodType::GET
12
+
13
+ @headers = {}
14
+
15
+ @timeout = 10
16
+ end
17
+
18
+ def type=(type)
19
+ @type = type
20
+ end
21
+
22
+ def proxy=(proxy)
23
+ @proxy = proxy
24
+ end
25
+
26
+ def port=(port)
27
+ @port = port
28
+ end
29
+
30
+ def set_header(key, value)
31
+ @headers[key] = value
32
+ end
33
+
34
+ def timeout=(timeout)
35
+ @timeout = timeout
36
+ end
37
+
38
+ def get_proxy
39
+ @proxy
40
+ end
41
+
42
+ def get_port
43
+ @port
44
+ end
45
+
46
+ def get_headers
47
+ @headers
48
+ end
49
+
50
+ def get_timeout
51
+ @timeout
52
+ end
53
+
54
+ def get_type
55
+ @type
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,60 @@
1
+ require 'socksify/http'
2
+ require 'net/http'
3
+ require_relative 'config.rb'
4
+ require_relative 'types.rb'
5
+
6
+ module ProxiedRequest
7
+ class Error < StandardError; end
8
+
9
+ class HTTP
10
+ def self.proxy(server, port)
11
+ TCPSocket.socks_server = server
12
+ TCPSocket.socks_port = port
13
+ end
14
+
15
+ def self.request(url, config=Config.new)
16
+ proxy(config.get_proxy, config.get_port)
17
+
18
+ uri = URI.parse(url)
19
+
20
+ if uri.host == nil
21
+ raise ProxiedRequest::Error, "Invalid URL"
22
+ end
23
+
24
+ http = Net::HTTP.new(uri.host, uri.port)
25
+ http.use_ssl = true
26
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
27
+
28
+ case config.get_type
29
+ when MethodType::GET
30
+ request = Net::HTTP::Get.new(uri)
31
+ when MethodType::POST
32
+ request = Net::HTTP::Post.new(uri)
33
+ when MethodType::PUT
34
+ request = Net::HTTP::Put.new(uri)
35
+ when MethodType::DELETE
36
+ request = Net::HTTP::Delete.new(uri)
37
+ when MethodType::HEAD
38
+ request = Net::HTTP::Head.new(uri)
39
+ when MethodType::OPTIONS
40
+ request = Net::HTTP::Options.new(uri)
41
+ when MethodType::TRACE
42
+ request = Net::HTTP::Trace.new(uri)
43
+ when MethodType::PATCH
44
+ request = Net::HTTP::Patch.new(uri)
45
+ else
46
+ raise ProxiedRequest::Error, "Invalid request type"
47
+ end
48
+
49
+ config.get_headers.each do |key, value|
50
+ request.delete(key)
51
+ request.add_field(key, value)
52
+ end
53
+
54
+ http.open_timeout = config.get_timeout
55
+
56
+ response = http.request(request)
57
+ return response
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,10 @@
1
+ class MethodType
2
+ GET = "GET"
3
+ POST = "POST"
4
+ PUT = "PUT"
5
+ DELETE = "DELETE"
6
+ HEAD = "HEAD"
7
+ OPTIONS = "OPTIONS"
8
+ TRACE = "TRACE"
9
+ PATCH = "PATCH"
10
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ProxiedRequest
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "proxied_request/version"
4
+
5
+ require 'proxied_request/config'
6
+ require 'proxied_request/request'
7
+ require 'proxied_request/types'
8
+
9
+
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/proxied_request/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "proxied_request"
7
+ spec.version = ProxiedRequest::VERSION
8
+ spec.authors = ["plusleft"]
9
+ spec.email = ["107749872+0xleft@users.noreply.github.com"]
10
+
11
+ spec.summary = "Make HTTP requests through a proxy."
12
+ spec.homepage = "https://github.com/0xleft/proxiedrequest"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 2.6.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/0xleft/proxiedrequest"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(__dir__) do
22
+ `git ls-files -z`.split("\x0").reject do |f|
23
+ (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
24
+ end
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ # Uncomment to register a new dependency of your gem
31
+ # spec.add_dependency "example-gem", "~> 1.0"
32
+
33
+ # For more information and examples about making a new gem, check out our
34
+ # guide at: https://bundler.io/guides/creating_gem.html
35
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: proxied_request
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - plusleft
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-10-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - 107749872+0xleft@users.noreply.github.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rspec"
21
+ - ".standard.yml"
22
+ - Gemfile
23
+ - Gemfile.lock
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - lib/proxied_request.rb
28
+ - lib/proxied_request/config.rb
29
+ - lib/proxied_request/request.rb
30
+ - lib/proxied_request/types.rb
31
+ - lib/proxied_request/version.rb
32
+ - proxied_request.gemspec
33
+ homepage: https://github.com/0xleft/proxiedrequest
34
+ licenses:
35
+ - MIT
36
+ metadata:
37
+ homepage_uri: https://github.com/0xleft/proxiedrequest
38
+ source_code_uri: https://github.com/0xleft/proxiedrequest
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.6.0
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 3.4.10
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Make HTTP requests through a proxy.
58
+ test_files: []