forward-proxy 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d2b9dbd7abcfa81bcdbd29b6dd2045e6d2210e92b303f7cfcdc4ab35ab0b868
4
- data.tar.gz: 729d4b7d964c8a5a3bec860f6bceb669a12225900a01b4737de8fdf6ba02a049
3
+ metadata.gz: ccf19df114eeec55eaef8765999561904d8f5b6cd91b7ed2016053ec9e717408
4
+ data.tar.gz: ce712f520c0ed32b93ea211ff658d330bef7eeb26c2ddfcea1246d955ce78175
5
5
  SHA512:
6
- metadata.gz: 70c0b51f0313e4ffedd1146ae93035db45bc8fe3a7cee647ea11cb0397d6862e99047befbc39aee6a08b17fd1e3d16394eb59ad9ad092140ea9354da10feadf6
7
- data.tar.gz: b0f3587f3c08b255be222f8f59530e19b5fcc6e589f93eafb1eaa21fac832a0f01847dfcf309ed443e51fdafd96a516241143c1a75795b3d09f0ce7088eedac0
6
+ metadata.gz: b71608455b079161950b09521d8fd99496767463f3e2aa0f0d293f21e3955b03d7b0ba12f06f3b3df1ff6674d598ed2e7eec7492ffb8fd9047ebb19771625251
7
+ data.tar.gz: '092035474f162e29d2c7d0735b43cd38e41580aadca7ae50e97e02dee8e6f3825f50393497c0a8db8a5e0b3622d3e44e25e69e03ae02b56eba1cad55abdc1388'
data/README.md CHANGED
@@ -6,8 +6,8 @@ Minimal forward proxy using 150LOC and only standard libraries. Useful for devel
6
6
 
7
7
  ```
8
8
  $ forward-proxy --binding 0.0.0.0 --port 3182 --threads 2
9
- [2021-01-14 19:37:47 +1100] INFO Listening 0.0.0.0:3182
10
- [2021-01-14 19:38:24 +1100] INFO CONNECT raw.githubusercontent.com:443 HTTP/1.1
9
+ I, [2021-07-04T10:33:32.947653 #1790] INFO -- : Listening 0.0.0.0:3182
10
+ I, [2021-07-04T10:33:32.998298 #1790] INFO -- : CONNECT raw.githubusercontent.com:443 HTTP/1.1
11
11
  ```
12
12
 
13
13
  ## Installation
data/exe/forward-proxy CHANGED
@@ -15,7 +15,8 @@ OptionParser.new do |parser|
15
15
  options[:bind_address] = bind_address
16
16
  end
17
17
 
18
- parser.on("-tTHREADS", "--threads=THREADS", Integer, "Specify the number of client threads. Default: 32") do |threads|
18
+ parser.on("-tTHREADS", "--threads=THREADS", Integer,
19
+ "Specify the number of client threads. Default: 128") do |threads|
19
20
  options[:threads] = threads
20
21
  end
21
22
 
@@ -10,11 +10,11 @@ module ForwardProxy
10
10
  class Server
11
11
  attr_reader :bind_address, :bind_port, :logger
12
12
 
13
- def initialize(bind_address: "127.0.0.1", bind_port: 9292, threads: 32, logger: Logger.new(STDOUT, level: :info))
14
- @logger = logger
15
- @thread_pool = ThreadPool.new(threads)
13
+ def initialize(bind_address: "127.0.0.1", bind_port: 9292, threads: 128, logger: default_logger)
16
14
  @bind_address = bind_address
17
15
  @bind_port = bind_port
16
+ @logger = logger
17
+ @thread_pool = ThreadPool.new(threads)
18
18
  end
19
19
 
20
20
  def start
@@ -29,7 +29,7 @@ module ForwardProxy
29
29
  begin
30
30
  req = parse_req(client_conn)
31
31
 
32
- logger.info(req.request_line)
32
+ logger.info(req.request_line.strip)
33
33
 
34
34
  case req.request_method
35
35
  when METHOD_CONNECT then handle_tunnel(client_conn, req)
