Skip to content

Commit 02f7bac

Browse files
authored
Merge pull request #1110 from codeborne/uploadSizeFix
[#1112] Allow to limit the size of whole request or the size of one uploaded file in a request
2 parents faf0972 + 65a7ba9 commit 02f7bac

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

documentation/manual/configuration.textile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,21 @@ bc. upload.threshold=20480
11651165

11661166
Default: @10240@
11671167

1168+
h3(#upload.maxRequestSize). upload.maxRequestSize
1169+
1170+
The maximum size permitted for the complete request. A value of -1 indicates no maximum.
1171+
1172+
bc. upload.maxRequestSize=2048
1173+
1174+
Default: @-1@
1175+
1176+
h3(#upload.maxFileSize). upload.maxFileSize
1177+
1178+
The maximum size permitted for a single uploaded file, as opposed to. A value of -1 indicates no maximum.
1179+
1180+
bc. upload.maxFileSize=1024
1181+
1182+
Default: @-1@
11681183

11691184
h2(#xforwarded). Proxy forwarding
11701185

framework/src/play/data/parsing/ApacheMultipartParser.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -610,14 +610,14 @@ public Map<String, String[]> parse(InputStream body) {
610610
// ----------------------------------------------------------- Data members
611611
/**
612612
* The maximum size permitted for the complete request, as opposed to
613-
* {@link #fileSizeMax}. A value of -1 indicates no maximum.
613+
* {@link #maxFileSize}. A value of -1 indicates no maximum.
614614
*/
615-
private long sizeMax = -1;
615+
private long maxRequestSize = Integer.parseInt(Play.configuration.getProperty("upload.maxRequestSize", "-1"));
616616
/**
617617
* The maximum size permitted for a single uploaded file, as opposed to
618-
* {@link #sizeMax}. A value of -1 indicates no maximum.
618+
* {@link #maxRequestSize}. A value of -1 indicates no maximum.
619619
*/
620-
private long fileSizeMax = -1;
620+
private long maxFileSize = Integer.parseInt(Play.configuration.getProperty("upload.maxFileSize", "-1"));
621621

622622
// ------------------------------------------------------ Protected methods
623623

@@ -865,8 +865,8 @@ private class FileItemStreamImpl implements FileItemStream {
865865
contentType = pContentType;
866866
formField = pFormField;
867867
InputStream istream = multi.newInputStream();
868-
if (fileSizeMax != -1) {
869-
istream = new LimitedInputStream(istream, fileSizeMax) {
868+
if (maxFileSize != -1) {
869+
istream = new LimitedInputStream(istream, maxFileSize) {
870870

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

1001-
if (sizeMax >= 0) {
1001+
if (maxRequestSize >= 0) {
10021002
// TODO check size
10031003

1004-
input = new LimitedInputStream(input, sizeMax) {
1004+
input = new LimitedInputStream(input, maxRequestSize) {
10051005

10061006
@Override
10071007
protected void raiseError(long pSizeMax, long pCount) throws IOException {

0 commit comments

Comments
 (0)