summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrent Wheeldon <brent.wheeldon@gmail.com>2015-04-14 11:52:43 -0400
committerBrent Wheeldon <brent.wheeldon@gmail.com>2015-04-14 15:11:57 -0400
commitb79e15304213403858538f45b8d1928376776ddb (patch)
treeaea8a9387739fe24e166591df553bb890533b7d3
parentd68b93a9922b8bbfd76d5c7bcf5b63f2aec8f36f (diff)
downloadrack-b79e15304213403858538f45b8d1928376776ddb.tar.gz
Add HTTP response helpers for 204, 301, and 412.
-rw-r--r--lib/rack/response.rb43
-rw-r--r--test/spec_response.rb13
2 files changed, 36 insertions, 20 deletions
diff --git a/lib/rack/response.rb b/lib/rack/response.rb
index 2b23406f..1fe23a8a 100644
--- a/lib/rack/response.rb
+++ b/lib/rack/response.rb
@@ -115,26 +115,29 @@ module Rack
alias headers header
module Helpers
- def invalid?; status < 100 || status >= 600; end
-
- def informational?; status >= 100 && status < 200; end
- def successful?; status >= 200 && status < 300; end
- def redirection?; status >= 300 && status < 400; end
- def client_error?; status >= 400 && status < 500; end
- def server_error?; status >= 500 && status < 600; end
-
- def ok?; status == 200; end
- def created?; status == 201; end
- def accepted?; status == 202; end
- def bad_request?; status == 400; end
- def unauthorized?; status == 401; end
- def forbidden?; status == 403; end
- def not_found?; status == 404; end
- def method_not_allowed?; status == 405; end
- def i_m_a_teapot?; status == 418; end
- def unprocessable?; status == 422; end
-
- def redirect?; [301, 302, 303, 307].include? status; end
+ def invalid?; status < 100 || status >= 600; end
+
+ def informational?; status >= 100 && status < 200; end
+ def successful?; status >= 200 && status < 300; end
+ def redirection?; status >= 300 && status < 400; end
+ def client_error?; status >= 400 && status < 500; end
+ def server_error?; status >= 500 && status < 600; end
+
+ def ok?; status == 200; end
+ def created?; status == 201; end
+ def accepted?; status == 202; end
+ def no_content?; status == 204; end
+ def moved_permanently?; status == 301; end
+ def bad_request?; status == 400; end
+ def unauthorized?; status == 401; end
+ def forbidden?; status == 403; end
+ def not_found?; status == 404; end
+ def method_not_allowed?; status == 405; end
+ def precondition_failed?; status == 412; end
+ def i_m_a_teapot?; status == 418; end
+ def unprocessable?; status == 422; end
+
+ def redirect?; [301, 302, 303, 307].include? status; end
# Headers
attr_reader :headers, :original_headers
diff --git a/test/spec_response.rb b/test/spec_response.rb
index 6b13c0c9..20a2d0c3 100644
--- a/test/spec_response.rb
+++ b/test/spec_response.rb
@@ -231,6 +231,14 @@ describe Rack::Response do
res.should.be.successful
res.should.be.accepted
+ res.status = 204
+ res.should.be.successful
+ res.should.be.no_content
+
+ res.status = 301
+ res.should.be.redirect
+ res.should.be.moved_permanently
+
res.status = 400
res.should.not.be.successful
res.should.be.client_error
@@ -251,6 +259,11 @@ describe Rack::Response do
res.should.be.client_error
res.should.be.method_not_allowed
+ res.status = 412
+ res.should.not.be.successful
+ res.should.be.client_error
+ res.should.be.precondition_failed
+
res.status = 418
res.should.not.be.successful
res.should.be.client_error