// This code is provided "as is" with NO WARRANTY expressed or // implied. You may use it freely at your own risk. import java.io.*; import java.net.*; public class Bounce { static int getContentLen(String line) throws NumberFormatException { String l = line.substring(line.indexOf(": ") + 2 ); return (Integer.parseInt(l)); } public static void main(String args[]) { try { int port = Integer.parseInt(args[0]); ServerSocket ss = new ServerSocket(port); for(;;) { Socket client = ss.accept(); BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream())); PrintWriter out = new PrintWriter(new OutputStreamWriter(client.getOutputStream())); out.println("HTTP/1.0 200 "); out.println("Content-Type: text/plain"); out.println(); String line; int cLen = 0; while ((line = in.readLine()) != null) { out.println(line); if (line.indexOf("ength: ") >= 0) { cLen = Bounce.getContentLen(line); } if (line.length() == 0) break; } if (cLen > 0) { char[] buffer = new char[cLen]; in.read(buffer, 0, cLen); line = new String(buffer); out.println(line); } out.flush(); out.close(); in.close(); client.close(); } } catch (NumberFormatException n) { System.err.println(n); } catch (Exception e) { System.err.println(e); } } }