still working on mime problem
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.srsoftware</groupId>
|
||||
<artifactId>web4rail</artifactId>
|
||||
<version>0.11.19</version>
|
||||
<version>0.11.20</version>
|
||||
<name>Web4Rail</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Java Model Railway Control</description>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
</appender>
|
||||
|
||||
<logger name="de.srsoftware.web4rail" level="DEBUG"/>
|
||||
<logger name="de.srsoftware.web4rail.Application" level="INFO"/>
|
||||
<logger name="de.srsoftware.web4rail.Application" level="DEBUG"/>
|
||||
<logger name="de.srsoftware.web4rail.Command" level="INFO"/>
|
||||
<logger name="de.srsoftware.web4rail.ControlUnit" level="INFO"/>
|
||||
|
||||
|
||||
@@ -8,13 +8,17 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.FileNameMap;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -206,10 +210,9 @@ public class Application extends BaseClass{
|
||||
File file = new File(System.getProperty("user.dir")+"/resources"+uri);
|
||||
LOG.debug("requesting file: {}",file);
|
||||
if (file.exists()) {
|
||||
LOG.debug("found...");
|
||||
String ct = Files.probeContentType(file.toPath());
|
||||
LOG.debug("Content-Type: {}",ct);
|
||||
client.getResponseHeaders().add("Content-Type", ct);
|
||||
String mime = mimeOf(file);
|
||||
LOG.debug("Mime type: {}",mime);
|
||||
client.getResponseHeaders().add("Content-Type", mime);
|
||||
LOG.debug("Length: {}",file.length());
|
||||
client.sendResponseHeaders(200, file.length());
|
||||
LOG.debug("Sent headers...");
|
||||
@@ -226,6 +229,18 @@ public class Application extends BaseClass{
|
||||
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
|
||||
* @param client
|
||||
|
||||
Reference in New Issue
Block a user