Class: Mongrel::Camping::CampingHandler

Class | Mongrel::Camping::CampingHandler
In: | lib/mongrel/camping.rb lib/mongrel/camping.rb
Parent: | Mongrel::HttpHandler

This is a specialized handler for Camping applications that has them process the request and then translates the results into something the Mongrel::HttpResponse needs.

### Methods

new new process process

### Attributes

files | [R] |
files | [R] |
guard | [R] |
guard | [R] |

### Public Class methods

new(klass)

[Source]

        # File lib/mongrel/camping.rb, line 40
    40:       def initialize(klass)
    41:         @files = Mongrel::DirHandler.new(nil, false)
    42:         @guard = Mutex.new
    43:         @klass = klass
    44:       end

new(klass)

[Source]

        # File lib/mongrel/camping.rb, line 40
    40:       def initialize(klass)
    41:         @files = Mongrel::DirHandler.new(nil, false)
    42:         @guard = Mutex.new
    43:         @klass = klass
    44:       end

### Public Instance methods

process(request, response)

[Source]

        # File lib/mongrel/camping.rb, line 46
    46:       def process(request, response)
    47:         if response.socket.closed?
    48:           return
    49:         end
    50:
    51:         controller = nil
    52:         @guard.synchronize {
    53:           controller = @klass.run(request.body, request.params)
    54:         }
    55:
    56:         sendfile, clength = nil
    57:         response.status = controller.status
    58:         controller.headers.each do |k, v|
    59:           if k =~ /^X-SENDFILE$/i
    60:             sendfile = v
    61:           elsif k =~ /^CONTENT-LENGTH$/i
    62:             clength = v.to_i
    63:           else
    64:             [*v].each do |vi|
    65:               response.header[k] = vi
    66:             end
    67:           end
    68:         end
    69:
    70:         if sendfile
    71:           request.params[Mongrel::Const::PATH_INFO] = sendfile
    72:           @files.process(request, response)
    73:         elsif controller.body.respond_to? :read
    74:           response.send_status(clength)
    75:           response.send_header
    76:           while chunk = controller.body.read(16384)
    77:             response.write(chunk)
    78:           end
    79:           if controller.body.respond_to? :close
    80:             controller.body.close
    81:           end
    82:         else
    83:           body = controller.body.to_s
    84:           response.send_status(body.length)
    85:           response.send_header
    86:           response.write(body)
    87:         end
    88:       end

process(request, response)

[Source]

        # File lib/mongrel/camping.rb, line 46
    46:       def process(request, response)
    47:         if response.socket.closed?
    48:           return
    49:         end
    50:
    51:         controller = nil
    52:         @guard.synchronize {
    53:           controller = @klass.run(request.body, request.params)
    54:         }
    55:
    56:         sendfile, clength = nil
    57:         response.status = controller.status
    58:         controller.headers.each do |k, v|
    59:           if k =~ /^X-SENDFILE$/i
    60:             sendfile = v
    61:           elsif k =~ /^CONTENT-LENGTH$/i
    62:             clength = v.to_i
    63:           else
    64:             [*v].each do |vi|
    65:               response.header[k] = vi
    66:             end
    67:           end
    68:         end
    69:
    70:         if sendfile
    71:           request.params[Mongrel::Const::PATH_INFO] = sendfile
    72:           @files.process(request, response)
    73:         elsif controller.body.respond_to? :read
    74:           response.send_status(clength)
    75:           response.send_header
    76:           while chunk = controller.body.read(16384)
    77:             response.write(chunk)
    78:           end
    79:           if controller.body.respond_to? :close
    80:             controller.body.close
    81:           end
    82:         else
    83:           body = controller.body.to_s
    84:           response.send_status(body.length)
    85:           response.send_header
    86:           response.write(body)
    87:         end
    88:       end

[Validate]