Sha256: 24d90dc4420698a6ccd992e5810e9609947c6f570b4b8f4c78283e095d2cab13
Contents?: true
Size: 1.79 KB
Versions: 1
Compression:
Stored size: 1.79 KB
Contents
require 'proxy_pac_rb' require 'rack' module ProxyPacRb module Rack # Rack Middleware to lint proxy pac # # @example Sinatra's <server>.rb # require 'proxy_pac_rb/rack/proxy_pac_linter' # use ProxyPacRb::Rack::ProxyPacLinter # # @example Rack's config.ru # require 'proxy_pac_rb/rack/proxy_pac_linter' # use ProxyPacRb::Rack::ProxyPacLinter # # @example Middleman's config.rb # require 'proxy_pac_rb/rack/proxy_pac_linter' # use ProxyPacRb::Rack::ProxyPacLinter class ProxyPacLinter private attr_reader :linter, :loader, :enabled public def initialize( app, enabled: true ) @app = app @linter = ProxyPacRb::ProxyPacLinter.new(silent: true) @loader = ProxyPacRb::ProxyPacLoader.new @enabled = enabled end def call(env) status, headers, body = @app.call(env) return [status, headers, body] if enabled == false # rubocop:disable Style/CaseEquality return [status, headers, body] unless headers.key?('Content-Type') \ && %r{application/x-ns-proxy-autoconfig} === headers['Content-Type'] # rubocop:enable Style/CaseEquality content = [body].flatten.each_with_object('') { |e, a| a << e.to_s } proxy_pac = ProxyPacFile.new(source: content) loader.load(proxy_pac) linter.lint(proxy_pac) if proxy_pac.valid? content = proxy_pac.content else status = 500 content = proxy_pac.message headers['Content-Length'] = content.bytesize.to_s if headers['Content-Length'] end [status, headers, [content]] ensure body.close if body.respond_to?(:close) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
proxy_pac_rb-0.4.0 | lib/proxy_pac_rb/rack/proxy_pac_linter.rb |