Sha256: b33d8946a5aa443d7957df63c90640e4a6768a2cf8ac7d809e568a235892c755

Contents?: true

Size: 801 Bytes

Versions: 4

Compression:

Stored size: 801 Bytes

Contents

module LocalPac
  class FileServer < Sinatra::Base
    use Rack::Deflater

    configure do
      if settings.environment == :test
        require_relative 'spec_helper_file_server'
        SpecHelperFileServer.new
      end

      set :local_storage, LocalPac::LocalStorage.new
    end

    configure do
      mime_type :proxy_pac_file, 'application/x-ns-proxy-autoconfig'
    end

    not_found do
      "Sorry, but I cant' find proxy-pac-file \"#{env['sinatra.error'].message}\"."
    end

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

    get '/v1/pac/:name' do
      content_type :proxy_pac_file
      file = settings.local_storage.find(params[:name])

      if file.nil?
        fail Sinatra::NotFound, params[:name]
      else
        file.content 
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
local_pac-0.1.3 lib/local_pac/file_server.rb
local_pac-0.1.2 lib/local_pac/file_server.rb
local_pac-0.1.1 lib/local_pac/file_server.rb
local_pac-0.1.0 lib/local_pac/file_server.rb