Skip to content

Commit

Permalink
Merge pull request #4371 from lachlan-roberts/jetty-10.0.x-4368-Multi…
Browse files Browse the repository at this point in the history
…PartsReview

Issue #4368 - remove MultiParts interface and simplify MultiPart cleanup
  • Loading branch information
lachlan-roberts committed Nov 27, 2019
2 parents 4af2857 + 76bb8d2 commit e8746ec
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 261 deletions.

This file was deleted.

This file was deleted.

27 changes: 18 additions & 9 deletions jetty-server/src/main/java/org/eclipse/jetty/server/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.http.MetaData;
import org.eclipse.jetty.http.MimeTypes;
import org.eclipse.jetty.http.MultiPartFormInputStream;
import org.eclipse.jetty.http.pathmap.PathSpec;
import org.eclipse.jetty.http.pathmap.ServletPathSpec;
import org.eclipse.jetty.io.RuntimeIOException;
Expand Down Expand Up @@ -141,7 +142,6 @@
public class Request implements HttpServletRequest
{
public static final String __MULTIPART_CONFIG_ELEMENT = "org.eclipse.jetty.multipartConfig";
public static final String __MULTIPARTS = "org.eclipse.jetty.multiParts";

private static final Logger LOG = Log.getLogger(Request.class);
private static final Collection<Locale> __defaultLocale = Collections.singleton(Locale.getDefault());
Expand Down Expand Up @@ -228,7 +228,7 @@ public static Request getBaseRequest(ServletRequest request)
private HttpSession _session;
private SessionHandler _sessionHandler;
private long _timeStamp;
private MultiParts _multiParts; //if the request is a multi-part mime
private MultiPartFormInputStream _multiParts; //if the request is a multi-part mime
private AsyncContextState _async;
private List<Session> _sessions; //list of sessions used during lifetime of request

Expand Down Expand Up @@ -1504,6 +1504,19 @@ public void onCompleted()
for (Session s:_sessions)
leaveSession(s);
}

//Clean up any tmp files created by MultiPartInputStream
if (_multiParts != null)
{
try
{
_multiParts.deleteParts();
}
catch (Throwable e)
{
LOG.warn("Errors deleting multipart tmp files", e);
}
}
}

/**
Expand Down Expand Up @@ -2305,17 +2318,13 @@ public Collection<Part> getParts() throws IOException, ServletException

private Collection<Part> getParts(MultiMap<String> params) throws IOException
{
if (_multiParts == null)
_multiParts = (MultiParts)getAttribute(__MULTIPARTS);

if (_multiParts == null)
{
MultipartConfigElement config = (MultipartConfigElement)getAttribute(__MULTIPART_CONFIG_ELEMENT);
if (config == null)
throw new IllegalStateException("No multipart config for servlet");

_multiParts = newMultiParts(config);
setAttribute(__MULTIPARTS, _multiParts);
Collection<Part> parts = _multiParts.getParts();

String formCharset = null;
Expand Down Expand Up @@ -2377,10 +2386,10 @@ else if (getCharacterEncoding() != null)
return _multiParts.getParts();
}

private MultiParts newMultiParts(MultipartConfigElement config) throws IOException
private MultiPartFormInputStream newMultiParts(MultipartConfigElement config) throws IOException
{
return new MultiParts.MultiPartsHttpParser(getInputStream(), getContentType(), config,
(_context != null ? (File)_context.getAttribute("javax.servlet.context.tempdir") : null), this);
return new MultiPartFormInputStream(getInputStream(), getContentType(), config,
(_context != null ? (File)_context.getAttribute("javax.servlet.context.tempdir") : null));
}

@Override
Expand Down

0 comments on commit e8746ec

Please sign in to comment.