PROXY  WHOIS  RQUOTE  TEXTS  SOFT  FOREX  BBOARD
 Music  Philosophy  Code  Literature  Russian

= ROOT|Technical|Code_Examples|Perl|Proxy|httpproxy-1.5.3.pl =

page 2 of 8



	if (defined $byte_read) {
	  debug "Client->Proxy ($byte_read bytes)",$sck;
	  if ($byte_read == 0) { # remote client/server just closed the connection?
	    debug "Client closed the connection",$sck;
	    clientclose $sck;
	    next READ_FHS;
	  }
	  else {
	    $st{$sck}{req} .= $buffer;
	  }	    
	}
	elsif ($! == EAGAIN()) { # socket buffer empty
	  debug "Client too slow, skipping... (non-blocking)",$sck;
	  last;
	}
	else { # anything elses...
	  debug "Client connection error",$sck;
	  clientclose $sck;
	  next READ_FHS;
	}
      }
      debug "Parsing header...", $sck;      
      if ($st{$sck}{mark} == 1) { # get request line
	while (1) { # skip crlf before start-line
	  unless ($st{$sck}{req} =~ s/^([^\r]*\r\n)//) {
	    debug "Client send partial request line header...getting some more", $sck;
	    next READ_FHS;
	  }
	  $buffer = $1;
	  $st{$sck}{req_orig} .= $buffer;
	  last if $buffer ne "\r\n";
	}
	# parse request start-line
	if ($buffer =~ /^(\w+)\s+([^\s]+)\s+([^\s]+)/) {
	  $st{$sck}{metode} = $1; 
	  $st{$sck}{uri} = $2; 
	  $st{$sck}{versi} = $3; $st{$sck}{persist} = 0 if $3 ne "HTTP/1.1";
	  $st{$sck}{uri} =~ m|^((\w*)://)?(.*?)(:(\d*))?(/.*)?$|; 
	  $st{$sck}{uri_scheme} = $2; 
	  $st{$sck}{uri_hostname} = $3; 
	  $st{$sck}{uri_port} = $5 ? $5 : "80"; 
	  $st{$sck}{uri_abspath} = $6 ? $6 : "/";
	}
	else {
	  quickresp 400, "Bad Request Start-line: $buffer", $sck;
	  $st{$sck}{persist} = 0;
	  next READ_FHS;
	}	
	if ($st{$sck}{uri_hostname} eq "!config") { # pure GNU, anyone may see the source code
	  my $haha = `cat $0`;
	  $haha =~ s/</>/g;
	  $haha =~ s/>/</g;
	  quickresp 200,"Here's the source code of this program:\n</h3><pre>$haha</pre>",$sck;
	  $st{$sck}{persist} = 0;
	  next READ_FHS;
	}	
	if ($st{$sck}{uri_hostname} eq "") {
	  quickresp 400,"You need to give absolute URI",$sck;
	  $st{$sck}{persist} = 0;
	  next READ_FHS;
	}

	for my $word (@sensors) { # access rule by URI
	  if ( $st{$sck}{uri} =~ /$word/i) {
	    quickresp 400,"Access blocked by URI ($st{$sck}{uri})",$sck;
	    next READ_FHS;
	  }
	}
	
	# build request line using URI rule
	$st{$sck}{req_line} = join "", $st{$sck}{metode}," ", $proxy ?
	                      $st{$sck}{uri} : 
                              $st{$sck}{uri_abspath},
                              " ", "HTTP/1.1\r\n";
	$st{$sck}{mark} = 2;
      }

      if ($st{$sck}{mark} == 2) { # get request field header
	while (1) { 
	  unless ($st{$sck}{req} =~ s/^([^\r]*\r\n)//) {
	    debug "Client send partial field header...getting some more", $sck;
	    next READ_FHS;
	  }
	  $buffer =  $1;
	  last if $buffer eq "\r\n";  
	  $st{$sck}{req_orig} .= $buffer;
	  # removing request field-line
	  next if $buffer =~ /^Connection:/i; 
	  next if $buffer =~ /^Proxy-Connection:/i;
	  $st{$sck}{req_fields} .= $buffer;
	  }	
	$st{$sck}{req_fields}||=""; 
	
	# Virtual host rule
	if ($st{$sck}{req_fields} !~ /^Host:/im) {
	  $st{$sck}{req_fields} .= "Host: $st{$sck}{uri_hostname}:$st{$sck}{uri_port}\r\n";
	}
	
	# Persistent connection rule
	if ($st{$sck}{versi} ne "HTTP/1.1" or 
=2=

1| < PREV = PAGE 2 = NEXT > |3|4|5|6|7|8

UP TO ROOT | UP TO DIR | TO FIRST PAGE

Google
 


E-mail Facebook Google Digg del.icio.us BlinkList Fark Furl Ma.gnolia Netscape NewsVine Reddit Slashdot Spurl StumbleUpon Technorati YahooMyWeb LiveJournal Blogmarks TwitThis Live News2.ru BobrDobr.ru Memori.ru MoeMesto.ru

0.00586796 wallclock secs ( 0.01 usr + 0.00 sys = 0.01 CPU)