forward-proxy 0.5.0 → 0.6.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/.github/workflows/ci.yaml +1 -1
- data/.github/workflows/cli.yaml +1 -1
- data/CHANGELOG.md +10 -0
- data/exe/forward-proxy +6 -1
- data/lib/forward_proxy/errors/connection_timeout_error.rb +5 -0
- data/lib/forward_proxy/server.rb +24 -13
- data/lib/forward_proxy/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ef1fa7e497462fc27f6b33ace589450994664c35c0e2744fae3a46c6caa0372
|
4
|
+
data.tar.gz: a396b7121e8a512a518a033aaa14261d7b86fd0377cf6e29d183a34ba02ff010
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af543772c2f4159b0697f3ad02d4a330f776b73f1ccbaab6e8eb0dff9a8b5a6855b515fea99165c884132e743fd65aff7ac5973916256bcd6f476102d9dad743
|
7
|
+
data.tar.gz: e625cc351e9ce99744ff6ad00dac9c4e2e22c75cc0f8e4899c17736dcd06067398e1228bbebc6fb5ba07b44322f9806e62259c712f7d9bfddc89db5620045ded
|
data/.github/workflows/ci.yaml
CHANGED
data/.github/workflows/cli.yaml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 0.6.0
|
4
|
+
|
5
|
+
- add connection timeout to stop tracking connection from saturating client threads.
|
6
|
+
- add cli flats for connection timeout `-t` and `--timeout`.
|
7
|
+
- change cli short flag `-t` to `-c` for `--threads`.
|
8
|
+
|
9
|
+
## 0.5.0
|
10
|
+
|
11
|
+
- increase default threads from `32` to `128`.
|
12
|
+
|
3
13
|
## 0.2.0
|
4
14
|
|
5
15
|
- Extract errors into module.
|
data/exe/forward-proxy
CHANGED
@@ -15,7 +15,12 @@ OptionParser.new do |parser|
|
|
15
15
|
options[:bind_address] = bind_address
|
16
16
|
end
|
17
17
|
|
18
|
-
parser.on("-
|
18
|
+
parser.on("-tTIMEOUT", "--timeout=TIMEOUT", Integer,
|
19
|
+
"Specify the connection timout in seconds. Default: 300") do |threads|
|
20
|
+
options[:timeout] = threads
|
21
|
+
end
|
22
|
+
|
23
|
+
parser.on("-cTHREADS", "--threads=THREADS", Integer,
|
19
24
|
"Specify the number of client threads. Default: 128") do |threads|
|
20
25
|
options[:threads] = threads
|
21
26
|
end
|
data/lib/forward_proxy/server.rb
CHANGED
@@ -1,20 +1,23 @@
|
|
1
1
|
require 'logger'
|
2
2
|
require 'socket'
|
3
|
-
require '
|
3
|
+
require 'timeout'
|
4
4
|
require 'net/http'
|
5
|
+
require 'webrick'
|
6
|
+
require 'forward_proxy/errors/connection_timeout_error'
|
5
7
|
require 'forward_proxy/errors/http_method_not_implemented'
|
6
8
|
require 'forward_proxy/errors/http_parse_error'
|
7
9
|
require 'forward_proxy/thread_pool'
|
8
10
|
|
9
11
|
module ForwardProxy
|
10
12
|
class Server
|
11
|
-
attr_reader :bind_address, :bind_port, :logger
|
13
|
+
attr_reader :bind_address, :bind_port, :logger, :timeout
|
12
14
|
|
13
|
-
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: 4, timeout: 1, logger: default_logger)
|
14
16
|
@bind_address = bind_address
|
15
17
|
@bind_port = bind_port
|
16
18
|
@logger = logger
|
17
19
|
@thread_pool = ThreadPool.new(threads)
|
20
|
+
@timeout = timeout
|
18
21
|
end
|
19
22
|
|
20
23
|
def start
|
@@ -27,18 +30,20 @@ module ForwardProxy
|
|
27
30
|
loop do
|
28
31
|
thread_pool.schedule(socket.accept) do |client_conn|
|
29
32
|
begin
|
30
|
-
|
33
|
+
Timeout::timeout(timeout, Errors::ConnectionTimeoutError, "connection exceeded #{timeout} seconds") do
|
34
|
+
req = parse_req(client_conn)
|
31
35
|
|
32
|
-
|
36
|
+
logger.info(req.request_line.strip)
|
33
37
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
38
|
+
case req.request_method
|
39
|
+
when METHOD_CONNECT then handle_tunnel(client_conn, req)
|
40
|
+
when METHOD_GET, METHOD_POST then handle(client_conn, req)
|
41
|
+
else
|
42
|
+
raise Errors::HTTPMethodNotImplemented
|
43
|
+
end
|
39
44
|
end
|
40
45
|
rescue => e
|
41
|
-
handle_error(
|
46
|
+
handle_error(client_conn, e)
|
42
47
|
ensure
|
43
48
|
client_conn.close
|
44
49
|
end
|
@@ -165,9 +170,15 @@ module ForwardProxy
|
|
165
170
|
end
|
166
171
|
end
|
167
172
|
|
168
|
-
def handle_error(
|
173
|
+
def handle_error(client_conn, err)
|
174
|
+
status_code = case err
|
175
|
+
when Errors::ConnectionTimeoutError then 504
|
176
|
+
else
|
177
|
+
502
|
178
|
+
end
|
179
|
+
|
169
180
|
client_conn.puts <<~eos.chomp
|
170
|
-
HTTP/1.1
|
181
|
+
HTTP/1.1 #{status_code}
|
171
182
|
Via: #{HEADER_VIA}
|
172
183
|
#{HEADER_EOP}
|
173
184
|
eos
|
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.6.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-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Forward proxy using just Ruby standard libraries.
|
14
14
|
email:
|
@@ -32,6 +32,7 @@ files:
|
|
32
32
|
- exe/forward-proxy
|
33
33
|
- forward-proxy.gemspec
|
34
34
|
- lib/forward_proxy.rb
|
35
|
+
- lib/forward_proxy/errors/connection_timeout_error.rb
|
35
36
|
- lib/forward_proxy/errors/http_method_not_implemented.rb
|
36
37
|
- lib/forward_proxy/errors/http_parse_error.rb
|
37
38
|
- lib/forward_proxy/server.rb
|