Class: Mongrel::RedirectHandler

### Home Classes Methods

### In Files

- lib/mongrel/handlers.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::RedirectHandler

This handler allows you to redirect one url to another. You can use it like String#gsub, where the string is the REQUEST_URI. REQUEST_URI is the full path with GET parameters.

Eg. /test/something?help=true&disclaimer=false

## Examples

    h = Mongrel::HttpServer.new('0.0.0.0')
    h.register '/test', Mongrel::RedirectHandler.new('/to/there') # simple
    h.register '/to',   Mongrel::RedirectHandler.new(/t/, 'w') # regexp
    # and with a block
    h.register '/hey',  Mongrel::RedirectHandler.new(/(\w+)/) { |match| ... }

### Public Class Methods

new(pattern, replacement = nil, &block) click to toggle source

You set the rewrite rules when building the object.

pattern => What to look for or replacement if used alone

replacement, block => One of them is used to replace the found text

    # File lib/mongrel/handlers.rb, line 446
    def initialize(pattern, replacement = nil, &block)
      unless replacement or block
        @pattern, @replacement = nil, pattern
      else
        @pattern, @replacement, @block = pattern, replacement, block
      end
    end

### Public Instance Methods

process(request, response) click to toggle source

Process the request and return a redirect response

    # File lib/mongrel/handlers.rb, line 455
    def process(request, response)
      unless @pattern
        response.socket.write(Mongrel::Const::REDIRECT % @replacement)
      else
        if @block
          new_path = request.params['REQUEST_URI'].gsub(@pattern, &@block)
        else
          new_path = request.params['REQUEST_URI'].gsub(@pattern, @replacement)
        end
        response.socket.write(Mongrel::Const::REDIRECT % new_path)
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.