Class: Request

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) ⇒ Request

Returns a new instance of Request.



573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
# File 'lib/rwd/net.rb', line 573

def initialize(io)
  @io		= io

  firstline	= @io.gets

  return	if firstline.nil?

  @request	= RequestRequest.new(firstline.strip)

  line	= @io.gets
  line	= line.strip	unless line.nil?
  while not line.nil? and not line.empty?
    key, value	= line.split(" ", 2)
    self[key.sub(/:$/, "").downcase]	= value

    line	= @io.gets
    line	= line.strip	unless line.nil?
  end

  cookie	= self["cookie"]
  cookie	= ""	if cookie.nil?
  @cookies	= {}
  cookie.split(/;/).each do |s|
    k, v		= s.strip.split(/=/, 2)
    @cookies[k]	= v
  end

  if not @request.method.nil?
    case @request.method.upcase
    when "HEAD"
    when "GET"
      @vars	= RequestGet.new(@request.data.nil? ? "" : @request.data)
    when "POST"
      data	= (@io.read(self["content-length"].to_i) or "")
      @vars	= RequestPost.new((self["content-type"] == "application/x-www-form-urlencoded") ? data : "")
    else
      $stderr.puts "Unknown request ('#{firstline}')."
    end
  end

  @peeraddr	= @io.peeraddr

  @pda	= false
  @pda	= true	if (self.include?("user-agent") and self["user-agent"].downcase.include?("windows ce"))
  @pda	= true	if (self.include?("user-agent") and self["user-agent"].downcase.include?("handhttp"))

  @io.close_read
end

Instance Attribute Details

#cookiesObject (readonly)

Returns the value of attribute cookies.



568
569
570
# File 'lib/rwd/net.rb', line 568

def cookies
  @cookies
end

#peeraddrObject (readonly)

Returns the value of attribute peeraddr.



566
567
568
# File 'lib/rwd/net.rb', line 566

def peeraddr
  @peeraddr
end

#requestObject (readonly)

Returns the value of attribute request.



567
568
569
# File 'lib/rwd/net.rb', line 567

def request
  @request
end

#userObject

Returns the value of attribute user.



570
571
572
# File 'lib/rwd/net.rb', line 570

def user
  @user
end

#varsObject (readonly)

Returns the value of attribute vars.



569
570
571
# File 'lib/rwd/net.rb', line 569

def vars
  @vars
end

Instance Method Details

#inspectObject



634
635
636
# File 'lib/rwd/net.rb', line 634

def inspect
  "(Request: %s)" % [@peeraddr, @request.inspect, @vars.inspect, @cookies.inspect, super].join(", ")
end

#pda?Boolean

Returns:

  • (Boolean)


622
623
624
# File 'lib/rwd/net.rb', line 622

def pda?
  @pda
end

#to_sObject



626
627
628
629
630
631
632
# File 'lib/rwd/net.rb', line 626

def to_s
  res = @request.to_s
  self.each do |k, v|
    res << "#{k}: #{v}\r\n"
  end
  res
end