Skip to content

Commit

Permalink
Merge branch 'master' of github.com:datagraph/trinity
Browse files Browse the repository at this point in the history
  • Loading branch information
artob committed Jan 26, 2010
2 parents 857a364 + 0eb1e22 commit 4a4f328
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/trinity/core/handler.rb
Expand Up @@ -41,5 +41,10 @@ def redirect(url)
def not_found
[404, {'Content-Type' => 'text/plain'}, '404 Resource Not Found']
end

def internal_error(message = nil)
[500, {'Content-Type' => 'text/plain'}, message || "Unspecified internal server error"]
end

end
end
10 changes: 8 additions & 2 deletions lib/trinity/core/handler/redirector.rb
Expand Up @@ -8,9 +8,15 @@ class Trinity::Handler
# @see http://www.w3.org/TR/2000/CR-rdf-schema-20000327/#s2.3.4
class Redirector < Trinity::Handler
def call(env)
query([env['trinity.subject'], RDF::RDFS.seeAlso]).each do |statement|
return redirect(statement.object.to_s)
subjects = [env['trinity.subject']]
object = nil
while statement = query([env['trinity.subject'], RDF::RDFS.seeAlso]).first do
object = statement.object
return internal_error("Looping redirects") if subjects.include? object
subjects << object
env['trinity.subject'] = object
end
return redirect(object.to_s) if object
super
end
end
Expand Down

0 comments on commit 4a4f328

Please sign in to comment.