Method: Request#initialize

Defined in:
lib/rwd/net.rb

#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
      if $DEBUG
         $stderr.puts data  
      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