Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding capability to take max upload size per request.Fileupload 1 3 1 #22

Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/main/java/org/apache/commons/fileupload/FileUploadBase.java
Expand Up @@ -205,6 +205,18 @@ public static boolean isMultipartContent(HttpServletRequest req) {
public long getSizeMax() {
return sizeMax;
}

/**
* This method enables subclassed to set
codecracker2014 marked this conversation as resolved.
Show resolved Hide resolved
allowed size per request if needed.
* @param ctx
* @return
*/
codecracker2014 marked this conversation as resolved.
Show resolved Hide resolved
public long getSizeMaxForThisRequest(RequestContext ctx) {
return sizeMax;
codecracker2014 marked this conversation as resolved.
Show resolved Hide resolved
}



/**
* Sets the maximum allowed size of a complete request, as opposed
Expand Down Expand Up @@ -959,15 +971,15 @@ public void setHeaders(FileItemHeaders pHeaders) {
? ((UploadContext) ctx).contentLength()
: contentLengthInt;
// CHECKSTYLE:ON

if (sizeMax >= 0) {
if (requestSize != -1 && requestSize > sizeMax) {
long sizeMaxForThisRequest = getSizeMaxForThisRequest(ctx);
if (sizeMaxForThisRequest >= 0) {
if (requestSize != -1 && requestSize > sizeMaxForThisRequest) {
throw new SizeLimitExceededException(
format("the request was rejected because its size (%s) exceeds the configured maximum (%s)",
Long.valueOf(requestSize), Long.valueOf(sizeMax)),
requestSize, sizeMax);
Long.valueOf(requestSize), Long.valueOf(sizeMaxForThisRequest)),
requestSize, sizeMaxForThisRequest);
}
input = new LimitedInputStream(input, sizeMax) {
input = new LimitedInputStream(input, sizeMaxForThisRequest) {
@Override
protected void raiseError(long pSizeMax, long pCount)
throws IOException {
Expand Down
Expand Up @@ -123,5 +123,14 @@ public String toString() {
Long.valueOf(this.contentLength()),
this.getContentType());
}

/**
*
* @return
codecracker2014 marked this conversation as resolved.
Show resolved Hide resolved
*/
public HttpServletRequest getRequest(){
return this.request;
}


}