Sha256: f223b28483058876ca6a14f181c74eefbb15324f1e3a0f4bafd6389ad4615101
Contents?: true
Size: 1.1 KB
Versions: 25
Compression:
Stored size: 1.1 KB
Contents
require 'orange-core/middleware/base' module Orange::Middleware class Rerouter < Base def init(*args) orange.add_pulp Orange::Pulp::Packet_Reroute end def packet_call(packet) begin pass packet rescue Orange::Reroute packet.finish end end end end module Orange module Pulp::Packet_Reroute def reroute(url, type = :real, *args) packet['reroute.to'] = url packet['reroute.type'] = type packet['reroute.args'] = *args if args raise Reroute.new(self), 'Unhandled reroute' end end class Reroute < Exception def initialize(packet) @packet = packet @packet[:headers] = {"Content-Type" => 'text/html', "Location" => self.url} @packet[:status] = 302 end def url case packet['reroute.type'] when :real packet['reroute.to'] # Parsing for orange urls or something when :orange packet.route_to(packet['reroute.to'], *packet['reroute.args', []]) else packet['reroute.to'] end end def packet @packet end end end
Version data entries
25 entries across 25 versions & 2 rubygems