rubroxy 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.md +7 -0
- data/README.md +69 -0
- data/lib/rubroxy/proxy_core.rb +40 -0
- data/lib/rubroxy/version.rb +4 -0
- data/lib/rubroxy.rb +4 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dacda13e6588517e47fe078c64f2c686386b29b1
|
4
|
+
data.tar.gz: 1846c163cefa0eb6abb3d223c99f62302abea16d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 73436602f6f7416e4fba7052fc32f636444cba7f1605ad7a95592e52e140832fec7cdd36e7691319ab9b672695eaf28bdbf75cbd69ebd30be2396f890c1718c2
|
7
|
+
data.tar.gz: 46013cc3ed1d2a60fb8e7da52cac4fe64518851c5c7847c2510b3efe07ada231e850753d39e18caa638484fdffb44ddda365bd03f35df8d5c369a1737f249772
|
data/LICENSE.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright 2016 ITV PLC, licensed under the ITV Open Source Software Licence, Version 1.0 (the “Licence"). You may not use any of the files in this repository except in compliance with the Licence”.
|
2
|
+
|
3
|
+
You may not use this file except in compliance with the Licence. You may obtain a copy of the Licence at http://itv.com/itv-oss-licence-v1.0.
|
4
|
+
|
5
|
+
Unless required by applicable law or as otherwise agreed in writing, software distributed under the Licence is distributed on an “as is” basis, without warranties or conditions of any kind, either express or implied, including without limitation,
|
6
|
+
any warranties or conditions as to title, non-infringement, merchantability or fitness for a particular purpose.
|
7
|
+
Please see the Licence for the specific language governing permissions and limitations under the Licence.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Rubroxy
|
2
|
+
|
3
|
+
A simple ruby proxy wrapped around WEBrick that can be integrated into any ruby script or test. The goal was to make something that solved some of my problems at work without needing too much configuration or use of many files.
|
4
|
+
|
5
|
+
This can also be used as part of tests without any external scripts or dependencies beyond ruby.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
`gem install rubroxy`
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
```
|
14
|
+
require 'rubroxy'
|
15
|
+
|
16
|
+
proxy = Proxy.new('localhost', 8080, 0)
|
17
|
+
proxy.start_server
|
18
|
+
```
|
19
|
+
|
20
|
+
To filter responses and edit if needed, do something like the following:
|
21
|
+
|
22
|
+
```
|
23
|
+
proxy = Proxy.new('localhost', 8080, 0)
|
24
|
+
|
25
|
+
# Creates a proc object with the logic provided in the code block
|
26
|
+
handler = proc do |req, res|
|
27
|
+
res.body = 'This has been proxied!' if res['content-type'] = 'text/html'
|
28
|
+
end
|
29
|
+
|
30
|
+
proxy.add_rules(handler)
|
31
|
+
proxy.start_server
|
32
|
+
```
|
33
|
+
|
34
|
+
You can also filter by `host`, so if you want to alter a response from a test environment as an example:
|
35
|
+
|
36
|
+
```
|
37
|
+
handler = proc do |req, res|
|
38
|
+
res.body = 'This has been altered' if req.host == 'something.itv.com'
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
Combining this with data can give you a pretty powerful proxy ruleset! We can also alter other aspects of the request, including headers:
|
43
|
+
|
44
|
+
```
|
45
|
+
handler = proc do |req, res|
|
46
|
+
req['auth'] = 'auth_token' if req.host = 'www.google.com'
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
The above will add the designated header to any request going to that URL.
|
51
|
+
|
52
|
+
## Development
|
53
|
+
|
54
|
+
### Contribution
|
55
|
+
|
56
|
+
If you think you can contribute to the project, whether it's through development or testing or when there's a bug to be fixed - feel free to clone the repo and create an issue so that I'm aware. Once it's complete and tested, create a Pull Request so that it can be merged in.
|
57
|
+
|
58
|
+
### Tests
|
59
|
+
|
60
|
+
We're using Rspec to build the tests for Rubroxy. If you want to run the current test suite just type `rspec` when in the rubroxy repo directory after cloning. All new features must come with relevant tests.
|
61
|
+
|
62
|
+
### Todos
|
63
|
+
|
64
|
+
Currently, this does what I need it to do - but it would be great to expand it and generally make it better :)
|
65
|
+
|
66
|
+
- An easier way to build rulesets for the proxy before initialisation. Currently you'd have to parse JSON etc yourself but I'm looking at integrating it as part of the gem.
|
67
|
+
- Further logging, including potential reports or other ways to analyse proxy sessions
|
68
|
+
- The ability to query the proxy for URLS that have been hit through the connection.
|
69
|
+
- Ability to set new rules during runtime. Ideally done without the need for a restart of the server but I realise this might be impossible.
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Main class of the proxy object, includes control methods
|
2
|
+
class Proxy
|
3
|
+
attr_accessor :server
|
4
|
+
|
5
|
+
# Creates the proxy object, defines logging levels and host:port
|
6
|
+
#
|
7
|
+
# @param host [String] Hostname of the proxy (eg: localhost, 127.0.0.1 etc)
|
8
|
+
# @param port [Integer] The expected port number (eg: 8080)
|
9
|
+
# @param logger_level [Integer] Sets the detail of the logger included.
|
10
|
+
# @return [Proxy]
|
11
|
+
def initialize(host, port, logger_level = 1)
|
12
|
+
logger = Logger.new($stderr)
|
13
|
+
logger.level = logger_level
|
14
|
+
access_log = [] if logger.level == 3
|
15
|
+
@server = WEBrick::HTTPProxyServer.new(Port: port,
|
16
|
+
Logger: logger,
|
17
|
+
AccessLog: access_log,
|
18
|
+
BindAddress: host)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Adds a Proc object to the Proxy server
|
22
|
+
#
|
23
|
+
# @param handler [Proc] The proc object to be passed into the server config
|
24
|
+
def add_rules(handler)
|
25
|
+
@server.config[:ProxyContentHandler] = handler
|
26
|
+
end
|
27
|
+
|
28
|
+
# Starts the server process, including traps for process termination
|
29
|
+
def start_server
|
30
|
+
Signal.trap('INT') { stop_server }
|
31
|
+
Signal.trap('TERM') { stop_server }
|
32
|
+
|
33
|
+
@server.start
|
34
|
+
end
|
35
|
+
|
36
|
+
# Shuts down the proxy server
|
37
|
+
def stop_server
|
38
|
+
@server.shutdown
|
39
|
+
end
|
40
|
+
end
|
data/lib/rubroxy.rb
ADDED
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubroxy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Prescott
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: webrick
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.3.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.3.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: logger
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.2'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.2.8
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.2'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.2.8
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rspec
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '3.4'
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 3.4.0
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.4'
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 3.4.0
|
73
|
+
description: A simple ruby built proxy
|
74
|
+
email: james.prescott@itv.com
|
75
|
+
executables: []
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- LICENSE.md
|
80
|
+
- README.md
|
81
|
+
- lib/rubroxy.rb
|
82
|
+
- lib/rubroxy/proxy_core.rb
|
83
|
+
- lib/rubroxy/version.rb
|
84
|
+
homepage: https://github.com/ITV/rubroxy
|
85
|
+
licenses:
|
86
|
+
- GPL-3.0
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.4.8
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Rubroxy
|
108
|
+
test_files: []
|
109
|
+
has_rdoc:
|