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.



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
621
622
623
624
625
626
627
628
629
630
# File 'lib/rwd/net.rb', line 579

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 "")
    #  data = url_unescape(data)
      @vars	= RequestPost.new((self["content-type"] == "application/x-www-form-urlencoded") ? data : "")
    else
      $stderr.puts "Unknown request ('#{firstline}')."
end

$rwdtinkerlog.debug  data  
   
  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.



574
575
576
# File 'lib/rwd/net.rb', line 574

def cookies
  @cookies
end

#peeraddrObject (readonly)

Returns the value of attribute peeraddr.



572
573
574
# File 'lib/rwd/net.rb', line 572

def peeraddr
  @peeraddr
end

#requestObject (readonly)

Returns the value of attribute request.



573
574
575
# File 'lib/rwd/net.rb', line 573

def request
  @request
end

#userObject

Returns the value of attribute user.



576
577
578
# File 'lib/rwd/net.rb', line 576

def user
  @user
end

#varsObject (readonly)

Returns the value of attribute vars.



575
576
577
# File 'lib/rwd/net.rb', line 575

def vars
  @vars
end

Instance Method Details

#inspectObject



644
645
646
# File 'lib/rwd/net.rb', line 644

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

#pda?Boolean

Returns:

  • (Boolean)


632
633
634
# File 'lib/rwd/net.rb', line 632

def pda?
  @pda
end

#to_sObject



636
637
638
639
640
641
642
# File 'lib/rwd/net.rb', line 636

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