Sha256: 24a6a79b8881a773661c7ac6246a366340dbeda5b8ea52cd2edd0f73cea744f3

Contents?: true

Size: 817 Bytes

Versions: 16

Compression:

Stored size: 817 Bytes

Contents

require 'faraday'



module Saddle
  module Middleware
    module Request

      # Public: Adds a user-agent to the request

      class UserAgent < Faraday::Middleware
        def call(env)
          user_agent = nil
          # Build a user agent that looks like 'SaddleExample 0.0.1'
          begin
            user_agent = client_name = env[:request][:saddle][:client].name
            parent_module = client_name.split('::')[0..-2].join('::').constantize
            if parent_module
              if defined?(parent_module::VERSION)
                user_agent += " #{parent_module::VERSION}"
              end
            end
          rescue StandardError
          end
          env[:request_headers]['User-Agent'] = user_agent if user_agent

          @app.call env
        end
      end

    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
saddle-0.0.53 lib/saddle/middleware/request/user_agent.rb
saddle-0.0.51 lib/saddle/middleware/request/user_agent.rb
saddle-0.0.50 lib/saddle/middleware/request/user_agent.rb
saddle-0.0.49 lib/saddle/middleware/request/user_agent.rb
saddle-0.0.48 lib/saddle/middleware/request/user_agent.rb
saddle-0.0.46 lib/saddle/middleware/request/user_agent.rb
saddle-0.0.45 lib/saddle/middleware/request/user_agent.rb
saddle-0.0.44 lib/saddle/middleware/request/user_agent.rb
saddle-0.0.43 lib/saddle/middleware/request/user_agent.rb
saddle-0.0.42 lib/saddle/middleware/request/user_agent.rb
saddle-0.0.41 lib/saddle/middleware/request/user_agent.rb
saddle-0.0.38 lib/saddle/middleware/request/user_agent.rb
saddle-0.0.37 lib/saddle/middleware/request/user_agent.rb
saddle-0.0.36 lib/saddle/middleware/request/user_agent.rb
saddle-0.0.35 lib/saddle/middleware/request/user_agent.rb
saddle-0.0.34 lib/saddle/middleware/request/user_agent.rb