Class: Response
Instance Attribute Summary collapse
-
#at_stop ⇒ Object
readonly
Returns the value of attribute at_stop.
-
#cookies ⇒ Object
readonly
Returns the value of attribute cookies.
-
#file ⇒ Object
writeonly
Sets the attribute file.
-
#response ⇒ Object
writeonly
Sets the attribute response.
-
#stop(&block) ⇒ Object
readonly
Returns the value of attribute stop.
Instance Method Summary collapse
- #<<(s) ⇒ Object
- #clean ⇒ Object
- #flush ⇒ Object
-
#initialize(io) ⇒ Response
constructor
A new instance of Response.
- #inspect ⇒ Object
- #stop? ⇒ Boolean
- #sync ⇒ Object
- #to_s ⇒ Object
Methods inherited from Hash
file, #ids, #rwd_table, #save, #subset, #to_i
Constructor Details
#initialize(io) ⇒ Response
Returns a new instance of Response.
646 647 648 649 650 651 652 653 654 655 |
# File 'lib/rwd/net.rb', line 646 def initialize(io) @io = io @response = "HTTP/1.0 200 OK" @cookies = {} @data = "" @syncd = false @stop = false @at_stop = lambda{} @file = nil end |
Instance Attribute Details
#at_stop ⇒ Object (readonly)
Returns the value of attribute at_stop.
644 645 646 |
# File 'lib/rwd/net.rb', line 644 def at_stop @at_stop end |
#cookies ⇒ Object (readonly)
Returns the value of attribute cookies.
642 643 644 |
# File 'lib/rwd/net.rb', line 642 def @cookies end |
#file=(value) ⇒ Object (writeonly)
Sets the attribute file
641 642 643 |
# File 'lib/rwd/net.rb', line 641 def file=(value) @file = value end |
#response=(value) ⇒ Object (writeonly)
Sets the attribute response
640 641 642 |
# File 'lib/rwd/net.rb', line 640 def response=(value) @response = value end |
#stop(&block) ⇒ Object (readonly)
Returns the value of attribute stop.
643 644 645 |
# File 'lib/rwd/net.rb', line 643 def stop @stop end |
Instance Method Details
#<<(s) ⇒ Object
706 707 708 |
# File 'lib/rwd/net.rb', line 706 def << (s) @data << s end |
#clean ⇒ Object
710 711 712 |
# File 'lib/rwd/net.rb', line 710 def clean @data = "" end |
#flush ⇒ Object
657 658 659 660 661 662 663 664 665 666 667 668 669 |
# File 'lib/rwd/net.rb', line 657 def flush sync if @file File.open(@file, "rb") do |f| while data = f.read(10_000) @io.write data end end end @io.close end |
#inspect ⇒ Object
714 715 716 |
# File 'lib/rwd/net.rb', line 714 def inspect "(Response: %s)" % [@response, @data].join(", ") end |
#stop? ⇒ Boolean
723 724 725 |
# File 'lib/rwd/net.rb', line 723 def stop? @stop end |
#sync ⇒ Object
684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 |
# File 'lib/rwd/net.rb', line 684 def sync size = (@data or "").length if @file ext = @file.scan(/\.[^\.]*$/) ext = ext.shift ext = ext[1..-1] unless ext.nil? mimetype = EVMime::MimeType[ext] self["Content-Type"] = mimetype unless mimetype.nil? size += File.size(@file) if File.file?(@file) end self["Content-Length"] = size @io.write("#{to_s}\r\n") unless @syncd @io.write(@data) @data = "" @syncd = true end |
#to_s ⇒ Object
671 672 673 674 675 676 677 678 679 680 681 682 |
# File 'lib/rwd/net.rb', line 671 def to_s res = "#{@response}\r\n" self.each do |k, v| res << "#{k}: #{v}\r\n" end @cookies.each do |k, v| res << "Set-Cookie: %s=%s;\r\n" % [k, v] end res end |