Class: Response

Inherits:
Hash show all
Defined in:
lib/rwd/net.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Hash

file, #ids, #rwd_table, #save, #subset, #to_i

Constructor Details

#initialize(io) ⇒ Response

Returns a new instance of Response.



656
657
658
659
660
661
662
663
664
665
# File 'lib/rwd/net.rb', line 656

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_stopObject (readonly)

Returns the value of attribute at_stop.



654
655
656
# File 'lib/rwd/net.rb', line 654

def at_stop
  @at_stop
end

#cookiesObject (readonly)

Returns the value of attribute cookies.



652
653
654
# File 'lib/rwd/net.rb', line 652

def cookies
  @cookies
end

#file=(value) ⇒ Object (writeonly)

Sets the attribute file

Parameters:

  • value

    the value to set the attribute file to.



651
652
653
# File 'lib/rwd/net.rb', line 651

def file=(value)
  @file = value
end

#response=(value) ⇒ Object (writeonly)

Sets the attribute response

Parameters:

  • value

    the value to set the attribute response to.



650
651
652
# File 'lib/rwd/net.rb', line 650

def response=(value)
  @response = value
end

#stop(&block) ⇒ Object (readonly)

Returns the value of attribute stop.



653
654
655
# File 'lib/rwd/net.rb', line 653

def stop
  @stop
end

Instance Method Details

#<<(s) ⇒ Object



716
717
718
# File 'lib/rwd/net.rb', line 716

def << (s)
  @data << s
end

#cleanObject



720
721
722
# File 'lib/rwd/net.rb', line 720

def clean
  @data	= ""
end

#flushObject



667
668
669
670
671
672
673
674
675
676
677
678
679
# File 'lib/rwd/net.rb', line 667

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

#inspectObject



724
725
726
# File 'lib/rwd/net.rb', line 724

def inspect
  "(Response: %s)" % [@response, @data].join(", ")
end

#stop?Boolean

Returns:

  • (Boolean)


733
734
735
# File 'lib/rwd/net.rb', line 733

def stop?
  @stop
end

#syncObject



694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
# File 'lib/rwd/net.rb', line 694

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_sObject



681
682
683
684
685
686
687
688
689
690
691
692
# File 'lib/rwd/net.rb', line 681

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