Add support for 'http-reponse-headers' attribute to add custom response headers

This commit is contained in:
Mike Primm 2011-08-29 21:33:41 -05:00
parent 7e37817b86
commit 5088adb7eb
4 changed files with 33 additions and 0 deletions

View file

@ -303,6 +303,19 @@ public class DynmapPlugin extends JavaPlugin {
boolean checkbannedips = configuration.getBoolean("check-banned-ips", true);
int maxconnections = configuration.getInteger("max-sessions", 30);
if(maxconnections < 2) maxconnections = 2;
/* Load customized response headers, if any */
ConfigurationNode custhttp = configuration.getNode("http-response-headers");
HashMap<String, String> custhdrs = new HashMap<String,String>();
if(custhttp != null) {
for(String k : custhttp.keySet()) {
String v = custhttp.getString(k);
if(v != null) {
custhdrs.put(k, v);
}
}
}
HttpServer.setCustomHeaders(custhdrs);
if(allow_symlinks)
Log.verboseinfo("Web server is permitting symbolic links");
else

View file

@ -10,8 +10,10 @@ import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.logging.Logger;
@ -34,6 +36,7 @@ public class HttpServer extends Thread {
private Object lock = new Object();
private HashSet<HttpServerConnection> active_connections = new HashSet<HttpServerConnection>();
private HashSet<HttpServerConnection> keepalive_connections = new HashSet<HttpServerConnection>();
private static Map<String, String> headers = new HashMap<String,String>();
public HttpServer(InetAddress bindAddress, int port, boolean check_banned_ips, int max_sessions) {
this.bindAddress = bindAddress;
@ -189,4 +192,10 @@ public class HttpServer extends Thread {
}
return false;
}
public static Map<String,String> getCustomHeaders() {
return headers;
}
public static void setCustomHeaders(Map<String,String> hdrs) {
headers = hdrs;
}
}

View file

@ -111,6 +111,12 @@ public class HttpServerConnection extends Thread {
out.append(field.getValue());
out.append("\r\n");
}
for(Entry<String, String> custom : HttpServer.getCustomHeaders().entrySet()) {
out.append(custom.getKey());
out.append(": ");
out.append(custom.getValue());
out.append("\r\n");
}
out.append("\r\n");
out.flush();
}