Changeset 793

Show
Ignore:
Timestamp:
10/30/07 14:22:26 (1 year ago)
Author:
jimfree..@gmail.com
Message:

Style and doc enhancements.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/merb/mongrel_handler.rb

    r745 r793  
    22  NO_CLOSE_STATUS_FORMAT = "HTTP/1.1 %d %s\r\n".freeze 
    33  def send_status_no_connection_close(content_length=@body.length) 
    4     if not @status_sent 
     4    unless @status_sent 
    55      @header['Content-Length'] = content_length unless @status == 304 
    66      write(NO_CLOSE_STATUS_FORMAT % [@status, Mongrel::HTTP_STATUS_CODES[@status]]) 
     
    1111 
    1212class MerbHandler < Mongrel::HttpHandler 
    13   @@file_only_methods = ["GET","HEAD"] 
    14   @@path_prefix = nil 
     13  @@file_only_methods    = ["GET","HEAD"] 
     14  @@path_prefix          = nil 
    1515  @@path_prefix_original = nil 
    1616   
     
    2020    def path_prefix=(prefix) 
    2121      @@path_prefix_original = prefix 
    22       @@path_prefix = (prefix.is_a?(String) ? Regexp.new("^" + prefix.escape_regexp) : prefix) 
     22      @@path_prefix          = (prefix.is_a?(String) ? /^#{prefix.escape_regexp}/ : prefix) 
    2323    end 
    2424  end 
     
    4040  # serve the request. 
    4141  # 4. After the controller has done its thing, we check for the X-SENDFILE 
    42   # header. if you set this header to the path to a file in your controller 
     42  # header. if you set this header to the path of a file in your controller 
    4343  # then mongrel will serve the file directly and your controller can go on 
    4444  # processing other requests. 
    45   def process(request, response) 
    46      
    47     start = Time.now 
     45  def process(request, response)     
     46    start      = Time.now 
    4847    benchmarks = {} 
    4948     
    50     if response.socket.closed? 
    51       return 
    52     end 
     49    return if response.socket.closed? 
    5350     
    54     MERB_LOGGER.info("\nRequest: REQUEST_URI: #{request.params[Mongrel::Const::REQUEST_URI]}  (#{Time.now.strftime("%Y-%m-%d %H:%M:%S")})") 
     51    MERB_LOGGER.info("\nRequest: REQUEST_URI: #{ 
     52      request.params[Mongrel::Const::REQUEST_URI]}  (#{Time.now.strftime("%Y-%m-%d %H:%M:%S")})") 
    5553     
    5654    # Truncate the request URI if there's a path prefix so that an app can be 
     
    7573    get_or_head = @@file_only_methods.include? request.params[Mongrel::Const::REQUEST_METHOD] 
    7674 
    77     if get_or_head and @files.can_serve(path_info) 
     75    if get_or_head && @files.can_serve(path_info) 
    7876      # File exists as-is so serve it up 
    7977      MERB_LOGGER.info("Serving static file: #{path_info}") 
    8078      @files.process(request,response) 
    81     elsif get_or_head and @files.can_serve(page_cached) 
     79    elsif get_or_head && @files.can_serve(page_cached) 
    8280      # Possible cached page, serve it up 
    8381      MERB_LOGGER.info("Serving static file: #{page_cached}") 
     
    8684    else 
    8785      # Let Merb:Dispatcher find the route and call the filter chain and action 
    88       controller, action = Merb::Dispatcher.handle(request, response)   
     86      controller, action      = Merb::Dispatcher.handle(request, response)   
    8987      benchmarks.merge!(controller._benchmarks) 
    9088      benchmarks[:controller] = controller.class.to_s 
    91       benchmarks[:action] = action 
     89      benchmarks[:action]     = action 
    9290 
    9391      MERB_LOGGER.info("Routing to controller: #{controller.class} action: #{action}\nRoute Recognition & Parsing HTTP Input took: #{benchmarks[:setup_time]} seconds") 
    9492       
    9593      sendfile, clength = nil 
    96       response.status = controller.status 
     94      response.status   = controller.status 
    9795      # Check for the X-SENDFILE header from your Merb::Controller and serve 
    9896      # the file directly instead of buffering. 
     
    111109      if sendfile 
    112110        benchmarks[:sendfile_time] = Time.now - start         
    113         MERB_LOGGER.info("X-SENDFILE: #{sendfile}\nComplete Request took: #{benchmarks[:sendfile_time]} seconds") 
    114         file_status = File.stat(sendfile) 
     111        MERB_LOGGER.info("X-SENDFILE: #{sendfile}\nComplete Request took: #{ 
     112          benchmarks[:sendfile_time]} seconds") 
     113        file_status     = File.stat(sendfile) 
    115114        response.status = 200 
    116115        # Set the last modified times as well and etag for all files 
     
    156155  ensure 
    157156    MERB_LOGGER.flush 
    158   end     
    159      
     157  end 
    160158end