Methods

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
446:     def initialize(pattern, replacement = nil, &block)
447:       unless replacement or block
448:         @pattern, @replacement = nil, pattern
449:       else
450:         @pattern, @replacement, @block = pattern, replacement, block
451:       end
452:     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
455:     def process(request, response)
456:       unless @pattern
457:         response.socket.write(Mongrel::Const::REDIRECT % @replacement)
458:       else
459:         if @block
460:           new_path = request.params['REQUEST_URI'].gsub(@pattern, &@block)
461:         else
462:           new_path = request.params['REQUEST_URI'].gsub(@pattern, @replacement)
463:         end
464:         response.socket.write(Mongrel::Const::REDIRECT % new_path)
465:       end
466:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.