Sha256: eea4f08991d90e088fa68b46e88916cb929f15637cf88426c9e89f7245253f3f

Contents?: true

Size: 872 Bytes

Versions: 7

Compression:

Stored size: 872 Bytes

Contents

module LocalPac
  module App
    class LookupController < ApplicationController

      get '/' do
        redirect to('/proxy.pac')
      end

      get '/:name' do
        file = local_storage.find(params[:name].to_s)
        fail Sinatra::NotFound, params[:name].to_s if file.nil?

        haml :lookup, layout: :application
      end

      post '/:name' do
        @file = local_storage.find(params[:name].to_s)
        @uri = Addressable::URI.heuristic_parse(params[:url].to_s)

        fail Sinatra::NotFound, params[:name].to_s if @file.nil?

        parser = LocalPac::ProxyPac::PacParser.new(file: @file)

        begin
          @result = parser.find(@uri)
        rescue Exceptions::PacFileInvalid
          fail I18n.t('errors.invalid_proxy_pac', name: params[:name] )
        end

        haml :lookup_result, layout: :application
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
local_pac-0.5.0 app/controllers/lookup_controller.rb
local_pac-0.4.0 app/controllers/lookup_controller.rb
local_pac-0.3.0 app/controllers/lookup_controller.rb
local_pac-0.2.3 app/controllers/lookup_controller.rb
local_pac-0.2.2 app/controllers/lookup_controller.rb
local_pac-0.2.1 app/controllers/lookup_controller.rb
local_pac-0.2.0 app/controllers/lookup_controller.rb