From 6f7bd66dfa16c3f6a74b32615cacbc743cbe6d36 Mon Sep 17 00:00:00 2001 From: Aaron Suggs Date: Wed, 21 May 2014 18:33:20 -0400 Subject: [PATCH] Default responses: add Content-Type header Fixes #68 --- CHANGELOG.md | 1 + lib/rack/attack.rb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e44a446..198b221 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changlog ## master (unreleased) + - Default throttled/blacklist responses have Content-Type: text/plain - Rack::Attack.clear! resets tracks ## v4.0.1 - 14 May 2014 diff --git a/lib/rack/attack.rb b/lib/rack/attack.rb index 0ec982c..78fb386 100644 --- a/lib/rack/attack.rb +++ b/lib/rack/attack.rb @@ -80,10 +80,10 @@ class Rack::Attack # Set defaults @notifier = ActiveSupport::Notifications if defined?(ActiveSupport::Notifications) - @blacklisted_response = lambda {|env| [403, {}, ["Forbidden\n"]] } + @blacklisted_response = lambda {|env| [403, {'Content-Type' => 'text/plain'}, ["Forbidden\n"]] } @throttled_response = lambda {|env| retry_after = env['rack.attack.match_data'][:period] rescue nil - [429, {'Retry-After' => retry_after.to_s}, ["Retry later\n"]] + [429, {'Content-Type' => 'text/plain', 'Retry-After' => retry_after.to_s}, ["Retry later\n"]] } def initialize(app)