forward-proxy 0.6.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +2 -1
- data/exe/forward-proxy +1 -1
- data/lib/forward_proxy/server.rb +9 -6
- data/lib/forward_proxy/thread_pool.rb +9 -4
- data/lib/forward_proxy/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4251c1e0cac2b15b884b54ee293a1822ee955347f3c488b558c0f82cf50ddfe
|
4
|
+
data.tar.gz: 51a472149c1c0f04ad12edc90b0084760417e03b8d17889b27ee11ceb66ebc0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f930317afad701fd29d5db2a720ce8d1ed7d9039116baa81c667f873ba709d252fe2c2286920258d522597279f9997c8fd284100640f966e14599f3d7b2df563
|
7
|
+
data.tar.gz: c5ca8e7c0c5238c5a0d09d9fc17a8eb920b014598e42a5aace0780663e19d52a8c850eab28be1cf8fa2a2449521a425d0b3b33e5546e7d6db1a14ea9610721ac
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -38,7 +38,8 @@ forward-proxy
|
|
38
38
|
Usage: forward-proxy [options]
|
39
39
|
-p, --port=PORT Bind to specified port. Default: 9292
|
40
40
|
-b, --binding=BINDING Bind to the specified ip. Default: 127.0.0.1
|
41
|
-
-t, --
|
41
|
+
-t, --timeout=TIMEOUT Specify the connection timeout in seconds. Default: 300
|
42
|
+
-c, --threads=THREADS Specify the number of client threads. Default: 128
|
42
43
|
-h, --help Prints this help.
|
43
44
|
```
|
44
45
|
|
data/exe/forward-proxy
CHANGED
@@ -16,7 +16,7 @@ OptionParser.new do |parser|
|
|
16
16
|
end
|
17
17
|
|
18
18
|
parser.on("-tTIMEOUT", "--timeout=TIMEOUT", Integer,
|
19
|
-
"Specify the connection
|
19
|
+
"Specify the connection timeout in seconds. Default: 300") do |threads|
|
20
20
|
options[:timeout] = threads
|
21
21
|
end
|
22
22
|
|
data/lib/forward_proxy/server.rb
CHANGED
@@ -12,7 +12,7 @@ module ForwardProxy
|
|
12
12
|
class Server
|
13
13
|
attr_reader :bind_address, :bind_port, :logger, :timeout
|
14
14
|
|
15
|
-
def initialize(bind_address: "127.0.0.1", bind_port: 9292, threads:
|
15
|
+
def initialize(bind_address: "127.0.0.1", bind_port: 9292, threads: 128, timeout: 300, logger: default_logger)
|
16
16
|
@bind_address = bind_address
|
17
17
|
@bind_port = bind_port
|
18
18
|
@logger = logger
|
@@ -37,7 +37,7 @@ module ForwardProxy
|
|
37
37
|
|
38
38
|
case req.request_method
|
39
39
|
when METHOD_CONNECT then handle_tunnel(client_conn, req)
|
40
|
-
when METHOD_GET, METHOD_POST then handle(client_conn, req)
|
40
|
+
when METHOD_GET, METHOD_HEAD, METHOD_POST then handle(client_conn, req)
|
41
41
|
else
|
42
42
|
raise Errors::HTTPMethodNotImplemented
|
43
43
|
end
|
@@ -67,14 +67,15 @@ module ForwardProxy
|
|
67
67
|
|
68
68
|
attr_reader :socket, :thread_pool
|
69
69
|
|
70
|
-
# The following comments are from the IETF document
|
71
|
-
# "Hypertext Transfer Protocol -- HTTP/1.1: Basic Rules"
|
72
|
-
# https://datatracker.ietf.org/doc/html/rfc2616#section-2.2
|
73
|
-
|
74
70
|
METHOD_CONNECT = "CONNECT"
|
75
71
|
METHOD_GET = "GET"
|
72
|
+
METHOD_HEAD = "HEAD"
|
76
73
|
METHOD_POST = "POST"
|
77
74
|
|
75
|
+
# The following comments are from the IETF document
|
76
|
+
# "Hypertext Transfer Protocol -- HTTP/1.1: Basic Rules"
|
77
|
+
# https://datatracker.ietf.org/doc/html/rfc2616#section-2.2
|
78
|
+
|
78
79
|
# HTTP/1.1 defines the sequence CR LF as the end-of-line marker for all
|
79
80
|
# protocol elements except the entity-body.
|
80
81
|
HEADER_EOP = "\r\n"
|
@@ -173,6 +174,7 @@ module ForwardProxy
|
|
173
174
|
def handle_error(client_conn, err)
|
174
175
|
status_code = case err
|
175
176
|
when Errors::ConnectionTimeoutError then 504
|
177
|
+
when Errors::HTTPMethodNotImplemented then 501
|
176
178
|
else
|
177
179
|
502
|
178
180
|
end
|
@@ -196,6 +198,7 @@ module ForwardProxy
|
|
196
198
|
|
197
199
|
klass = case req.request_method
|
198
200
|
when METHOD_GET then Net::HTTP::Get
|
201
|
+
when METHOD_HEAD then Net::HTTP::Head
|
199
202
|
when METHOD_POST then Net::HTTP::Post
|
200
203
|
else
|
201
204
|
raise Errors::HTTPMethodNotImplemented
|
@@ -1,24 +1,29 @@
|
|
1
1
|
module ForwardProxy
|
2
2
|
class ThreadPool
|
3
|
-
attr_reader :queue, :size
|
3
|
+
attr_reader :queue, :size, :threads
|
4
4
|
|
5
5
|
def initialize(size)
|
6
|
-
@
|
7
|
-
@
|
6
|
+
@queue = Queue.new
|
7
|
+
@size = size
|
8
|
+
@threads = []
|
8
9
|
end
|
9
10
|
|
10
11
|
def start
|
11
12
|
size.times do
|
12
|
-
Thread.new do
|
13
|
+
thread = Thread.new do
|
13
14
|
loop do
|
14
15
|
job, args = queue.pop
|
15
16
|
job.call(*args)
|
16
17
|
end
|
17
18
|
end
|
19
|
+
|
20
|
+
threads.push(thread)
|
18
21
|
end
|
19
22
|
end
|
20
23
|
|
21
24
|
def schedule(*args, &block)
|
25
|
+
raise Exception, "no threads" unless threads.any?(&:alive?)
|
26
|
+
|
22
27
|
queue.push([block, args])
|
23
28
|
end
|
24
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forward-proxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Moriarty
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Forward proxy using just Ruby standard libraries.
|
14
14
|
email:
|