Sha256: 2fc39b6c938c9c8882f910214c85bb4c06125b57e1cb4bcf386adc4f333c27c6

Contents?: true

Size: 825 Bytes

Versions: 2

Compression:

Stored size: 825 Bytes

Contents

# frozen_string_literal: true

module Keycard::Request
  # This request wrapper should be used when the application will be served
  # behind a reverse proxy. It relies on the trusted relationship with the
  # proxy to use HTTP headers for forwarded values.
  #
  # The typical headers forwarded are X-Forwarded-User and X-Forwarded-For,
  # which, somewhat confusingly, are transposed into HTTP_X_REMOTE_USER and
  # HTTP_X_FORWARDED_FOR once the Rack request is assembled.
  class ProxiedAttributes < Attributes
    def base
      {
        user_pid:  user_pid,
        user_eid:  user_eid,
        client_ip: client_ip
      }
    end

    def user_pid
      get 'HTTP_X_REMOTE_USER'
    end

    def user_eid
      user_pid
    end

    def client_ip
      safe('HTTP_X_FORWARDED_FOR').split(',').first
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
keycard-0.3.0 lib/keycard/request/proxied_attributes.rb
keycard-0.2.4 lib/keycard/request/proxied_attributes.rb