In accordance with the sequence starting from the beginning CGI

Ruby CGI Doc:

The Common Gateway Interface ( CGI ) Is a simple protocol for passing an HTTP request from a web server to a standalone program, and returning the output to the web browser. Basically, a CGI program is called with the parameters of the request passed in either in the environment (GET) or via $ stdin (POST), and everything it prints to $ stdout is returned to the client.

This class focuses on process! Methods:

  1. def process! (provider = FCGI)
  2. mark_features!
  3. dispatcher_log: info, 'starting'
  4. process_each_request provider
  5. dispatcher_log: info, 'stopping gracefully'
  6. rescue Exception => error
  7. case error
  8. when SystemExit
  9. dispatcher_log: info, 'stopping after explicit exit'
  10. when SignalException
  11. dispatcher_error error, 'stopping after unhandled signal'
  12. else
  13. # Retry if exceptions occur more than 10 seconds apart.
  14. if Time.now - @ last_error_on> 10
  15. @ last_error_on = Time.now
  16. dispatcher_error error, 'retrying after unhandled exception'
  17. retry
  18. else
  19. dispatcher_error error, 'stopping after unhandled exception within 10 seconds of the last'
  20. end
  21. end
  22. end


(1) mark_features!

def mark_features!

@ features = $ ". clone

end



/ / Through the $ "to be all Rails loaded. Rb file name composed of list

(2) process_each_request

  1. def process_each_request (provider)
  2. cgi = nil
  3. catch: exit do
  4. provider.each_cgi do | cgi |
  5. process_request (cgi)
  6. case when_ready
  7. when: reload
  8. reload!
  9. when: restart
  10. close_connection (cgi)
  11. restart!
  12. when: exit
  13. close_connection (cgi)
  14. throw: exit
  15. end
  16. end
  17. end
  18. rescue SignalException => signal
  19. raise unless signal.message == 'SIGUSR1'
  20. close_connection (cgi)
  21. end


(3) process_request

  1. def process_request (cgi)
  2. @ processing, @ when_ready = true, nil
  3. gc_countdown
  4. with_signal_handler 'USR1' do
  5. begin
  6. Dispatcher.dispatch (cgi)
  7. rescue SignalException, SystemExit
  8. raise
  9. rescue Exception => error
  10. dispatcher_error error, 'unhandled dispatch error'
  11. end
  12. end
  13. ensure
  14. @ processing = false
  15. end


Next on the inside of the Dispatcher