Guest User

Untitled

a guest
Apr 26th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. module MsfService
  2. class Controller
  3. attr_accessor :request,:response,:cookies,:session,:backend_server
  4. attr_accessor :ready_to_render,:response,:response_proc
  5. def initialize(env,format,backend_server,response_proc)
  6. @response_proc = response_proc
  7. @ready_to_render = false
  8. @request = Rack::Request.new(env)
  9. @format = format
  10. @backend_server = backend_server
  11. @params = @request.params
  12. @cookies = @request.cookies
  13. @status, @env, @headers = 200, env, {'Content-Type' => 'text/html'}
  14. # @response = Rack::Response.new([],@status,@headers)
  15. end
  16.  
  17. def call(action)
  18. send(action)
  19. # if @ready_to_render
  20. # [@status, @headers.merge('Content-Length' => @body.size.to_s), [@body]]
  21. # end
  22. end
  23.  
  24. def render options = {}
  25. response_format = options.keys.detect { |x| [:text,:html,:json,:xml].include? x}
  26. @headers.merge!('Content-Type' => "text/#{response_format}")
  27. @body = options[response_format]
  28. @status = options[:status] || 200
  29. result = [@status,@headers.merge!('Content-Length' => @body.size.to_s),[@body]]
  30. @response_proc.call(result)
  31. end
  32. end
  33. end
Add Comment
Please, Sign In to add comment