diff options
author | Jason Garber <jason@sixtwothree.org> | 2022-04-27 23:45:29 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-28 15:45:29 +1200 |
commit | 53458855fbbec1a08503aa6efac80643c627da85 (patch) | |
tree | fb71347d0cb5994322ec7ccb19dad8c647f27780 | |
parent | 504f1d56e60613d3d43c4271ebab8fff2d35a157 (diff) | |
download | rack-53458855fbbec1a08503aa6efac80643c627da85.tar.gz |
Add methods for HTTP status codes 406 and 408 (#1882)
This commit adds two new predicate methods to the `Rack::Response` class: - `not_acceptable?` which returns true on HTTP 406 Not Acceptable - `request_timeout?` which returns true on HTTP 408 Request Timeout Links to MDN documentation for each status code: - https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/406 - https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408
-rw-r--r-- | lib/rack/response.rb | 2 | ||||
-rw-r--r-- | test/spec_response.rb | 10 |
2 files changed, 12 insertions, 0 deletions
diff --git a/lib/rack/response.rb b/lib/rack/response.rb index d75a0fac..d621587c 100644 --- a/lib/rack/response.rb +++ b/lib/rack/response.rb @@ -190,6 +190,8 @@ module Rack def forbidden?; status == 403; end def not_found?; status == 404; end def method_not_allowed?; status == 405; end + def not_acceptable?; status == 406; end + def request_timeout?; status == 408; end def precondition_failed?; status == 412; end def unprocessable?; status == 422; end diff --git a/test/spec_response.rb b/test/spec_response.rb index 5e6d5a5b..54f41753 100644 --- a/test/spec_response.rb +++ b/test/spec_response.rb @@ -503,6 +503,16 @@ describe Rack::Response do res.must_be :client_error? res.must_be :method_not_allowed? + res.status = 406 + res.wont_be :successful? + res.must_be :client_error? + res.must_be :not_acceptable? + + res.status = 408 + res.wont_be :successful? + res.must_be :client_error? + res.must_be :request_timeout? + res.status = 412 res.wont_be :successful? res.must_be :client_error? |