README.md

Proxy Pac Rb

proxy_pac_rb is a gem to compress, lint and parse proxy auto-config files. It comes with a cli program, some rack middlewares and can be used from within ruby scripts as well. proxy_pac_rb uses a JavaScript runtime to evaulate a proxy auto-config file the same way a browser does to determine what proxy (if any at all) should a program use to connect to a server. You must install on of the supported JavaScript runtimes: therubyracer or therubyrhino.

"rack"-middleware

The middleware which comes with proxy_pac_rb is compliant with the
rack-specification - tested via
rack/lint and
should work with every rack-compliant-server.

Prerequisites

Make sure the content is served with "Content-Type": 'application/x-ns-proxy-autoconfig'. Otherwise the content is ignored by both
middlewares.

Warning

The linter-rack-middleware needs to be activated before ANY other
middleman-extension, rack-middleware or whatever framework you are using
can instantiate the V8-runtime! Only the first time the
V8-javascript-engine - aka therubyracer - is instantiated, it is possible to
create a binding to ruby code. Every other V8-object created later re-uses
this binding.

You might an error like this if you ignore this warning!

error build/proxy.pac
Unexpected token: name (is) (line: 1, col: 10, pos: 10)
Error
at new JS_Parse_Error (<eval>:2359:10623)
at js_error (<eval>:2359:10842)
at croak (<eval>:2359:19086)
at token_error (<eval>:2359:19223)
at unexpected (<eval>:2359:19311)
at semicolon (<eval>:2359:19784)
at simple_statement (<eval>:2359:22580)
at <eval>:2359:20553
at <eval>:2359:19957
at <eval>:2359:31968
There were errors during this build

Linter Middleware

require'proxy_pac_rb/rack/proxy_pac_linter'
use ProxyPacRb::Rack::ProxyPacLinter

Compressor Middleware

require'proxy_pac_rb/rack/proxy_pac_compressor'
use ProxyPacRb::Rack::ProxyPacCompressor

Using "rack"-middleware with "middleman"

If you want to use the rack-middleware with middleman look at the following
code snippet captured from the middleman-configuration file config.rb:

config.rb:

# IMPORTANT: Needs to come first before compressorrequire'proxy_pac_rb/rack/proxy_pac_linter'
use ProxyPacRb::Rack::ProxyPacLinterrequire'proxy_pac_rb/rack/proxy_pac_compressor'
use ProxyPacRb::Rack::ProxyPacCompressor# The middleware works on content served with # "Content-Type" 'application/x-ns-proxy-autoconfig'
page "*.pac", content_type:'application/x-ns-proxy-autoconfig', layout:false# This provides an uncompressed copy of the proxy.pac to make it# possible for your support to review it by handDir.glob(File.join(source_dir, '**', '*.pac*')).each do |f|
# Path should be relative to source dir
relative_path =Pathname.new(f).relative_path_from(Pathname.new(source_dir))
relative_path = relative_path.to_s.gsub(/(?<path>.*\.pac)\..*/, '\k<path>')
# "text/plain" prevents the middlewares to handle it
proxy(format('%s.raw', relative_path), relative_path, content_type:'text/plain', layout:false)
end

Developers

After checking out the repo, run script/bootstrap to install dependencies.
Then, run script/console for an interactive prompt that will allow you to
experiment. To run tests execute script/test.

To install this gem onto your local machine, run bundle exec rake gem:install. To
release a new version, update the version number in version.rb, and then run
bundle exec rake gem:release to create a git tag for the version, push git
commits and tags, and push the .gem file to
rubygems.org.

Contributing

If you want to contribute: fork, branch & pull request and please see
CONTRIBUTING.md.