Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into merge-1.1.x-changes
Browse files Browse the repository at this point in the history
# Conflicts:
#	Gemfile.lock
  • Loading branch information
chadlwilson committed Nov 26, 2024
2 parents 1221ff8 + 73be8e9 commit db6037b
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/spec/java/org/jruby/rack/mock/MockServletContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Enumeration;
Expand All @@ -31,7 +34,6 @@
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import javax.activation.FileTypeMap;
import javax.servlet.Filter;
import javax.servlet.FilterRegistration;
import javax.servlet.RequestDispatcher;
Expand Down Expand Up @@ -263,7 +265,12 @@ public int getEffectiveMinorVersion() {

@Override
public String getMimeType(String filePath) {
return MimeTypeResolver.getMimeType(filePath);
try {
Path path = Paths.get(filePath);
return Files.probeContentType(path);
} catch (IOException e) {
return "application/octet-stream"; // default MIME type
}
}

@Override
Expand Down Expand Up @@ -456,20 +463,6 @@ public String getServletContextName() {
return this.servletContextName;
}


/**
* Inner factory class used to just introduce a Java Activation Framework
* dependency when actually asked to resolve a MIME type.
*/
private static class MimeTypeResolver {

public static String getMimeType(String filePath) {
return FileTypeMap.getDefaultFileTypeMap().getContentType(filePath);
}

}


//---------------------------------------------------------------------
// Methods introduced in Servlet 3.0
//---------------------------------------------------------------------
Expand Down

0 comments on commit db6037b

Please sign in to comment.