rubroxy 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +2 -2
- data/lib/rubroxy/handlers/url_capture.rb +46 -0
- data/lib/rubroxy/proxy_core.rb +34 -32
- data/lib/rubroxy/version.rb +1 -1
- data/lib/rubroxy.rb +3 -1
- data.tar.gz.sig +3 -0
- metadata +87 -4
- metadata.gz.sig +2 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab93edcac22cc9df6aaa24ecb577dbd0f73dd52d
|
4
|
+
data.tar.gz: ddddc791cc4293d8195ea58cdb7437c228cee660
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6835b39c4e16e6a673d0802054e055ab257c8457020a19e1b16920005dbcae443983617ac70a4fa03c6527c3c2553c773f327e13601a611e29d561b6de31e45
|
7
|
+
data.tar.gz: 70963a7eaf0dc52fa305a426ef7c0799151361083c0115e7cf3a3185e21b7629e3e8019d76e51206ba21cc1786b2766f00bda85eebc2034c04163b4c2f763614
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data/README.md
CHANGED
@@ -13,14 +13,14 @@ This can also be used as part of tests without any external scripts or dependenc
|
|
13
13
|
```
|
14
14
|
require 'rubroxy'
|
15
15
|
|
16
|
-
proxy = Proxy.new('localhost', 8080, 0)
|
16
|
+
proxy = Rubroxy::Proxy.new('localhost', 8080, 0)
|
17
17
|
proxy.start_server
|
18
18
|
```
|
19
19
|
|
20
20
|
To filter responses and edit if needed, do something like the following:
|
21
21
|
|
22
22
|
```
|
23
|
-
proxy = Proxy.new('localhost', 8080, 0)
|
23
|
+
proxy = Rubroxy::Proxy.new('localhost', 8080, 0)
|
24
24
|
|
25
25
|
# Creates a proc object with the logic provided in the code block
|
26
26
|
handler = proc do |req, res|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Rubroxy
|
2
|
+
module Handler
|
3
|
+
# Captures URLs, stores the results in a hash as the handler
|
4
|
+
# Proc object is called.
|
5
|
+
class URLCapture
|
6
|
+
attr_accessor :collection
|
7
|
+
|
8
|
+
# Creates a new URLCapture object. Sets up the hash to store URLs
|
9
|
+
#
|
10
|
+
# @return [Hash]
|
11
|
+
def initialize
|
12
|
+
setup_collection
|
13
|
+
end
|
14
|
+
|
15
|
+
# Writes to the URL collection. It attempts to find the key matching the
|
16
|
+
# URL captured and increments the value if found. If not, it will create
|
17
|
+
# a new key value pair.
|
18
|
+
#
|
19
|
+
# @param url [String] the url captured by the handler Proc
|
20
|
+
# @return [Hash]
|
21
|
+
def write(url)
|
22
|
+
if @collection[:uris].key?(url)
|
23
|
+
@collection[:uris][url] += 1
|
24
|
+
else
|
25
|
+
@collection[:uris].merge!(url => 1)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Clears the objects URL hash.
|
30
|
+
#
|
31
|
+
# @return [Hash]
|
32
|
+
def clear
|
33
|
+
setup_collection
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
# Called by public methods to setup the correct hash structure.
|
39
|
+
#
|
40
|
+
# @return [Hash]
|
41
|
+
def setup_collection
|
42
|
+
@collection = { uris: {} }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/rubroxy/proxy_core.rb
CHANGED
@@ -1,40 +1,42 @@
|
|
1
|
+
module Rubroxy
|
1
2
|
# Main class of the proxy object, includes control methods
|
2
|
-
class Proxy
|
3
|
-
|
3
|
+
class Proxy
|
4
|
+
attr_accessor :server
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
6
|
+
# Creates the proxy object, defines logging levels and host:port
|
7
|
+
#
|
8
|
+
# @param host [String] Hostname of the proxy (eg: localhost, 127.0.0.1 etc)
|
9
|
+
# @param port [Integer] The expected port number (eg: 8080)
|
10
|
+
# @param logger_level [Integer] Sets the detail of the logger included.
|
11
|
+
# @return [Proxy]
|
12
|
+
def initialize(host, port, logger_level = 1)
|
13
|
+
logger = Logger.new($stderr)
|
14
|
+
logger.level = logger_level
|
15
|
+
access_log = [] if logger.level == 3
|
16
|
+
@server = WEBrick::HTTPProxyServer.new(Port: port,
|
17
|
+
Logger: logger,
|
18
|
+
AccessLog: access_log,
|
19
|
+
BindAddress: host)
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
# Adds a Proc object to the Proxy server
|
23
|
+
#
|
24
|
+
# @param handler [Proc] The proc object to be passed into the server config
|
25
|
+
def add_rules(handler)
|
26
|
+
@server.config[:ProxyContentHandler] = handler
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
# Starts the server process, including traps for process termination
|
30
|
+
def start_server
|
31
|
+
Signal.trap('INT') { stop_server }
|
32
|
+
Signal.trap('TERM') { stop_server }
|
32
33
|
|
33
|
-
|
34
|
-
|
34
|
+
@server.start
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
# Shuts down the proxy server
|
38
|
+
def stop_server
|
39
|
+
@server.shutdown
|
40
|
+
end
|
39
41
|
end
|
40
42
|
end
|
data/lib/rubroxy/version.rb
CHANGED
data/lib/rubroxy.rb
CHANGED
data.tar.gz.sig
ADDED
metadata
CHANGED
@@ -1,14 +1,36 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubroxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
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
|
+
MA0GCSqGSIb3DQEBBQUAA4IBAQAT/5x5FISP0g3Lolph1Dxe91cAMdWpPnuS9cGj
|
27
|
+
pV5lvSLemJg91DDEq0xiW9j2RmS7hAqgr4OEHrvfaJ23L+d8h3e5c5N1TU/uBDzD
|
28
|
+
3A5ksLJKJ3BgqahibgHTc60wVSHeiojcv0EEMI4RuXcfvupkekymquzhPTIAf/b/
|
29
|
+
qamACLst9BoPyfQ8GDyXJargT91lkpztE4E8kmND/465JyOBg7Px6Mc3K2ufNTKm
|
30
|
+
CniA6SAR8CxOQNwqzuOOYt9V1Yj3ihCdfWFkEMcsc7dmbOhsey2gifTPMgRusJVe
|
31
|
+
RV//y3nv21WEIgu0Q4GCMxWCCBIpq3otjDMoofmjM8R7TCfK
|
32
|
+
-----END CERTIFICATE-----
|
33
|
+
date: 2016-06-30 00:00:00.000000000 Z
|
12
34
|
dependencies:
|
13
35
|
- !ruby/object:Gem::Dependency
|
14
36
|
name: webrick
|
@@ -50,6 +72,26 @@ dependencies:
|
|
50
72
|
- - ">="
|
51
73
|
- !ruby/object:Gem::Version
|
52
74
|
version: 1.2.8
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: require_all
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '1.3'
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 1.3.3
|
85
|
+
type: :runtime
|
86
|
+
prerelease: false
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - "~>"
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '1.3'
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 1.3.3
|
53
95
|
- !ruby/object:Gem::Dependency
|
54
96
|
name: rspec
|
55
97
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,6 +112,46 @@ dependencies:
|
|
70
112
|
- - ">="
|
71
113
|
- !ruby/object:Gem::Version
|
72
114
|
version: 3.4.0
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: pry
|
117
|
+
requirement: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - "~>"
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0.10'
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.10.3
|
125
|
+
type: :development
|
126
|
+
prerelease: false
|
127
|
+
version_requirements: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.10'
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: 0.10.3
|
135
|
+
- !ruby/object:Gem::Dependency
|
136
|
+
name: httparty
|
137
|
+
requirement: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - "~>"
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0.13'
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: 0.13.7
|
145
|
+
type: :development
|
146
|
+
prerelease: false
|
147
|
+
version_requirements: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - "~>"
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0.13'
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: 0.13.7
|
73
155
|
description: A simple ruby built proxy
|
74
156
|
email: james.prescott@itv.com
|
75
157
|
executables: []
|
@@ -79,11 +161,12 @@ files:
|
|
79
161
|
- LICENSE.md
|
80
162
|
- README.md
|
81
163
|
- lib/rubroxy.rb
|
164
|
+
- lib/rubroxy/handlers/url_capture.rb
|
82
165
|
- lib/rubroxy/proxy_core.rb
|
83
166
|
- lib/rubroxy/version.rb
|
84
167
|
homepage: https://github.com/ITV/rubroxy
|
85
168
|
licenses:
|
86
|
-
-
|
169
|
+
- ITVPL
|
87
170
|
metadata: {}
|
88
171
|
post_install_message:
|
89
172
|
rdoc_options: []
|
metadata.gz.sig
ADDED