diff options
author | Andrei Belov <defan@nginx.com> | 2019-08-22 21:33:54 +0300 |
---|---|---|
committer | Andrei Belov <defan@nginx.com> | 2019-08-22 21:33:54 +0300 |
commit | a07c4d30a64f781f93730576b5dced32422a9935 (patch) | |
tree | 06ebfaa66845a057b8069014c5379b2dcfc80861 /src/java/nginx/unit/Context.java | |
parent | 8a579acddeae0c0106e15d82aa7220ac01deba84 (diff) | |
parent | c47af243b0e805376c4ec908f21e07dc811b33f0 (diff) | |
download | unit-a07c4d30a64f781f93730576b5dced32422a9935.tar.gz unit-a07c4d30a64f781f93730576b5dced32422a9935.tar.bz2 |
Merged with the default branch.1.10.0-1
Diffstat (limited to '')
-rw-r--r-- | src/java/nginx/unit/Context.java | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/java/nginx/unit/Context.java b/src/java/nginx/unit/Context.java index f6d5e339..e1482903 100644 --- a/src/java/nginx/unit/Context.java +++ b/src/java/nginx/unit/Context.java @@ -81,6 +81,7 @@ import javax.servlet.ServletSecurityElement; import javax.servlet.SessionCookieConfig; import javax.servlet.SessionTrackingMode; import javax.servlet.annotation.HandlesTypes; +import javax.servlet.annotation.MultipartConfig; import javax.servlet.annotation.WebInitParam; import javax.servlet.annotation.WebServlet; import javax.servlet.annotation.WebFilter; @@ -313,6 +314,7 @@ public class Context implements ServletContext, InitParams } else { response.setContentLengthLong(f.length()); + response.setContentType(getMimeType(f.getName())); InputStream is = new FileInputStream(f); byte[] buffer = new byte[response.getBufferSize()]; @@ -953,6 +955,8 @@ public class Context implements ServletContext, InitParams ServletReg servlet = findServlet(path, req); + req.setMultipartConfig(servlet.multipart_config_); + FilterChain fc = new CtxFilterChain(servlet, req.getFilterPath(), DispatcherType.REQUEST); fc.doFilter(req, resp); @@ -1073,6 +1077,8 @@ public class Context implements ServletContext, InitParams ServletReg servlet = findServlet(path, req); + req.setMultipartConfig(servlet.multipart_config_); + FilterChain fc = new CtxFilterChain(servlet, req.getFilterPath(), DispatcherType.ERROR); fc.doFilter(req, resp); @@ -1851,11 +1857,13 @@ public class Context implements ServletContext, InitParams private boolean initialized_ = false; private final List<FilterMap> filters_ = new ArrayList<>(); private boolean system_jsp_servlet_ = false; + private MultipartConfigElement multipart_config_; public ServletReg(String name, Class<?> servlet_class) { super(name, servlet_class.getName()); servlet_class_ = servlet_class; + getAnnotationMultipartConfig(); } public ServletReg(String name, Servlet servlet) @@ -1892,6 +1900,7 @@ public class Context implements ServletContext, InitParams try { if (servlet_class_ == null) { servlet_class_ = loader_.loadClass(getClassName()); + getAnnotationMultipartConfig(); } Constructor<?> ctor = servlet_class_.getConstructor(); @@ -1947,6 +1956,20 @@ public class Context implements ServletContext, InitParams super.setClassName(servlet_class.getName()); servlet_class_ = servlet_class; + getAnnotationMultipartConfig(); + } + + private void getAnnotationMultipartConfig() { + if (servlet_class_ == null) { + return; + } + + MultipartConfig mpc = servlet_class_.getAnnotation(MultipartConfig.class); + if (mpc == null) { + return; + } + + multipart_config_ = new MultipartConfigElement(mpc); } public void service(ServletRequest request, ServletResponse response) @@ -2026,7 +2049,8 @@ public class Context implements ServletContext, InitParams public void setMultipartConfig( MultipartConfigElement multipartConfig) { - log("ServletReg.setMultipartConfig"); + trace("ServletReg.setMultipartConfig"); + multipart_config_ = multipartConfig; } @Override @@ -2507,6 +2531,8 @@ public class Context implements ServletContext, InitParams ServletReg servlet = findServlet(path, req); + req.setMultipartConfig(servlet.multipart_config_); + req.setRequestURI(uri_.getRawPath()); req.setQueryString(uri_.getRawQuery()); req.setDispatcherType(DispatcherType.FORWARD); @@ -2576,6 +2602,8 @@ public class Context implements ServletContext, InitParams ServletReg servlet = findServlet(path, req); + req.setMultipartConfig(servlet.multipart_config_); + req.setRequestURI(uri_.getRawPath()); req.setQueryString(uri_.getRawQuery()); req.setDispatcherType(DispatcherType.INCLUDE); @@ -2756,7 +2784,7 @@ public class Context implements ServletContext, InitParams { trace("getRealPath for " + path); - File f = new File(webapp_, path.substring(1)); + File f = new File(webapp_, path.isEmpty() ? "" : path.substring(1)); return f.getAbsolutePath(); } |