@@ -37,8 +37,8 @@ module ForwardProxy
37
37
  else
38
38
  raise Errors::HTTPMethodNotImplemented
39
39
  end
40
- rescue => err
41
- handle_error(err, client_conn)
40
+ rescue => e
41
+ handle_error(e, client_conn)
42
42
  ensure
43
43
  client_conn.close
44
44
  end
@@ -130,20 +130,20 @@ module ForwardProxy
130
130
  # "Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content"
131
131
  # https://tools.ietf.org/html/rfc7231#section-4.3.6
132
132
 
133
- # An intermediary MAY combine an ordered subsequence of Via header
134
- # field entries into a single such entry if the entries have identical
135
- # received-protocol values. For example,
133
+ # An intermediary MAY combine an ordered subsequence of Via header
134
+ # field entries into a single such entry if the entries have identical
135
+ # received-protocol values. For example,
136
136
  #
137
- # Via: 1.0 ricky, 1.1 ethel, 1.1 fred, 1.0 lucy
137
+ # Via: 1.0 ricky, 1.1 ethel, 1.1 fred, 1.0 lucy
138
138
  #
139
- # could be collapsed to
139
+ # could be collapsed to
140
140
  #
141
- # Via: 1.0 ricky, 1.1 mertz, 1.0 lucy
141
+ # Via: 1.0 ricky, 1.1 mertz, 1.0 lucy
142
142
  #
143
- # A sender SHOULD NOT combine multiple entries unless they are all
144
- # under the same organizational control and the hosts have already been
145
- # replaced by pseudonyms. A sender MUST NOT combine entries that have
146
- # different received-protocol values.
143
+ # A sender SHOULD NOT combine multiple entries unless they are all
144
+ # under the same organizational control and the hosts have already been
145
+ # replaced by pseudonyms. A sender MUST NOT combine entries that have
146
+ # different received-protocol values.
147
147
  headers = resp.to_hash.merge(Via: [HEADER_VIA, resp['Via']].compact.join(', '))
148
148
 
149
149
  client_conn.puts <<~eos.chomp
@@ -173,10 +173,13 @@ module ForwardProxy
173
173
  eos
174
174
 
175
175
  logger.error(err.message)
176
-
177
176
  logger.debug(err.backtrace.join("\n"))
178
177
  end
179
178
 
179
+ def default_logger
180
+ Logger.new(STDOUT, level: :info)
181
+ end
182
+
180
183
  def map_webrick_to_net_http_req(req)
181
184
  req_headers = Hash[req.header.map { |k, v| [k, v.first] }]
182
185
 
@@ -1,21 +1,18 @@
1
1
  module ForwardProxy
2
2
  class ThreadPool
3
- attr_reader :queue, :threads, :size
3
+ attr_reader :queue, :size
4
4
 
5
5
  def initialize(size)
6
- @size = size
7
- @queue = Queue.new
8
- @threads = []
6
+ @size = size
7
+ @queue = Queue.new
9
8
  end
10
9
 
11
10
  def start
12
11
  size.times do
13
- threads << Thread.new do
14
- catch(:exit) do
15
- loop do
16
- job, args = queue.pop
17
- job.call(*args)
18
- end
12
+ Thread.new do
13
+ loop do
14
+ job, args = queue.pop
15
+ job.call(*args)
19
16
  end
20
17
  end
21
18
  end
@@ -24,13 +21,5 @@ module ForwardProxy
24
21
  def schedule(*args, &block)
25
22
  queue.push([block, args])
26
23
  end
27
-
28
- def shutdown
29
- threads.each do
30
- schedule { throw :exit }
31
- end
32
-
33
- threads.each(&:join)
34
- end
35
24
  end
36
25
  end
@@ -1,3 +1,3 @@
1
1
  module ForwardProxy
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.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.4.0
4
+ version: 0.5.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-04 00:00:00.000000000 Z
11
+ date: 2021-07-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Forward proxy using just Ruby standard libraries.
14
14
  email: