Sha256: 6f9c1ecb3294955ef5de7709fb71fc409026c159c90a208dc22e13634fcb3f55

Contents?: true

Size: 648 Bytes

Versions: 7

Compression:

Stored size: 648 Bytes

Contents

require 'multi_json'

module Goliath
  module Rack
    module Formatters
      # A JSON formatter. Uses MultiJson so you can use the JSON
      # encoder that is right for your project.
      #
      # @example
      #   use Goliath::Rack::Formatters::JSON
      class JSON
        include AsyncMiddleware

        def post_process(env, status, headers, body)
          if json_response?(headers)
            body = [MultiJson.dump(body)]
          end
          [status, headers, body]
        end

        def json_response?(headers)
          headers['Content-Type'] =~ %r{^application/(json|javascript)}
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
goliath-1.0.5 lib/goliath/rack/formatters/json.rb
goliath-1.0.4 lib/goliath/rack/formatters/json.rb
goliath-1.0.3 lib/goliath/rack/formatters/json.rb
goliath-1.0.2 lib/goliath/rack/formatters/json.rb
goliath-1.0.1 lib/goliath/rack/formatters/json.rb
goliath-1.0.0 lib/goliath/rack/formatters/json.rb
goliath-1.0.0.beta.1 lib/goliath/rack/formatters/json.rb