Sha256: da7bd36d19495b30c99933ab3d496b4f28e0c2561e7965316348e66daeef671e

Contents?: true

Size: 1.29 KB

Versions: 23

Compression:

Stored size: 1.29 KB

Contents

require 'rack'
module AgileProxy
  # A mixin that all handlers must include
  module Handler
    ##
    #
    # Handles an incoming rack request and returns a rack response.
    #
    # This method accepts rack request parameters and must return
    # a rack response array containing [status, headers, content]
    # , or [404, {}, ''] if the request cannot be fulfilled.
    #
    # @param  _env [Hash] The rack environment
    # @return [Array]               An array of [status, headers, content]
    #                               Returns status of 404 if the request cannot be fulfilled.
    def call(_env)
      [500, {}, 'The handler has not overridden the handle_request method!']
    end

    private

    def username_password(env)
      Base64.decode64(env['HTTP_PROXY_AUTHORIZATION'].sub(/^Basic /, '')).split(':') if proxy_auth? env
    end

    def proxy_auth?(env)
      env.key?('HTTP_PROXY_AUTHORIZATION') && env['HTTP_PROXY_AUTHORIZATION'] =~ /^Basic /
    end

    def downcase_header_name(name)
      name.split(/_/).drop(1).map { |word| word.downcase.capitalize }.join('-')
    end

    def downcased_headers(env)
      headers = {}
      env.each do |name, value|
        next unless name =~ /^HTTP_/
        headers[downcase_header_name(name)] = value
      end
      headers
    end
  end
end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
agile-proxy-0.1.26 lib/agile_proxy/handlers/handler.rb
agile-proxy-jruby-0.1.26-jruby lib/agile_proxy/handlers/handler.rb
agile-proxy-jruby-0.1.25-jruby lib/agile_proxy/handlers/handler.rb
agile-proxy-0.1.25 lib/agile_proxy/handlers/handler.rb
agile-proxy-0.1.24 lib/agile_proxy/handlers/handler.rb
agile-proxy-0.1.23 lib/agile_proxy/handlers/handler.rb
agile-proxy-0.1.22 lib/agile_proxy/handlers/handler.rb
agile-proxy-0.1.21 lib/agile_proxy/handlers/handler.rb
agile-proxy-0.1.20 lib/agile_proxy/handlers/handler.rb
agile-proxy-0.1.19 lib/agile_proxy/handlers/handler.rb
agile-proxy-0.1.18 lib/agile_proxy/handlers/handler.rb
agile-proxy-0.1.13 lib/agile_proxy/handlers/handler.rb
agile-proxy-0.1.12 lib/agile_proxy/handlers/handler.rb
agile-proxy-0.1.11 lib/agile_proxy/handlers/handler.rb
agile-proxy-0.1.10 lib/agile_proxy/handlers/handler.rb
agile-proxy-0.1.9 lib/agile_proxy/handlers/handler.rb
agile-proxy-0.1.8 lib/agile_proxy/handlers/handler.rb
agile-proxy-0.1.7 lib/agile_proxy/handlers/handler.rb
agile-proxy-0.1.6 lib/agile_proxy/handlers/handler.rb
agile-proxy-0.1.5 lib/agile_proxy/handlers/handler.rb