Class: Spider::Response
Instance Attribute Summary collapse
-
#cookies ⇒ Object
Returns the value of attribute cookies.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#server_output ⇒ Object
Returns the value of attribute server_output.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
- #body=(io) ⇒ Object
- #buffer ⇒ Object
- #buffer_until_length ⇒ Object
- #buffering? ⇒ Boolean
- #clear_buffer ⇒ Object
- #connection_keep_alive ⇒ Object
- #content_length ⇒ Object
- #content_length=(val) ⇒ Object
- #content_type ⇒ Object
- #content_type=(val) ⇒ Object
- #do_not_buffer! ⇒ Object
- #finish! ⇒ Object
-
#initialize ⇒ Response
constructor
A new instance of Response.
- #no_cookies ⇒ Object
- #output_buffer ⇒ Object
- #prepare_headers ⇒ Object
- #register(key, val) ⇒ Object
- #start_buffering ⇒ Object
- #stop_buffering ⇒ Object
Constructor Details
Instance Attribute Details
#cookies ⇒ Object
Returns the value of attribute cookies.
7 8 9 |
# File 'lib/spiderfw/controller/response.rb', line 7 def @cookies end |
#headers ⇒ Object
Returns the value of attribute headers.
7 8 9 |
# File 'lib/spiderfw/controller/response.rb', line 7 def headers @headers end |
#server_output ⇒ Object
Returns the value of attribute server_output.
7 8 9 |
# File 'lib/spiderfw/controller/response.rb', line 7 def server_output @server_output end |
#status ⇒ Object
Returns the value of attribute status.
6 7 8 |
# File 'lib/spiderfw/controller/response.rb', line 6 def status @status end |
Instance Method Details
#body=(io) ⇒ Object
14 15 16 |
# File 'lib/spiderfw/controller/response.rb', line 14 def body=(io) @server_output.set_body_io(io) end |
#buffer ⇒ Object
78 79 80 |
# File 'lib/spiderfw/controller/response.rb', line 78 def buffer @buffer end |
#buffer_until_length ⇒ Object
106 107 108 109 110 111 |
# File 'lib/spiderfw/controller/response.rb', line 106 def buffer_until_length unless content_length start_buffering @buffer_until_length = true end end |
#buffering? ⇒ Boolean
52 53 54 |
# File 'lib/spiderfw/controller/response.rb', line 52 def buffering? @prev_io != nil end |
#clear_buffer ⇒ Object
82 83 84 |
# File 'lib/spiderfw/controller/response.rb', line 82 def clear_buffer @buffer = nil end |
#connection_keep_alive ⇒ Object
122 123 124 125 |
# File 'lib/spiderfw/controller/response.rb', line 122 def connection_keep_alive @headers['Connection'] = 'Keep-Alive' buffer_until_length unless Spider.conf.get('webserver.has_buffering_proxy') end |
#content_length ⇒ Object
102 103 104 |
# File 'lib/spiderfw/controller/response.rb', line 102 def content_length @headers['Content-Length'] end |
#content_length=(val) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/spiderfw/controller/response.rb', line 94 def content_length=(val) @headers['Content-Length'] = val if @buffer_until_length && val output_buffer @buffer_until_length = false end end |
#content_type ⇒ Object
90 91 92 |
# File 'lib/spiderfw/controller/response.rb', line 90 def content_type @headers['Content-Type'] end |
#content_type=(val) ⇒ Object
86 87 88 |
# File 'lib/spiderfw/controller/response.rb', line 86 def content_type=(val) @headers['Content-Type'] = val end |
#do_not_buffer! ⇒ Object
127 128 129 130 131 132 133 |
# File 'lib/spiderfw/controller/response.rb', line 127 def do_not_buffer! unless Spider.conf.get('webserver.has_buffering_proxy') @headers['Connection'] = 'Close' end output_buffer @buffer_until_length = false end |
#finish! ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/spiderfw/controller/response.rb', line 113 def finish! if buffering? stop_buffering needs_length = @needs_length self.content_length = @buffer.length output_buffer unless needs_length end end |
#no_cookies ⇒ Object
23 24 25 |
# File 'lib/spiderfw/controller/response.rb', line 23 def @no_cookies = true end |
#output_buffer ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/spiderfw/controller/response.rb', line 67 def output_buffer stop_buffering if buffering? return unless @buffer while d = @buffer.read(1024) $out << d end buffer = @buffer @buffer = nil buffer end |
#prepare_headers ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/spiderfw/controller/response.rb', line 27 def prepare_headers unless @no_cookies @headers['Set-Cookie'] ||= [] @cookies.each do |k, v| h = "#{k}=#{v}" h += '; expires='+v.expires.strftime("%a, %b %d %Y %H:%M:%S %Z") if (v.expires.respond_to?(:strftime)) h += "; path=#{v.path}" if (v.path) h += "; domain=#{v.domain}" if (v.domain) h += "; secure" if (v.secure) @headers['Set-Cookie'] << h end end Spider::Logger.debug("HEADERS:") Spider::Logger.debug(@headers) end |
#register(key, val) ⇒ Object
18 19 20 21 |
# File 'lib/spiderfw/controller/response.rb', line 18 def register(key, val) instance_variable_set("@#{key}", val) self.class.send(:attr_accessor, key) # FIXME: threadsafety end |