Skip to content

Instantly share code, notes, and snippets.

Created November 9, 2017 22:22
Show Gist options
  • Save anonymous/4c927c789208149f05388140f76fb147 to your computer and use it in GitHub Desktop.
Save anonymous/4c927c789208149f05388140f76fb147 to your computer and use it in GitHub Desktop.
# 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