1 //header of class--------------------------------------------------------------- 2 import java.*; 3 import java.io.*; 4 import java.net.*; 5 6 public class MiniProxy extends TCPService{ 7 private boolean analyzed; 8 private StringBuffer fromnet; 9 private int tail; 10 public final static int BUILD=54; 11 //serve.zdys-------------------------------------------------------------------- 12 public void serve(){ 13 try{ 14 BufferedReader br= new BufferedReader(new InputStreamReader(so.getInputStream())); 15 DataOutputStream dos= new DataOutputStream(new BufferedOutputStream(so.getOutputStream())); 16 StringBuffer sb= new StringBuffer(); 17 String line= ""; 18 do{ 19 line= br.readLine(); 20 sb.append(line); 21 sb.append("\r\n"); 22 }while(!line.trim().equals("")); 23 Socket s2= new Socket("heise.de", 80); 24 DataOutputStream dosh= new DataOutputStream(new BufferedOutputStream(s2.getOutputStream())); 25 DataInputStream dish= new DataInputStream(new BufferedInputStream(s2.getInputStream())); 26 byte[] recdata= new byte[4096]; 27 byte[] toheise= (sb.toString()).getBytes(); 28 Utils.pr(this, "from browser:\n"+ sb.toString()); 29 dosh.write(toheise, 0, toheise.length); 30 dosh.flush(); 31 analyzed= false; 32 tail= 0x00000000; 33 fromnet= new StringBuffer(); 34 fromnet.append("from net:\n"); 35 try{ 36 while(true){ 37 dish.readFully(recdata); 38 analyzeHeader(recdata); 39 dos.write(recdata, 0, recdata.length); 40 } 41 }catch(Exception ex2){ 42 analyzeHeader(recdata); 43 dos.write(recdata, 0, recdata.length); 44 } 45 dos.flush(); 46 s2.close(); 47 so.close(); 48 }catch(Exception ex){ 49 Utils.pr(this, "ERROR in run():"+ ex); 50 } 51 } 52 //analyzeHeader.zdys------------------------------------------------------------ 53 private void analyzeHeader(byte[] given) throws Exception{ 54 if(!analyzed){ 55 BufferedReader br= new BufferedReader(new InputStreamReader(new ByteArrayInputStream(given))); 56 int act= 0; 57 while((act= br.read())!= -1){ 58 tail<<= 8; 59 tail+= act; 60 if(tail== 0x0d0a0d0a){ 61 analyzed= true; 62 Utils.pr(this, fromnet.toString()); 63 return; 64 }else{ 65 fromnet.append((char)act); 66 } 67 } 68 } 69 } 70 //end of class------------------------------------------------------------------ 71 }