pacproxy 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.travis.yml +5 -0
- data/README.md +18 -12
- data/Rakefile +15 -1
- data/lib/pacproxy/access_logger.rb +32 -0
- data/lib/pacproxy/general_logger.rb +16 -0
- data/lib/pacproxy/loggable.rb +39 -0
- data/lib/pacproxy/pac_file.rb +40 -0
- data/lib/pacproxy/pacproxy.rb +38 -13
- data/lib/pacproxy/version.rb +2 -1
- data/lib/pacproxy.rb +7 -3
- data/pacproxy.gemspec +4 -1
- data/spec/access_logger_spec.rb +33 -0
- data/spec/loggable_spec.rb +53 -0
- data/spec/pac_file_spec.rb +25 -0
- data/spec/pacproxy_spec.rb +72 -48
- data/spec/spec_helper.rb +14 -0
- metadata +46 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3640640110abb9f0a611723777390e1047433198
|
4
|
+
data.tar.gz: 98acc0fd1efc7786b7976d1dfea84207c5752fe8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dec5acf4e26b12e0e7c9a0c8e4ad9e6a4993469af55a6c20d099f8995aa0cb09520e8aa9eadc68f86fa0ab23434f4fa72a146f99c819887892e7b28b213bdeac
|
7
|
+
data.tar.gz: 0e4579441de1e8399910eba31c323385600270048e1a3de4c3eebe6b2d09eb01d708b8b906a53f452033959b874d73e235cfa038f9156114c3ec48a7acaca581
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,21 @@
|
|
1
1
|
# Pacproxy
|
2
2
|
|
3
|
-
Pacproxy provides http/https proxy routed
|
3
|
+
Pacproxy provides http/https proxy routed by proxy.pac.
|
4
4
|
|
5
|
-
|
5
|
+
[](https://travis-ci.org/otahi/pacproxy)
|
6
|
+
[](https://coveralls.io/r/otahi/pacproxy?branch=master)
|
7
|
+
[](https://codeclimate.com/github/otahi/pacproxy)
|
8
|
+
[](http://badge.fury.io/rb/pacproxy)
|
9
|
+
|
10
|
+
**:warning: Now Pacproxy is early stage, so it might have big change.**
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
$ bundle exec pacproxy -P proxy.pac -p 3128
|
15
|
+
|
16
|
+
or
|
17
|
+
|
18
|
+
$ bundle exec pacproxy -P http://sample.org/proxy.pac -p 3128
|
6
19
|
|
7
20
|
## Installation
|
8
21
|
|
@@ -17,22 +30,15 @@ And then execute:
|
|
17
30
|
|
18
31
|
## Requirements
|
19
32
|
|
20
|
-
After installing the `pacproxy` gem
|
21
|
-
|
33
|
+
Before or After installing the `pacproxy` gem,
|
34
|
+
you need to install a JavaScript runtime. Compatible runtimes include
|
35
|
+
(see [pac](https://github.com/samuelkadolph/ruby-pac/blob/master/README.md)):
|
22
36
|
|
23
37
|
* [therubyracer](https://rubygems.org/gems/therubyracer) Google V8 embedded within Ruby
|
24
38
|
* [therubyrhino](https://rubygems.org/gems/therubyrhino/) Mozilla Rhino embedded within JRuby
|
25
39
|
* [johnson](https://rubygems.org/gems/johnson/) Mozilla SpiderMonkey embedded within Ruby 1.8
|
26
40
|
* [mustang](https://rubygems.org/gems/mustang/) Mustang V8 embedded within Ruby
|
27
41
|
|
28
|
-
## Usage
|
29
|
-
|
30
|
-
$ bundle exec pacproxy -P proxy.pac -p 3128
|
31
|
-
|
32
|
-
or
|
33
|
-
|
34
|
-
$ bundle exec pacproxy -P http://sample.org/proxy.pac -p 3128
|
35
|
-
|
36
42
|
## Contributing
|
37
43
|
|
38
44
|
1. Fork it ( https://github.com/otahi/pacproxy/fork )
|
data/Rakefile
CHANGED
@@ -1,2 +1,16 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rubocop/rake_task'
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
require 'coveralls/rake/task'
|
2
5
|
|
6
|
+
task default: [:spec, 'coveralls:push', :rubocop]
|
7
|
+
|
8
|
+
Coveralls::RakeTask.new
|
9
|
+
|
10
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
11
|
+
t.pattern = 'spec/**/*_spec.rb'
|
12
|
+
end
|
13
|
+
|
14
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
15
|
+
task.patterns = %w(lib/**/*.rb spec/**/*.rb)
|
16
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'logger'
|
3
|
+
require 'webrick/accesslog'
|
4
|
+
|
5
|
+
module Pacproxy
|
6
|
+
# Provide log Function
|
7
|
+
class AccessLogger
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
attr_accessor :logger
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@logger = Logger.new('proxy_access.log', 7, 10 * 1024 * 1024)
|
14
|
+
@format = WEBrick::AccessLog::COMMON_LOG_FORMAT
|
15
|
+
end
|
16
|
+
|
17
|
+
def accesslog(req, res)
|
18
|
+
params = setup_params(req, res)
|
19
|
+
logger << WEBrick::AccessLog.format(@format, params)
|
20
|
+
logger << "\n"
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# This format specification is a subset of mod_log_config of Apache:
|
26
|
+
# See: https://github.com/ruby/ruby/blob/trunk/lib/webrick/accesslog.rb
|
27
|
+
|
28
|
+
def setup_params(req, res)
|
29
|
+
WEBrick::AccessLog.setup_params({ ServerName: '-' }, req, res)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
module Pacproxy
|
5
|
+
# Provide log Function
|
6
|
+
class GeneralLogger
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
attr_accessor :logger
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@logger = Logger.new('pacproxy.log', 7, 10 * 1024 * 1024)
|
13
|
+
@logger.progname = 'pacproxy'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'pacproxy/general_logger'
|
2
|
+
require 'pacproxy/access_logger'
|
3
|
+
|
4
|
+
module Pacproxy
|
5
|
+
# Provide log Function
|
6
|
+
module Loggable
|
7
|
+
def general_logger
|
8
|
+
GeneralLogger.instance.logger
|
9
|
+
end
|
10
|
+
|
11
|
+
def access_logger
|
12
|
+
AccessLogger.instance
|
13
|
+
end
|
14
|
+
|
15
|
+
def debug(message)
|
16
|
+
general_logger.debug(message)
|
17
|
+
end
|
18
|
+
|
19
|
+
def info(message)
|
20
|
+
general_logger.info(message)
|
21
|
+
end
|
22
|
+
|
23
|
+
def lwarn(message)
|
24
|
+
general_logger.warn(message)
|
25
|
+
end
|
26
|
+
|
27
|
+
def error(message)
|
28
|
+
general_logger.error(message)
|
29
|
+
end
|
30
|
+
|
31
|
+
def fatal(message)
|
32
|
+
general_logger.fatal(message)
|
33
|
+
end
|
34
|
+
|
35
|
+
def accesslog(req, res)
|
36
|
+
access_logger.accesslog(req, res)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'pacproxy'
|
2
|
+
require 'pac'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module Pacproxy
|
6
|
+
# Pacproxy::PacFile represent proxy.pac file
|
7
|
+
class PacFile
|
8
|
+
def initialize(file_location, update_interval = 1800)
|
9
|
+
@pac = nil
|
10
|
+
begin_update(file_location, update_interval)
|
11
|
+
end
|
12
|
+
|
13
|
+
def find(uri)
|
14
|
+
return 'DIRECT' unless @pac
|
15
|
+
@pac.find(uri)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def begin_update(file_location, update_interval)
|
21
|
+
is_updated = false
|
22
|
+
Thread.new do
|
23
|
+
loop do
|
24
|
+
update(file_location)
|
25
|
+
is_updated = true
|
26
|
+
sleep(update_interval)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
sleep 0.01 until is_updated
|
30
|
+
end
|
31
|
+
|
32
|
+
def update(file_location)
|
33
|
+
tmp = PAC.load(file_location)
|
34
|
+
@pac = tmp if @pac.nil? || @pac.source != tmp.source
|
35
|
+
rescue
|
36
|
+
# log
|
37
|
+
puts "#{file_location} update error"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/pacproxy/pacproxy.rb
CHANGED
@@ -1,35 +1,60 @@
|
|
1
|
+
require 'pacproxy'
|
1
2
|
require 'webrick/httpproxy'
|
2
|
-
require 'pac'
|
3
3
|
require 'uri'
|
4
4
|
|
5
5
|
module Pacproxy
|
6
|
+
# Pacproxy::Pacproxy represent http/https proxy server
|
6
7
|
class Pacproxy < WEBrick::HTTPProxyServer
|
7
|
-
|
8
|
+
include Loggable
|
9
|
+
|
10
|
+
def initialize(config = {}, default = WEBrick::Config::HTTP)
|
11
|
+
config[:Logger] = general_logger
|
8
12
|
super(config, default)
|
9
|
-
@pac = config[:Proxypac]
|
13
|
+
@pac = PacFile.new(config[:Proxypac])
|
10
14
|
end
|
11
15
|
|
12
16
|
def proxy_uri(req, res)
|
13
|
-
|
17
|
+
super(req, res)
|
14
18
|
return unless @pac
|
15
19
|
|
16
|
-
|
20
|
+
proxy_line = @pac.find(request_uri(req))
|
21
|
+
lookup_proxy_uri(proxy_line)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
17
25
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
26
|
+
def request_uri(request)
|
27
|
+
if 'CONNECT' == request.request_method
|
28
|
+
"https://#{request.unparsed_uri}/"
|
29
|
+
else
|
30
|
+
request.unparsed_uri
|
31
|
+
end
|
32
|
+
end
|
23
33
|
|
24
|
-
|
34
|
+
def lookup_proxy_uri(proxy_line)
|
25
35
|
case proxy_line
|
26
36
|
when /^DIRECT/
|
27
|
-
|
37
|
+
nil
|
28
38
|
when /PROXY/
|
29
39
|
primary_proxy = proxy_line.split(';')[0]
|
30
40
|
proxy = /PROXY (.*)/.match(primary_proxy)[1]
|
31
|
-
|
41
|
+
URI.parse("http://#{proxy}")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def perform_proxy_request(req, res)
|
46
|
+
super
|
47
|
+
accesslog(req, res)
|
48
|
+
end
|
49
|
+
|
50
|
+
# allow PUT method on proxy server
|
51
|
+
# method names for webrick is indicated by rubocop
|
52
|
+
# rubocop:disable all
|
53
|
+
def do_PUT(req, res)
|
54
|
+
perform_proxy_request(req, res) do |http, path, header|
|
55
|
+
http.put(path, req.body || '', header)
|
32
56
|
end
|
33
57
|
end
|
58
|
+
# rubocop:enable all
|
34
59
|
end
|
35
60
|
end
|
data/lib/pacproxy/version.rb
CHANGED
data/lib/pacproxy.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'pacproxy/version'
|
2
|
+
require 'pacproxy/loggable'
|
3
|
+
require 'pacproxy/pacproxy'
|
4
|
+
require 'pacproxy/pac_file'
|
5
|
+
require 'pacproxy/general_logger'
|
6
|
+
require 'pacproxy/access_logger'
|
3
7
|
|
8
|
+
# Pacproxy provides http/https proxy routed with proxy.pac.
|
4
9
|
module Pacproxy
|
5
|
-
# Your code goes here...
|
6
10
|
end
|
data/pacproxy.gemspec
CHANGED
@@ -24,5 +24,8 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency 'rspec', '~> 3.0.0'
|
25
25
|
spec.add_development_dependency 'rake', '~> 10.3.2'
|
26
26
|
spec.add_development_dependency 'httpclient', '~> 2.4.0'
|
27
|
-
spec.add_development_dependency '
|
27
|
+
spec.add_development_dependency 'therubyracer', '~> 0.12.1'
|
28
|
+
|
29
|
+
spec.add_development_dependency 'rubocop', '0.24.1'
|
30
|
+
spec.add_development_dependency 'coveralls', '~> 0.7'
|
28
31
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Pacproxy::AccessLogger do
|
4
|
+
describe 'accesslog' do
|
5
|
+
it 'write Apache common log format' do
|
6
|
+
log = Pacproxy::AccessLogger.instance
|
7
|
+
log.logger = ''
|
8
|
+
now = Time.now
|
9
|
+
now_string = now.strftime('[%d/%b/%Y:%H:%M:%S %Z]')
|
10
|
+
|
11
|
+
req = double('req')
|
12
|
+
allow(req).to receive(:attributes).and_return([])
|
13
|
+
allow(req).to receive(:peeraddr).and_return(%w(host-a host-b host-c))
|
14
|
+
allow(req).to receive(:port).and_return(80)
|
15
|
+
allow(req).to receive(:query_string).and_return('query_string_test')
|
16
|
+
allow(req).to receive(:request_line)
|
17
|
+
.and_return(req_line = 'GET http://remotehost/abc HTTP/1.1')
|
18
|
+
allow(req).to receive(:request_method).and_return('GET')
|
19
|
+
allow(req).to receive(:request_time).and_return(now)
|
20
|
+
allow(req).to receive(:unparsed_uri).and_return('http://remotehost/abc')
|
21
|
+
allow(req).to receive(:user).and_return('user-a')
|
22
|
+
|
23
|
+
res = double('req')
|
24
|
+
allow(res).to receive(:filename).and_return('')
|
25
|
+
allow(res).to receive(:sent_size).and_return(128)
|
26
|
+
allow(res).to receive(:status).and_return(200)
|
27
|
+
|
28
|
+
log.accesslog(req, res)
|
29
|
+
expect(log.logger)
|
30
|
+
.to eq("host-c - user-a #{now_string} \"#{req_line}\" 200 128\n")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Pacproxy::GeneralLogger do
|
4
|
+
|
5
|
+
# Loggable class example
|
6
|
+
class LoggableExample
|
7
|
+
include Pacproxy::Loggable
|
8
|
+
end
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
log = StringIO.new
|
12
|
+
@logger = Logger.new(log)
|
13
|
+
@logger.level = Logger::DEBUG
|
14
|
+
Pacproxy::GeneralLogger.instance.logger = @logger
|
15
|
+
@loggable = LoggableExample.new
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#debug' do
|
19
|
+
it 'write debug log' do
|
20
|
+
message = 'DEBUG LOG'
|
21
|
+
expect(@logger).to receive(:debug).with(message)
|
22
|
+
@loggable.debug(message)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
describe '#info' do
|
26
|
+
it 'write info log' do
|
27
|
+
message = 'INFO LOG'
|
28
|
+
expect(@logger).to receive(:info).with(message)
|
29
|
+
@loggable.info(message)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
describe '#lwarn' do
|
33
|
+
it 'write warn log' do
|
34
|
+
message = 'WARN LOG'
|
35
|
+
expect(@logger).to receive(:warn).with(message)
|
36
|
+
@loggable.lwarn(message)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
describe '#error' do
|
40
|
+
it 'write error log' do
|
41
|
+
message = 'ERROR LOG'
|
42
|
+
expect(@logger).to receive(:error).with(message)
|
43
|
+
@loggable.error(message)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
describe '#fatal' do
|
47
|
+
it 'write fatal log' do
|
48
|
+
message = 'FATAL LOG'
|
49
|
+
expect(@logger).to receive(:fatal).with(message)
|
50
|
+
@loggable.fatal(message)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Pacproxy::PacFile do
|
4
|
+
describe 'PacFile#find' do
|
5
|
+
it 'returns proxyurl in pac file' do
|
6
|
+
pac_file = Pacproxy::PacFile.new('spec/all_proxy.pac')
|
7
|
+
expect(pac_file.find('http://sample.org/')).to eq('PROXY localhost:13081')
|
8
|
+
end
|
9
|
+
it 'returns DIRECT when no pac file' do
|
10
|
+
pac_file = Pacproxy::PacFile.new('')
|
11
|
+
expect(pac_file.find('http://sample.org/')).to eq('DIRECT')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
describe 'PacFile#update' do
|
15
|
+
it 'has same pac file if no change' do
|
16
|
+
pac_file = Pacproxy::PacFile.new('spec/all_proxy.pac', 0.01)
|
17
|
+
expect(pac_file).to receive(:update).at_least(2).times
|
18
|
+
|
19
|
+
first_pac = pac_file.instance_variable_get(:@pac)
|
20
|
+
sleep 0.2
|
21
|
+
second_pac = pac_file.instance_variable_get(:@pac)
|
22
|
+
expect(second_pac).to eq(first_pac)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/spec/pacproxy_spec.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'httpclient'
|
3
|
+
require 'webrick/https'
|
3
4
|
|
4
5
|
def wait_server_status(servers, status)
|
5
|
-
return unless
|
6
|
+
return unless servers || status
|
6
7
|
servers = [servers] unless servers.respond_to?(:all?)
|
7
8
|
return unless servers.all? { |s| s.respond_to?(:status) }
|
8
|
-
sleep(0.
|
9
|
+
sleep(0.01) until servers.all? { |s| s.status == status }
|
9
10
|
end
|
10
11
|
|
11
12
|
describe Pacproxy do
|
@@ -15,72 +16,93 @@ describe Pacproxy do
|
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
18
|
-
describe 'Pacproxy#
|
19
|
+
describe 'Pacproxy#proxy_uri' do
|
19
20
|
before(:each) do
|
20
21
|
$stdout, $stderr = StringIO.new, StringIO.new
|
22
|
+
@http_server = WEBrick::HTTPServer.new(Port: 13_080)
|
23
|
+
@http_server.define_singleton_method(:service) do |_req, res|
|
24
|
+
res.status = 200
|
25
|
+
end
|
26
|
+
|
27
|
+
@https_server = WEBrick::HTTPServer.new(Port: 13_443,
|
28
|
+
SSLEnable: true,
|
29
|
+
SSLCertName: [%w(CN 127.0.0.1)])
|
30
|
+
@https_server.define_singleton_method(:service) do |_req, res|
|
31
|
+
res.status = 200
|
32
|
+
end
|
33
|
+
|
34
|
+
@proxy_server = WEBrick::HTTPProxyServer.new(Port: 13_081)
|
35
|
+
Thread.new { @http_server.start }
|
36
|
+
Thread.new { @https_server.start }
|
37
|
+
Thread.new { @proxy_server.start }
|
38
|
+
wait_server_status([@http_server, @https_server, @proxy_server], :Running)
|
21
39
|
end
|
22
40
|
|
23
41
|
after(:each) do
|
24
42
|
$stdout, $stderr = STDOUT, STDERR
|
43
|
+
@http_server.shutdown
|
44
|
+
@https_server.shutdown
|
45
|
+
@proxy_server.shutdown
|
46
|
+
@pacproxy_server.shutdown
|
47
|
+
wait_server_status([@http_server,
|
48
|
+
@https_server,
|
49
|
+
@proxy_server,
|
50
|
+
@pacproxy_server],
|
51
|
+
:Stop)
|
25
52
|
end
|
26
53
|
|
27
|
-
it '
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
54
|
+
it 'transfer request to server directly' do
|
55
|
+
@pacproxy_server =
|
56
|
+
Pacproxy::Pacproxy.new(Port: 13_128,
|
57
|
+
Proxypac: 'spec/all_direct.pac')
|
58
|
+
Thread.new { @pacproxy_server.start }
|
59
|
+
wait_server_status(@pacproxy_server, :Running)
|
32
60
|
|
33
|
-
|
34
|
-
|
35
|
-
expect(
|
36
|
-
s.shutdown
|
37
|
-
end
|
61
|
+
c = HTTPClient.new('http://127.0.0.1:13128')
|
62
|
+
res = c.get('http://127.0.0.1:13080/')
|
63
|
+
expect(res.status).to eq(200)
|
38
64
|
|
39
|
-
|
40
|
-
|
41
|
-
s = Pacproxy::Pacproxy.new(Port: 3128, Proxypac: pacfile)
|
42
|
-
expect(s.instance_variable_get(:@pac)).to eq(pacfile)
|
43
|
-
s.shutdown
|
65
|
+
res = c.get('http://127.0.0.1:13080/noproxy/')
|
66
|
+
expect(res.status).to eq(200)
|
44
67
|
end
|
45
|
-
end
|
46
68
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
$proxy_server = WEBrick::HTTPProxyServer.new(Port: 13081)
|
54
|
-
Thread.new { $http_server.start }
|
55
|
-
Thread.new { $proxy_server.start }
|
56
|
-
wait_server_status([$http_server,$proxy_server], :Running)
|
57
|
-
end
|
69
|
+
it 'transfer request to server directly via HTTPS' do
|
70
|
+
@pacproxy_server =
|
71
|
+
Pacproxy::Pacproxy.new(Port: 13_128,
|
72
|
+
Proxypac: 'spec/all_direct.pac')
|
73
|
+
Thread.new { @pacproxy_server.start }
|
74
|
+
wait_server_status(@pacproxy_server, :Running)
|
58
75
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
76
|
+
c = HTTPClient.new('http://127.0.0.1:13128')
|
77
|
+
c.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
78
|
+
res = c.get('https://127.0.0.1:13443/')
|
79
|
+
expect(res.status).to eq(200)
|
80
|
+
|
81
|
+
res = c.get('https://127.0.0.1:13443/noproxy/')
|
82
|
+
expect(res.status).to eq(200)
|
65
83
|
end
|
66
84
|
|
67
|
-
it 'transfer request to server directly' do
|
68
|
-
|
69
|
-
|
70
|
-
|
85
|
+
it 'transfer request to server directly with PUT method' do
|
86
|
+
@pacproxy_server =
|
87
|
+
Pacproxy::Pacproxy.new(Port: 13_128,
|
88
|
+
Proxypac: 'spec/all_direct.pac')
|
89
|
+
Thread.new { @pacproxy_server.start }
|
90
|
+
wait_server_status(@pacproxy_server, :Running)
|
71
91
|
|
72
92
|
c = HTTPClient.new('http://127.0.0.1:13128')
|
73
|
-
res = c.
|
93
|
+
res = c.put('http://127.0.0.1:13080/')
|
74
94
|
expect(res.status).to eq(200)
|
75
95
|
|
76
|
-
res = c.
|
96
|
+
res = c.put('http://127.0.0.1:13080/noproxy/')
|
77
97
|
expect(res.status).to eq(200)
|
78
98
|
end
|
79
99
|
|
80
100
|
it 'transfer request to server via parent proxy' do
|
81
|
-
|
82
|
-
|
83
|
-
|
101
|
+
@pacproxy_server =
|
102
|
+
Pacproxy::Pacproxy.new(Port: 13_128,
|
103
|
+
Proxypac: 'spec/all_proxy.pac')
|
104
|
+
Thread.new { @pacproxy_server.start }
|
105
|
+
wait_server_status(@pacproxy_server, :Running)
|
84
106
|
|
85
107
|
c = HTTPClient.new('http://127.0.0.1:13128')
|
86
108
|
res = c.get('http://127.0.0.1:13080/')
|
@@ -91,9 +113,11 @@ describe Pacproxy do
|
|
91
113
|
end
|
92
114
|
|
93
115
|
it 'transfer request to server via parent proxy partially' do
|
94
|
-
|
95
|
-
|
96
|
-
|
116
|
+
@pacproxy_server =
|
117
|
+
Pacproxy::Pacproxy.new(Port: 13_128,
|
118
|
+
Proxypac: 'spec/partial_proxy.pac')
|
119
|
+
Thread.new { @pacproxy_server.start }
|
120
|
+
wait_server_status(@pacproxy_server, :Running)
|
97
121
|
|
98
122
|
c = HTTPClient.new('http://127.0.0.1:13128')
|
99
123
|
res = c.get('http://127.0.0.1:13080/')
|
data/spec/spec_helper.rb
CHANGED
@@ -1,2 +1,16 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear!
|
3
|
+
|
4
|
+
require 'simplecov'
|
5
|
+
|
6
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
7
|
+
SimpleCov::Formatter::HTMLFormatter,
|
8
|
+
Coveralls::SimpleCov::Formatter
|
9
|
+
]
|
10
|
+
SimpleCov.start do
|
11
|
+
add_filter '.bundle/'
|
12
|
+
end
|
13
|
+
|
1
14
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
15
|
+
|
2
16
|
require 'pacproxy'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pacproxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OTA Hiroshi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pac
|
@@ -81,19 +81,47 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 2.4.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: therubyracer
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.12.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.12.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '='
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
103
|
+
version: 0.24.1
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
|
-
- - '
|
108
|
+
- - '='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.24.1
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: coveralls
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.7'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
95
123
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
124
|
+
version: '0.7'
|
97
125
|
description: A proxy server works with proxy.pac
|
98
126
|
email:
|
99
127
|
- ota_h@nifty.com
|
@@ -103,19 +131,27 @@ extensions: []
|
|
103
131
|
extra_rdoc_files: []
|
104
132
|
files:
|
105
133
|
- .gitignore
|
134
|
+
- .travis.yml
|
106
135
|
- Gemfile
|
107
136
|
- LICENSE
|
108
137
|
- README.md
|
109
138
|
- Rakefile
|
110
139
|
- bin/pacproxy
|
111
140
|
- lib/pacproxy.rb
|
141
|
+
- lib/pacproxy/access_logger.rb
|
142
|
+
- lib/pacproxy/general_logger.rb
|
143
|
+
- lib/pacproxy/loggable.rb
|
144
|
+
- lib/pacproxy/pac_file.rb
|
112
145
|
- lib/pacproxy/pacproxy.rb
|
113
146
|
- lib/pacproxy/version.rb
|
114
147
|
- pacproxy.gemspec
|
115
148
|
- pacproxy/.gitignore
|
116
149
|
- proxy.pac
|
150
|
+
- spec/access_logger_spec.rb
|
117
151
|
- spec/all_direct.pac
|
118
152
|
- spec/all_proxy.pac
|
153
|
+
- spec/loggable_spec.rb
|
154
|
+
- spec/pac_file_spec.rb
|
119
155
|
- spec/pacproxy_spec.rb
|
120
156
|
- spec/partial_proxy.pac
|
121
157
|
- spec/spec_helper.rb
|
@@ -144,8 +180,11 @@ signing_key:
|
|
144
180
|
specification_version: 4
|
145
181
|
summary: A proxy server works with proxy.pac
|
146
182
|
test_files:
|
183
|
+
- spec/access_logger_spec.rb
|
147
184
|
- spec/all_direct.pac
|
148
185
|
- spec/all_proxy.pac
|
186
|
+
- spec/loggable_spec.rb
|
187
|
+
- spec/pac_file_spec.rb
|
149
188
|
- spec/pacproxy_spec.rb
|
150
189
|
- spec/partial_proxy.pac
|
151
190
|
- spec/spec_helper.rb
|