Skip to content

Instantly share code, notes, and snippets.

Created November 9, 2017 22:22
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment