package exploitpack;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author jsacco
 */
public class XSSServer implements Runnable {

    Set XSSAgents = new HashSet();

    public XSSServer() throws Exception {

    }

    @Override
    public void run() {

        class MyHandler implements HttpHandler {

            @Override
            public void handle(HttpExchange t) throws IOException {
                XSSAgents.add(t.getRequestURI());
                System.out.println(t.getRequestURI());
                System.out.println(XSSAgents.contains(t.getRequestURI()));
                String response = "Welcome Real's HowTo test page";
                t.sendResponseHeaders(200, response.length());
                try (OutputStream os = t.getResponseBody()) {
                    os.write(response.getBytes());
                }
            }
        }
        HttpServer server;
        try {
            server = HttpServer.create(new InetSocketAddress(8000), 0);
            server.createContext("/test", new MyHandler());
            server.setExecutor(null); // creates a default executor
            server.start();
        } catch (IOException ex) {
            Logger.getLogger(XSSServer.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

}
