package util.http;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;

public final class HttpWriter
{
	public static void writeAsClient(Socket socket, String data, String playerName) throws IOException
	{
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
		PrintWriter pw = new PrintWriter(bw);

		pw.println("POST / HTTP/1.0");
		pw.println("Accept: text/delim");
		pw.println("Sender: GAMESERVER");
		pw.println("Receiver: "+playerName);
		pw.println("Content-type: text/acl");
		pw.println("Content-length: " + data.length());
		pw.println();
		pw.println(data);

		pw.flush();
	}

	public static void writeAsServer(Socket socket, String data) throws IOException
	{
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
		PrintWriter pw = new PrintWriter(bw);

		pw.println("HTTP/1.0 200 OK");
		pw.println("Content-type: text/acl");
		pw.println("Content-length: " + data.length());
		pw.println("Access-Control-Allow-Origin: *");
		pw.println("Access-Control-Allow-Methods: POST, GET, OPTIONS");
		pw.println("Access-Control-Allow-Headers: *");
		pw.println("Access-Control-Allow-Age: 86400");
		pw.println();
		pw.println(data);

		pw.flush();
	}

}

@@ -158,16 +158,44 @@
 .Socket;
+%0Aimport java.net.URLEncoder;
 %0A%0Apublic
@@ -220,16 +220,512 @@
 riter%0A%7B%0A
+    public static void writeAsClientGET(Socket socket, String data, String playerName) throws IOException%0A    %7B%0A        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));%0A        PrintWriter pw = new PrintWriter(bw);%0A%0A        pw.println(%22GET /%22 + URLEncoder.encode(data, %22UTF-8%22) + %22 HTTP/1.0%22);%0A        pw.println(%22Accept: text/delim%22);%0A        pw.println(%22Sender: GAMESERVER%22);%0A        pw.println(%22Receiver: %22+playerName);%0A%0A        pw.flush();%0A    %7D%0A    %0A
 %09public 

Add a way to write to servers using GET rather than POST.