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 +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +1 -1
- data/lib/forward_proxy/server.rb +17 -5
- data/lib/forward_proxy/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0e621e13501a70783e49eb16c52fd937974bc7e
|
4
|
+
data.tar.gz: 70488fc1e2147c6c181e1dbb102929fe81eb1ecb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5bd0ed7c697ea9ea8e3fb973e31f44947b2c9c5d1b7c23cc025580f82c3cdf16aaf238a9e0b831397c69bf803b5d04f02212553de968dfece8c52c5d1688104
|
7
|
+
data.tar.gz: 9a0b6db5127d71f0351577232d744ff0497c04c35a6a6e70580894d109dd160910b7ec4144134c295bafd35add0c3a9d6e57c6c47f63ca7ec92f16c67fa10c67
|
data/CHANGELOG.md
CHANGED
@@ -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
data/lib/forward_proxy/server.rb
CHANGED
@@ -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
|
-
|
27
|
-
|
28
|
-
|
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')
|
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.
|
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-
|
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:
|