Class: Digup::Responder
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#response ⇒ Object
Returns the value of attribute response.
-
#response_body ⇒ Object
Returns the value of attribute response_body.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
-
#append_javascript_to_evaluate_json ⇒ Object
Appends javascript to every page when response_type Setting includes :json Appends javascript to display json response appendes to original response.
-
#append_template_to_response(template) ⇒ Object
Appends template to reponse depending on the settings.
-
#build_response ⇒ Object
build a response to be sent to client.
- #can_handle_response? ⇒ Boolean
-
#clear_digup_message_store ⇒ Object
clears log message unless its not a redirection If its redirection log needs to be displayed on redirected page.
- #empty_response? ⇒ Boolean
- #html_response? ⇒ Boolean
-
#initialize(original_response) ⇒ Responder
constructor
A new instance of Responder.
- #javascript_response? ⇒ Boolean
- #json_response? ⇒ Boolean
- #request ⇒ Object
- #response_not_a_file? ⇒ Boolean
-
#valid? ⇒ Boolean
If responsder is valid, then only response is modified.
Constructor Details
#initialize(original_response) ⇒ Responder
Returns a new instance of Responder.
7 8 9 10 |
# File 'lib/digup/responder.rb', line 7 def initialize(original_response) @original_response = original_response @status, @headers, @response = original_response end |
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers.
5 6 7 |
# File 'lib/digup/responder.rb', line 5 def headers @headers end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/digup/responder.rb', line 5 def response @response end |
#response_body ⇒ Object
Returns the value of attribute response_body.
5 6 7 |
# File 'lib/digup/responder.rb', line 5 def response_body @response_body end |
#status ⇒ Object
Returns the value of attribute status.
5 6 7 |
# File 'lib/digup/responder.rb', line 5 def status @status end |
Instance Method Details
#append_javascript_to_evaluate_json ⇒ Object
Appends javascript to every page when response_type Setting includes :json Appends javascript to display json response appendes to original response
28 29 30 31 32 33 34 35 |
# File 'lib/digup/responder.rb', line 28 def append_javascript_to_evaluate_json if response_body.include?('</body>') position = response_body.rindex('</body>') response_body.insert(position, Template.javascript_template_to_evaluate_json) else response_body << Template.javascript_template_to_evaluate_json end end |
#append_template_to_response(template) ⇒ Object
Appends template to reponse depending on the settings
17 18 19 20 21 22 23 24 |
# File 'lib/digup/responder.rb', line 17 def append_template_to_response(template) position = if response_body.include?('</body>') response_body.rindex('</body>') else javascript_response? ? response_body.length : response_body.length - 1 end response_body.insert(position, (json_response? ? '' : "\n") + template ) end |
#build_response ⇒ Object
build a response to be sent to client
55 56 57 |
# File 'lib/digup/responder.rb', line 55 def build_response valid? ? [status, headers, [response_body]] : @original_response end |
#can_handle_response? ⇒ Boolean
69 70 71 |
# File 'lib/digup/responder.rb', line 69 def can_handle_response? Setting.content_type_to_handle.include?(response.content_type) end |
#clear_digup_message_store ⇒ Object
clears log message unless its not a redirection If its redirection log needs to be displayed on redirected page. So its not cleared
61 62 63 |
# File 'lib/digup/responder.rb', line 61 def Digup..clear unless [301, 302].include?(status) end |
#empty_response? ⇒ Boolean
41 42 43 44 45 46 |
# File 'lib/digup/responder.rb', line 41 def empty_response? (@response.is_a?(Array) && @response.size <= 1) || !@response.respond_to?(:body) || !response_body.respond_to?(:empty?) || response_body.empty? end |
#html_response? ⇒ Boolean
73 74 75 |
# File 'lib/digup/responder.rb', line 73 def html_response? response.content_type == 'text/html' end |
#javascript_response? ⇒ Boolean
77 78 79 |
# File 'lib/digup/responder.rb', line 77 def javascript_response? response.content_type == 'text/javascript' end |
#json_response? ⇒ Boolean
81 82 83 |
# File 'lib/digup/responder.rb', line 81 def json_response? response.content_type == 'application/json' end |
#request ⇒ Object
12 13 14 |
# File 'lib/digup/responder.rb', line 12 def request response.request end |
#response_not_a_file? ⇒ Boolean
37 38 39 |
# File 'lib/digup/responder.rb', line 37 def response_not_a_file? headers["Content-Transfer-Encoding"] != "binary" end |
#valid? ⇒ Boolean
If responsder is valid, then only response is modified
49 50 51 52 |
# File 'lib/digup/responder.rb', line 49 def valid? !empty_response? && !response_body.frozen? && response_not_a_file? && status == 200 && can_handle_response? end |