My question duplicates javax.servlet.HttpServletRequest.getContentLength() returns int only, however I am interested in different. What is proper return of javax.servlet.HttpServletRequest.getContentLength() when content length is greater than Integer.MAX_VALUE? The question author assumes it is -1. However servlet specification doesn't cover the topic. http://docs.oracle.com/javaee/6/api/javax/servlet/ServletRequest.html#getContentLength%28%29 It says as -1 when length is unknown. It is incorrect because length is known, simply can't fit Integer. EE7 covers the gap http://docs.oracle.com/javaee/7/api/javax/servlet/ServletRequest.html#getContentLength%28%29 and even introduces getContentLengthLong(). However my question is if I implement EE6 specification what is right behavior in case of content length > Integer.MAX_VALUE?
Asked
Active
Viewed 705 times
1 Answers
1
You need to read the JavaDoc for the Java EE 7 version of ServletRequest.getContentLength().
It says quite clearly:
... or -1 if the length is not known or is greater than Integer.MAX_VALUE
Beware that if you're attempting to read a large request body it will almost certainly be chunked anyway. Many HTTP firewalls and proxies will chunk large bodies as a matter of course.

Steve C
- 18,876
- 5
- 34
- 37
-
You're quite right - I must have been overdoing the multitasking that day. I will remove this answer shortly and provide a better one. – Steve C Jun 20 '14 at 07:40