Sha256: 318ef74e397990656e3f15325dcf2743a7f433d05360b1cf6543238366693908

Contents?: true

Size: 569 Bytes

Versions: 2

Compression:

Stored size: 569 Bytes

Contents

require 'base64'

module Commute
  module Common

    class BasicAuth
      @name = :auth

      def call router, request, options = {}
        # Create the Authorization header.
        authorization = Base64.strict_encode64 \
          "#{options[:username]}:#{options[:password]}}"
        # Set the header on the http request.
        request.http.headers['Authorization'] = "Basic #{authorization}"

        # Send the request, pipe the data, and forward the response.
        request.pipe router.call(request.http, &request.responder)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
commute-0.3.0.pre.2 lib/commute/common/basic_auth.rb
commute-0.3.0.pre lib/commute/common/basic_auth.rb