Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
#1112 Allow to limit the size of whole request or the size of one upl…
…oaded file in a request.

 The configuration parameters are: 'upload.sizeMax' and 'upload.fileSizeMax'.
 The defaults stay the same -1 which means 'unlimited'.
  • Loading branch information
Erik Jõgi authored and Erik Jõgi, Andrei Solntsev committed Feb 22, 2017
1 parent faf0972 commit 65a7ba9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
15 changes: 15 additions & 0 deletions documentation/manual/configuration.textile
Expand Up @@ -1165,6 +1165,21 @@ bc. upload.threshold=20480

Default: @10240@

h3(#upload.maxRequestSize). upload.maxRequestSize

The maximum size permitted for the complete request. A value of -1 indicates no maximum.

bc. upload.maxRequestSize=2048

Default: @-1@

h3(#upload.maxFileSize). upload.maxFileSize

The maximum size permitted for a single uploaded file, as opposed to. A value of -1 indicates no maximum.

bc. upload.maxFileSize=1024

Default: @-1@

h2(#xforwarded). Proxy forwarding

Expand Down
16 changes: 8 additions & 8 deletions framework/src/play/data/parsing/ApacheMultipartParser.java
Expand Up @@ -610,14 +610,14 @@ public Map<String, String[]> parse(InputStream body) {
// ----------------------------------------------------------- Data members
/**
* The maximum size permitted for the complete request, as opposed to
* {@link #fileSizeMax}. A value of -1 indicates no maximum.
* {@link #maxFileSize}. A value of -1 indicates no maximum.
*/
private long sizeMax = -1;
private long maxRequestSize = Integer.parseInt(Play.configuration.getProperty("upload.maxRequestSize", "-1"));
/**
* The maximum size permitted for a single uploaded file, as opposed to
* {@link #sizeMax}. A value of -1 indicates no maximum.
* {@link #maxRequestSize}. A value of -1 indicates no maximum.
*/
private long fileSizeMax = -1;
private long maxFileSize = Integer.parseInt(Play.configuration.getProperty("upload.maxFileSize", "-1"));

// ------------------------------------------------------ Protected methods

Expand Down Expand Up @@ -865,8 +865,8 @@ private class FileItemStreamImpl implements FileItemStream {
contentType = pContentType;
formField = pFormField;
InputStream istream = multi.newInputStream();
if (fileSizeMax != -1) {
istream = new LimitedInputStream(istream, fileSizeMax) {
if (maxFileSize != -1) {
istream = new LimitedInputStream(istream, maxFileSize) {

@Override
protected void raiseError(long pSizeMax, long pCount) throws IOException {
Expand Down Expand Up @@ -998,10 +998,10 @@ void close() throws IOException {
throw new InvalidContentTypeException("the request doesn't contain a " + MULTIPART_FORM_DATA + " or " + MULTIPART_MIXED + " stream, content type header is " + contentType);
}

if (sizeMax >= 0) {
if (maxRequestSize >= 0) {
// TODO check size

input = new LimitedInputStream(input, sizeMax) {
input = new LimitedInputStream(input, maxRequestSize) {

@Override
protected void raiseError(long pSizeMax, long pCount) throws IOException {
Expand Down

0 comments on commit 65a7ba9

Please sign in to comment.