forward-proxy 0.1.3 → 0.1.4

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
  SHA1:
3
- metadata.gz: 3f624058897845408afede390c49b3048ee7a74f
4
- data.tar.gz: d2a90df621baefdecc61bba48a44bfdee2180766
3
+ metadata.gz: f0e621e13501a70783e49eb16c52fd937974bc7e
4
+ data.tar.gz: 70488fc1e2147c6c181e1dbb102929fe81eb1ecb
5
5
  SHA512:
6
- metadata.gz: 76d5bffc4db996cdc9578baa97cef6e13eb519cc065a0856cf83724470b27beaf6819b66aaddaf10bc21b1053b269635623ed5b4e9e0f13dff561bc044c7313d
7
- data.tar.gz: e085eba75e664a72575920750045ef62334cc0e3c64c72daddc5db5bf571656fb395790c6cb5d0a32bd3b3320fdeb2e0ce50705d59e3a2da0844628ae9b37148
6
+ metadata.gz: b5bd0ed7c697ea9ea8e3fb973e31f44947b2c9c5d1b7c23cc025580f82c3cdf16aaf238a9e0b831397c69bf803b5d04f02212553de968dfece8c52c5d1688104
7
+ data.tar.gz: 9a0b6db5127d71f0351577232d744ff0497c04c35a6a6e70580894d109dd160910b7ec4144134c295bafd35add0c3a9d6e57c6c47f63ca7ec92f16c67fa10c67
@@ -1,5 +1,12 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.1.4
4
+
5
+ - `accept` connections via thread pool.
6
+ - catch and throw custom http parse error.
7
+ - `Server:` header added for default error 502 response.
8
+ - rescue and logs socket error `Errno::EBADF`.
9
+
3
10
  ## 0.1.3
4
11
 
5
12
  - Refine CLI help text.
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ![Gem Version][3] ![Gem][1] ![Build Status][2]
4
4
 
5
- Ruby Forward Proxy implemented with only standard libraries.
5
+ 100LOC Ruby forward proxy using just standard libraries.
6
6
 
7
7
  ```
8
8
  $ forward-proxy --binding 0.0.0.0 --port 3182 --threads 2
@@ -5,6 +5,7 @@ require 'net/http'
5
5
 
6
6
  module ForwardProxy
7
7
  class HTTPMethodNotImplemented < StandardError; end
8
+ class HTTPParseError < StandardError; end
8
9
 
9
10
  class Server
10
11
  attr_reader :bind_address, :bind_port
@@ -16,16 +17,21 @@ module ForwardProxy
16
17
  end
17
18
 
18
19
  def start
19
- @server = TCPServer.new(bind_address, bind_port)
20
-
21
20
  thread_pool.start
22
21
 
22
+ @server = TCPServer.new(bind_address, bind_port)
23
+
23
24
  log("Listening #{bind_address}:#{bind_port}")
24
25
 
25
26
  loop do
26
- client = server.accept
27
-
28
- thread_pool.schedule(client) do |client_conn|
27
+ # The following comments are from "man 2 accept"
28
+ #
29
+ # The argument socket is a socket that has been created with socket(2), bound to an address with bind(2), and is listening for connections after a listen(2). accept() extracts the
30
+ # first connection request on the queue of pending connections, creates a new socket with the same properties of socket, and allocates a new file descriptor for the socket. If no
31
+ # pending connections are present on the queue, and the socket is not marked as non-blocking, accept() blocks the caller until a connection is present. If the socket is marked
32
+ # non-blocking and no pending connections are present on the queue, accept() returns an error as described below. The accepted socket may not be used to accept more connections.
33
+ # The original socket socket, remains open.
34
+ thread_pool.schedule(server.accept) do |client_conn|
29
35
  begin
30
36
  req = parse_req(client_conn)
31
37
 
@@ -40,6 +46,7 @@ module ForwardProxy
40
46
  rescue => e
41
47
  client_conn.puts <<~eos.chomp
42
48
  HTTP/1.1 502
49
+ Server: ForwardProxy
43
50
  eos
44
51
 
45
52
  puts e.message
@@ -50,6 +57,9 @@ module ForwardProxy
50
57
  end
51
58
  end
52
59
  rescue Interrupt
60
+ log("Exiting...")
61
+ rescue Errno::EBADF => e
62
+ log(e.message, "ERROR")
53
63
  end
54
64
 
55
65
  def shutdown
@@ -145,6 +155,8 @@ module ForwardProxy
145
155
  WEBrick::HTTPRequest.new(WEBrick::Config::HTTP).tap do |req|
146
156
  req.parse(client_conn)
147
157
  end
158
+ rescue => e
159
+ throw HTTPParseError.new(e.message)
148
160
  end
149
161
 
150
162
  def log(str, level = 'INFO')
@@ -1,3 +1,3 @@
1
1
  module ForwardProxy
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
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.1.3
4
+ version: 0.1.4
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-01-14 00:00:00.000000000 Z
11
+ date: 2021-01-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Forward proxy using just Ruby standard libraries.
14
14
  email: