|
|
@ -8,13 +8,17 @@ import java.io.IOException; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.io.OutputStreamWriter; |
|
|
|
import java.io.OutputStreamWriter; |
|
|
|
import java.lang.reflect.InvocationTargetException; |
|
|
|
import java.lang.reflect.InvocationTargetException; |
|
|
|
|
|
|
|
import java.net.FileNameMap; |
|
|
|
import java.net.InetAddress; |
|
|
|
import java.net.InetAddress; |
|
|
|
import java.net.InetSocketAddress; |
|
|
|
import java.net.InetSocketAddress; |
|
|
|
import java.net.URI; |
|
|
|
import java.net.URI; |
|
|
|
|
|
|
|
import java.net.URLConnection; |
|
|
|
import java.net.URLDecoder; |
|
|
|
import java.net.URLDecoder; |
|
|
|
import java.nio.file.Files; |
|
|
|
import java.nio.file.Files; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Vector; |
|
|
|
|
|
|
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
@ -206,10 +210,9 @@ public class Application extends BaseClass{ |
|
|
|
File file = new File(System.getProperty("user.dir")+"/resources"+uri); |
|
|
|
File file = new File(System.getProperty("user.dir")+"/resources"+uri); |
|
|
|
LOG.debug("requesting file: {}",file); |
|
|
|
LOG.debug("requesting file: {}",file); |
|
|
|
if (file.exists()) { |
|
|
|
if (file.exists()) { |
|
|
|
LOG.debug("found..."); |
|
|
|
String mime = mimeOf(file); |
|
|
|
String ct = Files.probeContentType(file.toPath()); |
|
|
|
LOG.debug("Mime type: {}",mime); |
|
|
|
LOG.debug("Content-Type: {}",ct); |
|
|
|
client.getResponseHeaders().add("Content-Type", mime); |
|
|
|
client.getResponseHeaders().add("Content-Type", ct); |
|
|
|
|
|
|
|
LOG.debug("Length: {}",file.length()); |
|
|
|
LOG.debug("Length: {}",file.length()); |
|
|
|
client.sendResponseHeaders(200, file.length()); |
|
|
|
client.sendResponseHeaders(200, file.length()); |
|
|
|
LOG.debug("Sent headers..."); |
|
|
|
LOG.debug("Sent headers..."); |
|
|
@ -226,6 +229,18 @@ public class Application extends BaseClass{ |
|
|
|
sendError(client,404,t("Could not find \"{}\"",uri)); |
|
|
|
sendError(client,404,t("Could not find \"{}\"",uri)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static String mimeOf(File file) throws IOException { |
|
|
|
|
|
|
|
String[] parts = file.toString().split("\\."); |
|
|
|
|
|
|
|
switch (parts[parts.length-1].toLowerCase()) { |
|
|
|
|
|
|
|
case "js": |
|
|
|
|
|
|
|
return "application/javascript"; |
|
|
|
|
|
|
|
case "css": |
|
|
|
|
|
|
|
return "text/css"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
LOG.warn("No conten type stored for {}!",file); |
|
|
|
|
|
|
|
return Files.probeContentType(file.toPath()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* sends a response to a given client |
|
|
|
* sends a response to a given client |
|
|
|
* @param client |
|
|
|
* @param client |
|
|
|