Class: Mongrel::Camping::CampingHandler

### Home Classes Methods

### In Files

- lib/mongrel/camping.rb

### Parent

Mongrel::HttpHandler

### Methods

- ::new
- #process

### Files

- CHANGELOG
- COPYING
- LICENSE
- README
- Makefile

### Class/Module Index

Quicksearch

- Mongrel
- Mongrel::CGIWrapper
- Mongrel::Camping
- Mongrel::Camping::CampingHandler
- Mongrel::Command
- Mongrel::Command::Base
- Mongrel::Command::Registry
- Mongrel::Configurator
- Mongrel::Const
- Mongrel::DeflateFilter
- Mongrel::DirHandler
- Mongrel::Error404Handler
- Mongrel::Gems
- Mongrel::HeaderOut
- Mongrel::HttpHandler
- Mongrel::HttpHandlerPlugin
- Mongrel::HttpParams
- Mongrel::HttpParser
- Mongrel::HttpParserError
- Mongrel::HttpRequest
- Mongrel::HttpResponse
- Mongrel::HttpServer
- Mongrel::Rails
- Mongrel::Rails::RailsConfigurator
- Mongrel::Rails::RailsHandler
- Mongrel::RedirectHandler
- Mongrel::StatisticsFilter
- Mongrel::Stats
- Mongrel::StatusHandler
- Mongrel::StopServer
- Mongrel::TimeoutError
- Mongrel::URIClassifier
- Mongrel::URIClassifier::RegistrationError
- Mongrel::URIClassifier::UsageError
- RequestLog
- RequestLog::Access
- RequestLog::Files
- RequestLog::Objects
- RequestLog::Params
- RequestLog::Threads
- IO
- Kernel
- MongrelDbg
- TCPServer

No matching classes.

# Mongrel::Camping::CampingHandler

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.

### Attributes

files[R]
guard[R]

### Public Class Methods

new(klass) click to toggle source

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

### Public Instance Methods

process(request, response) click to toggle source

    # File lib/mongrel/camping.rb, line 46
    def process(request, response)
      if response.socket.closed?
        return
      end

      controller = nil
      @guard.synchronize {
        controller = @klass.run(request.body, request.params)
      }

      sendfile, clength = nil
      response.status = controller.status
      controller.headers.each do |k, v|
        if k =~ /^X-SENDFILE$/
          sendfile = v
        elsif k =~ /^CONTENT-LENGTH$/
          clength = v.to_i
        else
          [*v].each do |vi|
            response.header[k] = vi
          end
        end
      end

      if sendfile
        request.params[Mongrel::Const::PATH_INFO] = sendfile
        @files.process(request, response)
      elsif controller.body.respond_to? :read
        response.send_status(clength)
        response.send_header
        while chunk = controller.body.read(16384)
          response.write(chunk)
        end
        if controller.body.respond_to? :close
          controller.body.close
        end
      else
        body = controller.body.to_s
        response.send_status(body.length)
        response.send_header
        response.write(body)
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.