Created
November 9, 2017 22:22
Revisions
-
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ # lib/encode.rb class Encode def initialize(app) @app = app end def call(env) @request = Rack::Request.new(env) status, headers, response = @app.call(env) enc = env['intake']['path']['encodings'] encoded = encode(enc, response) # @response = Rack::Response.new # @response.set_header('Content-Type', "application/#{enc}") # @response.write encoded # @response.status = status # @response.write response # @response.write "\n" # @response.finish encoded << "\n" [status, headers, encoded] end attr_reader :request private def encode(encoding, text) case encoding when 'json' then text.to_json end end def decode(encoding, code) case encoding when 'json' then JSON.parse(code) end end end