Sha256: 7b62552fe41720216b6d105c5ca05ced209ddf249b9ad8c3a21384783781abb4

Contents?: true

Size: 1.85 KB

Versions: 21

Compression:

Stored size: 1.85 KB

Contents

module Hanami
  # @api private
  module Config
    # Cookies configuration
    #
    # @since 0.3.0
    # @api private
    class Cookies

      # Return the routes for this application
      #
      # @return [Hash] options for cookies
      #
      # @since 0.3.0
      # @api private
      attr_reader :default_options

      # Cookies configuration
      #
      # httponly option enabled by default.
      # Prevent attackers to steal cookies via JavaScript,
      # Eg. alert(document.cookie) will fail
      #
      # @param options [Hash, TrueClass, FalseClass] optional cookies options
      # @param configuration [Hanami::Configuration] the application configuration
      #
      # @since 0.3.0
      # @api private
      #
      # @see https://github.com/rack/rack/blob/master/lib/rack/utils.rb #set_cookie_header!
      # @see https://www.owasp.org/index.php/HttpOnly
      #
      # @example Enable cookies with boolean
      #   module Web
      #     class Application < Hanami::Application
      #       configure do
      #         # ...
      #         cookies true
      #       end
      #     end
      #   end
      #
      # @example Enable cookies with options
      #   module Web
      #     class Application < Hanami::Application
      #       configure do
      #         # ...
      #         cookies max_age: 300
      #       end
      #     end
      #   end
      def initialize(configuration, options = {})
        @options         = options
        @default_options = { httponly: true, secure: configuration.ssl? }
        @default_options.merge!(options) if options.is_a?(::Hash)
      end

      # Return if cookies are enabled
      #
      # @return [TrueClass, FalseClass] enabled cookies
      #
      # @since 0.3.0
      # @api private
      def enabled?
        @options.respond_to?(:empty?) ? !@options.empty? : !!@options
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
hanami-1.3.5 lib/hanami/config/cookies.rb
hanami-1.3.4 lib/hanami/config/cookies.rb
hanami-1.3.3 lib/hanami/config/cookies.rb
hanami-1.3.2 lib/hanami/config/cookies.rb
hanami-1.3.1 lib/hanami/config/cookies.rb
hanami-1.3.0 lib/hanami/config/cookies.rb
hanami-1.3.0.beta1 lib/hanami/config/cookies.rb
hanami-1.2.0 lib/hanami/config/cookies.rb
hanami-1.2.0.rc2 lib/hanami/config/cookies.rb
hanami-1.2.0.rc1 lib/hanami/config/cookies.rb
hanami-1.2.0.beta2 lib/hanami/config/cookies.rb
hanami-1.2.0.beta1 lib/hanami/config/cookies.rb
hanami-1.1.1 lib/hanami/config/cookies.rb
hanami-1.1.0 lib/hanami/config/cookies.rb
hanami-1.1.0.rc1 lib/hanami/config/cookies.rb
hanami-1.1.0.beta3 lib/hanami/config/cookies.rb
hanami-1.1.0.beta2 lib/hanami/config/cookies.rb
hanami-1.1.0.beta1 lib/hanami/config/cookies.rb
hanami-1.0.0 lib/hanami/config/cookies.rb
hanami-1.0.0.rc1 lib/hanami/config/cookies.rb