Skip to content

Commit

Permalink
Added middleware example
Browse files Browse the repository at this point in the history
  • Loading branch information
bturnbull committed Feb 18, 2009
1 parent 3533f54 commit 9ce77aa
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
8 changes: 7 additions & 1 deletion config/environment.rb
Expand Up @@ -34,11 +34,17 @@
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]

# Add additional load paths for your own custom dirs
# config.load_paths += %W( #{RAILS_ROOT}/extras )
# config.load_paths += %W( #{RAILS_ROOT}/lib/middleware )

# Force all environments to use the same logger level
# (by default production uses :info, the others :debug)
# config.log_level = :debug

# Rack Middleware
require "#{RAILS_ROOT}/lib/middleware/django_middleware"
require "#{RAILS_ROOT}/lib/middleware/no_django_middleware"
config.middleware.use NoDjangoMiddleware
config.middleware.use DjangoMiddleware

# Make Time.zone default to the specified zone, and make Active Record store time values
# in the database in UTC, and return them converted to the specified local zone.
Expand Down
14 changes: 14 additions & 0 deletions lib/middleware/django_middleware.rb
@@ -0,0 +1,14 @@
class DjangoMiddleware
def initialize(app)
@app = app
end

def call(env)
status, headers, response = @app.call(env)
new_response = []
response.each do |part|
new_response << part.gsub(/Rails/, 'Django')
end
[status, headers, new_response]
end
end
14 changes: 14 additions & 0 deletions lib/middleware/no_django_middleware.rb
@@ -0,0 +1,14 @@
class NoDjangoMiddleware
def initialize(app)
@app = app
end

def call(env)
status, headers, response = @app.call(env)
new_response = []
response.each do |part|
new_response << part.gsub(/Django/, 'Rails')
end
[status, headers, new_response]
end
end

0 comments on commit 9ce77aa

Please sign in to comment.