Index: org/apache/commons/httpclient/ContentLengthInputStream.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ContentLengthInputStream.java,v retrieving revision 1.6 diff -u -r1.6 ContentLengthInputStream.java --- org/apache/commons/httpclient/ContentLengthInputStream.java 28 Jan 2003 04:40:20 -0000 1.6 +++ org/apache/commons/httpclient/ContentLengthInputStream.java 12 Jul 2003 20:14:25 -0000 @@ -82,15 +82,17 @@ * The maximum number of bytes that can be read from the stream. Subsequent * read operations will return -1. */ - private int contentLength; + private long contentLength; /** The current position */ - private int pos = 0; + private long pos = 0; /** True if the stream is closed. */ private boolean closed = false; /** + * @deprecated use {@link #ContentLengthInputStream(InputStream, long)} + * * Creates a new length limited stream * * @param in The stream to wrap @@ -103,6 +105,18 @@ } /** + * Creates a new length limited stream + * + * @param in The stream to wrap + * @param contentLength The maximum number of bytes that can be read from + * the stream. Subsequent read operations will return -1. + */ + public ContentLengthInputStream(InputStream in, long contentLength) { + super(in); + this.contentLength = contentLength; + } + + /** *
Reads until the end of the known length of content.
* *Does not close the underlying socket input, but instead leaves it
@@ -162,7 +176,7 @@
}
if (pos + len > contentLength) {
- len = contentLength - pos;
+ len = (int) (contentLength - pos);
}
int count = super.read(b, off, len);
pos += count;
Index: org/apache/commons/httpclient/HttpMethodBase.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
retrieving revision 1.164
diff -u -r1.164 HttpMethodBase.java
--- org/apache/commons/httpclient/HttpMethodBase.java 11 Jul 2003 01:07:29 -0000 1.164
+++ org/apache/commons/httpclient/HttpMethodBase.java 12 Jul 2003 20:14:31 -0000
@@ -668,7 +668,7 @@
* If Content-Length header is not present, the method
* returns -1.
*/
- protected int getResponseContentLength() {
+ protected long getResponseContentLength() {
Header[] headers = getResponseHeaderGroup().getHeaders("Content-Length");
if (headers.length == 0) {
return -1;
@@ -679,7 +679,7 @@
for (int i = headers.length - 1; i >= 0; i++) {
Header header = headers[i];
try {
- return Integer.parseInt(header.getValue());
+ return Long.parseLong(header.getValue());
} catch (NumberFormatException e) {
if (LOG.isWarnEnabled()) {
LOG.warn("Invalid content-length value: " + e.getMessage());
@@ -1361,7 +1361,7 @@
*
* @return 0, indicating that the request has no body.
*/
- protected int getRequestContentLength() {
+ protected long getRequestContentLength() {
return 0;
}
@@ -1423,7 +1423,7 @@
+ "HttpState, HttpConnection)");
// add content length or chunking
- int len = getRequestContentLength();
+ long len = getRequestContentLength();
if (getRequestHeader("content-length") == null) {
if (0 < len) {
setRequestHeader("Content-Length", String.valueOf(len));
@@ -2080,7 +2080,7 @@
result = is;
}
} else {
- int expectedLength = getResponseContentLength();
+ long expectedLength = getResponseContentLength();
if (expectedLength == -1) {
if (canResponseHaveBody(statusLine.getStatusCode())) {
setConnectionCloseForced(true);
Index: org/apache/commons/httpclient/methods/EntityEnclosingMethod.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java,v
retrieving revision 1.19
diff -u -r1.19 EntityEnclosingMethod.java
--- org/apache/commons/httpclient/methods/EntityEnclosingMethod.java 5 Jul 2003 18:43:04 -0000 1.19
+++ org/apache/commons/httpclient/methods/EntityEnclosingMethod.java 12 Jul 2003 20:14:32 -0000
@@ -127,7 +127,7 @@
/** The content length of the requestBodyStream or one of
* CONTENT_LENGTH_AUTO and CONTENT_LENGTH_CHUNKED.
*/
- private int requestContentLength = CONTENT_LENGTH_AUTO;
+ private long requestContentLength = CONTENT_LENGTH_AUTO;
// ----------------------------------------------------------- Constructors
@@ -243,6 +243,8 @@
}
/**
+ * @deprecated use {@link #setRequestContentLength(long)} instead
+ *
* Sets length information about the request body.
*
*
@@ -268,12 +270,37 @@ } /** + * Sets length information about the request body. + * + *
+ * Note: If you specify a content length the request is unbuffered. This + * prevents redirection and automatic retry if a request fails the first + * time. This means that the HttpClient can not perform authorization + * automatically but will throw an Exception. You will have to set the + * necessary 'Authorization' or 'Proxy-Authorization' headers manually. + *
+ * + * @param length size in bytes or any of CONTENT_LENGTH_AUTO, + * CONTENT_LENGTH_CHUNKED. If number of bytes or CONTENT_LENGTH_CHUNKED + * is specified the content will not be buffered internally and the + * Content-Length header of the request will be used. In this case + * the user is responsible to supply the correct content length. + * If CONTENT_LENGTH_AUTO is specified the request will be buffered + * before it is sent over the network. + * + */ + public void setRequestContentLength(long length) { + LOG.trace("enter EntityEnclosingMethod.setRequestContentLength(int)"); + this.requestContentLength = length; + } + + /** * Override method of {@link org.apache.commons.httpclient.HttpMethodBase} * to return the length of the request body. * * @return number of bytes in the request body */ - protected int getRequestContentLength() { + protected long getRequestContentLength() { LOG.trace("enter EntityEnclosingMethod.getRequestContentLength()"); if (!hasRequestContent()) { @@ -306,9 +333,9 @@ LOG.trace("enter HttpMethodBase.addContentLengthRequestHeader(" + "HttpState, HttpConnection)"); - if ((getRequestHeader("content-length") == null) && - (getRequestHeader("Transfer-Encoding") == null)) { - int len = getRequestContentLength(); + if ((getRequestHeader("content-length") == null) + && (getRequestHeader("Transfer-Encoding") == null)) { + long len = getRequestContentLength(); if (len >= 0) { addRequestHeader("Content-Length", String.valueOf(len)); } else if ((len == CONTENT_LENGTH_CHUNKED) && (isHttp11())) { @@ -403,7 +430,7 @@ return true; } - int contentLength = getRequestContentLength(); + long contentLength = getRequestContentLength(); if ((contentLength == CONTENT_LENGTH_CHUNKED) && !isHttp11()) { throw new HttpException( Index: org/apache/commons/httpclient/methods/MultipartPostMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/MultipartPostMethod.java,v retrieving revision 1.18 diff -u -r1.18 MultipartPostMethod.java --- org/apache/commons/httpclient/methods/MultipartPostMethod.java 5 Jul 2003 18:43:04 -0000 1.18 +++ org/apache/commons/httpclient/methods/MultipartPostMethod.java 12 Jul 2003 20:14:33 -0000 @@ -250,16 +250,10 @@ * * @return The request content length. */ - protected int getRequestContentLength() { + protected long getRequestContentLength() { LOG.trace("enter MultipartPostMethod.getRequestContentLength()"); try { - long len = Part.getLengthOfParts(getParts()); - // Chop the length to the max int value. - if (len <= Integer.MAX_VALUE) { - return (int) len; - } else { - return (Integer.MAX_VALUE); - } + return Part.getLengthOfParts(getParts()); } catch (IOException e) { // Can't throw an IOException and still override throw new RuntimeException(e.toString());