Sha256: e0512d6968c177b60c1d58842ada0550b2ac8c5668dda8b03badbfb13e962dab

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module SecureNative
  module Frameworks
    class Rails
      SECURENATIVE_COOKIE = '_sn'

      def self.get_client_token(request)
        begin
          request.cookies[SECURENATIVE_COOKIE]
        rescue StandardError
          nil
        end
      end

      def self.get_url(request)
        begin
          # Rails >= 3.x
          request.fullpath
        rescue StandardError
          begin
            # Rails < 3.x & Sinatra
            request.url if url.nil?
          rescue StandardError
            nil
          end
        end
      end

      def self.get_method(request)
        begin
          request.method
        rescue StandardError
          nil
        end
      end

      def self.get_headers(request)
        begin
          headers = {}
          request.headers.env.select { |k, _| k.in?(ActionDispatch::Http::Headers::CGI_VARIABLES) || k =~ /^HTTP_/ }.each { |header|
            headers[header[0].downcase.gsub("http_", "").gsub("_", "-")] = header[1]
          }
          return headers
        rescue StandardError
          nil
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
securenative-0.1.37 lib/securenative/frameworks/rails.rb
securenative-0.1.36 lib/securenative/frameworks/rails.rb
securenative-0.1.35 lib/securenative/frameworks/rails.rb