Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module MsfService
- class Controller
- attr_accessor :request,:response,:cookies,:session,:backend_server
- attr_accessor :ready_to_render,:response,:response_proc
- def initialize(env,format,backend_server,response_proc)
- @response_proc = response_proc
- @ready_to_render = false
- @request = Rack::Request.new(env)
- @format = format
- @backend_server = backend_server
- @params = @request.params
- @cookies = @request.cookies
- @status, @env, @headers = 200, env, {'Content-Type' => 'text/html'}
- # @response = Rack::Response.new([],@status,@headers)
- end
- def call(action)
- send(action)
- # if @ready_to_render
- # [@status, @headers.merge('Content-Length' => @body.size.to_s), [@body]]
- # end
- end
- def render options = {}
- response_format = options.keys.detect { |x| [:text,:html,:json,:xml].include? x}
- @headers.merge!('Content-Type' => "text/#{response_format}")
- @body = options[response_format]
- @status = options[:status] || 200
- result = [@status,@headers.merge!('Content-Length' => @body.size.to_s),[@body]]
- @response_proc.call(result)
- end
- end
- end
Add Comment
Please, Sign In to add comment