Sha256: 598718b26e3eadea8b24b134920473f405259884e22058c2a4b9628db4b70220
Contents?: true
Size: 1.1 KB
Versions: 13
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
13 entries across 13 versions & 1 rubygems