Sha256: 67c5f74a65115716f7216707c32ddb34044dc3b3001cd21ec817b1792e728070

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

class Tynn
  # Adds support to set default headers for responses.
  #
  #   require "tynn"
  #   require "tynn/test"
  #
  #   Tynn.set(:default_headers, {
  #     "Content-Type" => "application/json"
  #   })
  #
  #   Tynn.define { }
  #
  #   app = Tynn::Test.new
  #   app.get("/")
  #
  #   app.res.headers
  #   # => { "Content-Type" => "application/json" }
  #
  # This plugin is included by default.
  #
  module DefaultHeaders
    def self.setup(app) # :nodoc:
      app.set(:default_headers, {})
    end

    module ClassMethods
      # Returns a Hash with the default headers.
      #
      #   Tynn.set(:default_headers, {
      #     "Content-Type" => "application/json"
      #   })
      #
      #   Tynn.default_headers["Content-Type"]
      #   # => "application/json"
      #
      def default_headers
        settings[:default_headers]
      end
    end

    module InstanceMethods # :nodoc:
      # Overrides Syro's default implementation of default headers.
      def default_headers
        Hash[self.class.default_headers]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tynn-2.0.0.alpha lib/tynn/default_headers.rb