Class: Doze::Responder
Defined Under Namespace
Classes: Error, Main, Resource
Constant Summary
Constants included from Utils
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #auth_failed_response ⇒ Object
- #call ⇒ Object
- #error_response(status = STATUS_INTERNAL_SERVER_ERROR, message = nil, headers = {}, backtrace = nil) ⇒ Object
- #error_response_from_error(error) ⇒ Object
-
#initialize(app, request) ⇒ Responder
constructor
A new instance of Responder.
-
#raise_error(status = STATUS_INTERNAL_SERVER_ERROR, message = nil, headers = {}) ⇒ Object
for use within #response.
- #recognized_method ⇒ Object
Methods included from Utils
#escape, #quote, #request_base_uri, #unescape
Constructor Details
#initialize(app, request) ⇒ Responder
Returns a new instance of Responder.
6 7 8 9 |
# File 'lib/doze/responder.rb', line 6 def initialize(app, request) @app = app @request = request end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
4 5 6 |
# File 'lib/doze/responder.rb', line 4 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
4 5 6 |
# File 'lib/doze/responder.rb', line 4 def response @response end |
Instance Method Details
#auth_failed_response ⇒ Object
52 53 54 55 56 57 |
# File 'lib/doze/responder.rb', line 52 def auth_failed_response error_response(@request.session_authenticated? ? STATUS_FORBIDDEN : # this one, 403, really means 'unauthorized', ie STATUS_UNAUTHORIZED # http status code 401 called 'unauthorized' but really used to mean 'unauthenticated' ) end |
#call ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/doze/responder.rb', line 31 def call begin response().finish rescue Doze::Error => error error_response_from_error(error).finish rescue => exception raise unless @app.config[:catch_application_errors] lines = ["#{exception.class}: #{exception.}", *exception.backtrace].join("\n") @app.logger << lines if @app.config[:expose_exception_details] error_response(STATUS_INTERNAL_SERVER_ERROR, exception., {}, exception.backtrace).finish else error_response.finish end end end |
#error_response(status = STATUS_INTERNAL_SERVER_ERROR, message = nil, headers = {}, backtrace = nil) ⇒ Object
23 24 25 |
# File 'lib/doze/responder.rb', line 23 def error_response(status=STATUS_INTERNAL_SERVER_ERROR, =nil, headers={}, backtrace=nil) error_response_from_error(Doze::Error.new(status, , headers, backtrace)) end |
#error_response_from_error(error) ⇒ Object
27 28 29 |
# File 'lib/doze/responder.rb', line 27 def error_response_from_error(error) Doze::Responder::Error.new(@app, @request, error).response end |
#raise_error(status = STATUS_INTERNAL_SERVER_ERROR, message = nil, headers = {}) ⇒ Object
for use within #response
19 20 21 |
# File 'lib/doze/responder.rb', line 19 def raise_error(status=STATUS_INTERNAL_SERVER_ERROR, =nil, headers={}) raise Doze::Error.new(status, , headers) end |
#recognized_method ⇒ Object
11 12 13 14 15 16 |
# File 'lib/doze/responder.rb', line 11 def recognized_method @recognized_method ||= begin method = @request.normalized_request_method ([:options] + @app.config[:recognized_methods]).find {|m| m.to_s == method} or raise_error(STATUS_NOT_IMPLEMENTED) end end |