forward-proxy 0.6.0 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ef1fa7e497462fc27f6b33ace589450994664c35c0e2744fae3a46c6caa0372
4
- data.tar.gz: a396b7121e8a512a518a033aaa14261d7b86fd0377cf6e29d183a34ba02ff010
3
+ metadata.gz: f4251c1e0cac2b15b884b54ee293a1822ee955347f3c488b558c0f82cf50ddfe
4
+ data.tar.gz: 51a472149c1c0f04ad12edc90b0084760417e03b8d17889b27ee11ceb66ebc0d
5
5
  SHA512:
6
- metadata.gz: af543772c2f4159b0697f3ad02d4a330f776b73f1ccbaab6e8eb0dff9a8b5a6855b515fea99165c884132e743fd65aff7ac5973916256bcd6f476102d9dad743
7
- data.tar.gz: e625cc351e9ce99744ff6ad00dac9c4e2e22c75cc0f8e4899c17736dcd06067398e1228bbebc6fb5ba07b44322f9806e62259c712f7d9bfddc89db5620045ded
6
+ metadata.gz: f930317afad701fd29d5db2a720ce8d1ed7d9039116baa81c667f873ba709d252fe2c2286920258d522597279f9997c8fd284100640f966e14599f3d7b2df563
7
+ data.tar.gz: c5ca8e7c0c5238c5a0d09d9fc17a8eb920b014598e42a5aace0780663e19d52a8c850eab28be1cf8fa2a2449521a425d0b3b33e5546e7d6db1a14ea9610721ac
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.8.0
4
+
5
+ - add http head support.
6
+ - improve timeout testing.
7
+
8
+ ## 0.7.0
9
+
10
+ - bugfix default threads from `4` to `128`.
11
+
3
12
  ## 0.6.0
4
13
 
5
14
  - add connection timeout to stop tracking connection from saturating client threads.
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, --threads=THREADS Specify the number of client threads. Default: 32
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 timout in seconds. Default: 300") do |threads|
19
+ "Specify the connection timeout in seconds. Default: 300") do |threads|
20
20
  options[:timeout] = threads
21
21
  end
22
22
 
@@ -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: 4, timeout: 1, logger: default_logger)
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
- @size = size
7
- @queue = Queue.new
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
@@ -1,3 +1,3 @@
1
1
  module ForwardProxy
2
- VERSION = "0.6.0"
2
+ VERSION = "0.8.0"
3
3
  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.6.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-17 00:00:00.000000000 Z
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: