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