Merge remote-tracking branch 'origin/jetty-11.0.x' into jetty-12.0.x
This commit is contained in:
commit
0532e23ba6
|
@ -18,7 +18,7 @@ import org.junit.jupiter.api.Disabled;
|
|||
@Disabled // TODO
|
||||
public class MultiPartFormInputStreamTest
|
||||
{
|
||||
/* TODO
|
||||
/* TODO pull extra changes from Jetty 11
|
||||
private static final AtomicInteger testCounter = new AtomicInteger();
|
||||
private static final String FILENAME = "stuff.txt";
|
||||
protected String _contentType = "multipart/form-data, boundary=AaB03x";
|
||||
|
|
|
@ -30,6 +30,7 @@ import java.nio.file.StandardCopyOption;
|
|||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -91,6 +92,7 @@ public class MultiPartFormInputStream
|
|||
|
||||
private final AutoLock _lock = new AutoLock();
|
||||
private final MultiMap<Part> _parts = new MultiMap<>();
|
||||
private final EnumSet<NonCompliance> _nonComplianceWarnings = EnumSet.noneOf(NonCompliance.class);
|
||||
private final InputStream _in;
|
||||
private final MultipartConfigElement _config;
|
||||
private final File _contextTmpDir;
|
||||
|
@ -102,6 +104,31 @@ public class MultiPartFormInputStream
|
|||
private volatile int _bufferSize = 16 * 1024;
|
||||
private State state = State.UNPARSED;
|
||||
|
||||
public enum NonCompliance
|
||||
{
|
||||
TRANSFER_ENCODING("https://tools.ietf.org/html/rfc7578#section-4.7");
|
||||
|
||||
final String _rfcRef;
|
||||
|
||||
NonCompliance(String rfcRef)
|
||||
{
|
||||
_rfcRef = rfcRef;
|
||||
}
|
||||
|
||||
public String getURL()
|
||||
{
|
||||
return _rfcRef;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an EnumSet of non compliances with the RFC that were accepted by this parser
|
||||
*/
|
||||
public EnumSet<NonCompliance> getNonComplianceWarnings()
|
||||
{
|
||||
return _nonComplianceWarnings;
|
||||
}
|
||||
|
||||
public class MultiPart implements Part
|
||||
{
|
||||
protected String _name;
|
||||
|
@ -671,7 +698,11 @@ public class MultiPartFormInputStream
|
|||
|
||||
// Transfer encoding is not longer considers as it is deprecated as per
|
||||
// https://tools.ietf.org/html/rfc7578#section-4.7
|
||||
|
||||
if (key.equalsIgnoreCase("content-transfer-encoding"))
|
||||
{
|
||||
if (!"8bit".equalsIgnoreCase(value) && !"binary".equalsIgnoreCase(value))
|
||||
_nonComplianceWarnings.add(NonCompliance.TRANSFER_ENCODING);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -65,6 +65,7 @@ import jakarta.servlet.http.Part;
|
|||
import jakarta.servlet.http.PushBuilder;
|
||||
import org.eclipse.jetty.http.BadMessageException;
|
||||
import org.eclipse.jetty.http.ComplianceViolation;
|
||||
import org.eclipse.jetty.http.HttpCompliance;
|
||||
import org.eclipse.jetty.http.HttpCookie;
|
||||
import org.eclipse.jetty.http.HttpCookie.SetCookieHttpField;
|
||||
import org.eclipse.jetty.http.HttpField;
|
||||
|
@ -2000,6 +2001,7 @@ public class Request implements HttpServletRequest
|
|||
|
||||
_multiParts = newMultiParts(config);
|
||||
Collection<Part> parts = _multiParts.getParts();
|
||||
setNonComplianceViolationsOnRequest();
|
||||
|
||||
String formCharset = null;
|
||||
Part charsetPart = _multiParts.getPart("_charset_");
|
||||
|
@ -2060,6 +2062,22 @@ public class Request implements HttpServletRequest
|
|||
return _multiParts.getParts();
|
||||
}
|
||||
|
||||
private void setNonComplianceViolationsOnRequest()
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> violations = (List<String>)getAttribute(HttpCompliance.VIOLATIONS_ATTR);
|
||||
if (violations != null)
|
||||
return;
|
||||
|
||||
EnumSet<MultiPartFormInputStream.NonCompliance> nonComplianceWarnings = _multiParts.getNonComplianceWarnings();
|
||||
violations = new ArrayList<>();
|
||||
for (MultiPartFormInputStream.NonCompliance nc : nonComplianceWarnings)
|
||||
{
|
||||
violations.add(nc.name() + ": " + nc.getURL());
|
||||
}
|
||||
setAttribute(HttpCompliance.VIOLATIONS_ATTR, violations);
|
||||
}
|
||||
|
||||
private MultiPartFormInputStream newMultiParts(MultipartConfigElement config) throws IOException
|
||||
{
|
||||
return new MultiPartFormInputStream(getInputStream(), getContentType(), config,
|
||||
|
|
|
@ -486,6 +486,7 @@ public class RequestTest
|
|||
"Host: whatever\r\n" +
|
||||
"Content-Type: multipart/form-data; boundary=\"AaB03x\"\r\n" +
|
||||
"Content-Length: " + multipart.getBytes().length + "\r\n" +
|
||||
"Content-Transfer-Encoding: something\r\n" +
|
||||
"\r\n" +
|
||||
multipart;
|
||||
|
||||
|
@ -500,7 +501,9 @@ public class RequestTest
|
|||
"\r\n";
|
||||
|
||||
endPoint.addInput(cleanupRequest);
|
||||
assertTrue(endPoint.getResponse().startsWith("HTTP/1.1 200"));
|
||||
String response = endPoint.getResponse();
|
||||
assertTrue(response.startsWith("HTTP/1.1 200"));
|
||||
assertThat(response, containsString("Violation: TRANSFER_ENCODING"));
|
||||
assertThat("File Count in dir: " + testTmpDir, getFileCount(testTmpDir), is(0L));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue