final public void handle_connect(boolean direct) throws IOException
{
 WebConnection wc;
 try
 {
    wc=new WebConnection(proxyhost,proxyport);
 }
 catch (IOException e)
 {
     send_error(500,"Connect to server failed ("+e+"). CONNECT request canceled.");
     return;
 }
  DataInputStream sin=wc.webis;
  DataOutputStream sou=wc.webos;
  if(!direct)
  {
      /* write connect request to https_proxy */
      sou.writeBytes("CONNECT ");
      sou.writeBytes(URL);
      sou.writeBytes(" HTTP/1.0\r\n\r\n");
      sou.flush();
  }
  else
  {
      out.writeBytes("HTTP/1.0 200 Connection established\r\nProxy-agent: ");
      out.writeBytes(scache.VERSION);
      out.writeBytes("\r\n\r\n");
      out.flush();
      httprc=200;
  }

  /* buffer */
  byte b[]=new byte[512];
  int rb;

  // Thread worker=new Thread(new InOut(sin,out,Thread.currentThread()));
  Thread worker=new Thread(new InOut(in,sou,Thread.currentThread()));
  worker.start();

  mainloop:while(true)
  {
     if(Thread.interrupted()) break;
     rb=sin.read(b,0,512);
     if(rb==-1) break mainloop;
     out.write(b,0,rb);
     log_size+=rb;
     out.flush();
  }
  worker.interrupt();
  wc.close();
  close();
  keepalive=false;
  return;
}