Index: java/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.172 diff -u -r1.172 HttpMethodBase.java --- java/org/apache/commons/httpclient/HttpMethodBase.java 22 Jul 2003 18:17:48 -0000 1.172 +++ java/org/apache/commons/httpclient/HttpMethodBase.java 25 Jul 2003 09:51:21 -0000 @@ -1328,25 +1328,6 @@ } /** - * Return the length (in bytes) of my request body, suitable for use in a - * Content-Length header. - * - *

- * Return -1 when the content-length is unknown. - *

- * - *

- * This implementation returns 0, indicating that the request has - * no body. - *

- * - * @return 0, indicating that the request has no body. - */ - protected long getRequestContentLength() { - return 0; - } - - /** * Adds an Authorization request if needed, as long as no * Authorization request header already exists. * @@ -1382,39 +1363,6 @@ } /** - * Adds a Content-Length or Transfer-Encoding: Chunked - * request header, as long as no Content-Length request header - * already exists. - * - * TODO: Revise this method as it is potentially error-prone. - * 'Transfer-encoding: chunked' header should not be set here - * as some sub classes may not support chunk-encoding. - * - * @param state current state of http requests - * @param conn the connection to use for I/O - * - * @throws IOException when errors occur reading or writing to/from the - * connection - * @throws HttpException when a recoverable error occurs - */ - protected void addContentLengthRequestHeader(HttpState state, - HttpConnection conn) - throws IOException, HttpException { - LOG.trace("enter HttpMethodBase.addContentLengthRequestHeader(" - + "HttpState, HttpConnection)"); - - // add content length or chunking - long len = getRequestContentLength(); - if (getRequestHeader("content-length") == null) { - if (0 < len) { - setRequestHeader("Content-Length", String.valueOf(len)); - } else if (http11 && (len < 0)) { - setRequestHeader("Transfer-Encoding", "chunked"); - } - } - } - - /** * Adds a Cookie request containing the matching {@link Cookie}s. * * @param state current state of http requests @@ -1567,8 +1515,8 @@ * *

* This implementation adds User-Agent, Host, - * Cookie, Content-Length, Transfer-Encoding, - * and Authorization headers, when appropriate. + * Cookie, Authorization, Proxy-Authorization + * and Proxy-Connection headers, when appropriate. *

* *

@@ -1596,7 +1544,6 @@ addAuthorizationRequestHeader(state, conn); addProxyAuthorizationRequestHeader(state, conn); addProxyConnectionHeader(state, conn); - addContentLengthRequestHeader(state, conn); } /** Index: java/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.23 diff -u -r1.23 EntityEnclosingMethod.java --- java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java 17 Jul 2003 21:57:42 -0000 1.23 +++ java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java 25 Jul 2003 09:51:22 -0000 @@ -235,10 +235,7 @@ */ public void setFollowRedirects(boolean followRedirects) { if (followRedirects == true) { - // TODO: EntityEnclosingMethod should inherit from HttpMethodBase rather than GetMethod - // Enable exception once the inheritence is fixed - //throw new IllegalArgumentException( - // "Entity enclosing requests cannot be redirected without user intervention"); + throw new IllegalArgumentException("Entity enclosing requests cannot be redirected without user intervention"); } super.setFollowRedirects(false); } @@ -317,6 +314,37 @@ } /** + * Populates the request headers map to with additional {@link Header + * headers} to be submitted to the given {@link HttpConnection}. + * + *

+ * This implementation adds tt>Content-Length or Transfer-Encoding + * headers. + *

+ * + *

+ * Subclasses may want to override this method to to add additional + * headers, and may choose to invoke this implementation (via + * super) to add the "standard" headers. + *

+ * + * @param state the client state + * @param conn the {@link HttpConnection} the headers will eventually be + * written to + * @throws IOException when an error occurs writing the request + * @throws HttpException when a HTTP protocol error occurs + * + * @see #writeRequestHeaders + */ + protected void addRequestHeaders(HttpState state, HttpConnection conn) + throws IOException, HttpException { + LOG.trace("enter EntityEnclosingMethod.addRequestHeaders(HttpState, " + + "HttpConnection)"); + + super.addRequestHeaders(state, conn); + addContentLengthRequestHeader(state, conn); + } + /** * Adds a Content-Length or Transfer-Encoding: Chunked * request header, as long as no Content-Length request header * already exists. @@ -331,7 +359,7 @@ protected void addContentLengthRequestHeader(HttpState state, HttpConnection conn) throws IOException, HttpException { - LOG.trace("enter HttpMethodBase.addContentLengthRequestHeader(" + LOG.trace("enter EntityEnclosingMethod.addContentLengthRequestHeader(" + "HttpState, HttpConnection)"); if ((getRequestHeader("content-length") == null) Index: java/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.19 diff -u -r1.19 MultipartPostMethod.java --- java/org/apache/commons/httpclient/methods/MultipartPostMethod.java 15 Jul 2003 12:40:57 -0000 1.19 +++ java/org/apache/commons/httpclient/methods/MultipartPostMethod.java 25 Jul 2003 09:51:22 -0000 @@ -195,32 +195,87 @@ public Part[] getParts() { return (Part[]) parameters.toArray(new Part[parameters.size()]); } + /** - * Add content type header and set the Expect header - * if it has not already been set, in addition to the "standard" - * set of headers - * + * Adds a Content-Length request header, as long as no + * Content-Length request header already exists. + * + * @param state current state of http requests + * @param conn the connection to use for I/O + * + * @throws IOException when errors occur reading or writing to/from the + * connection + * @throws HttpException when a recoverable error occurs + */ + protected void addContentLengthRequestHeader(HttpState state, + HttpConnection conn) + throws IOException, HttpException { + LOG.trace("enter EntityEnclosingMethod.addContentLengthRequestHeader(" + + "HttpState, HttpConnection)"); + + if (getRequestHeader("Content-Length") == null) { + long len = getRequestContentLength(); + addRequestHeader("Content-Length", String.valueOf(len)); + } + removeRequestHeader("Transfer-Encoding"); + } + + /** + * Adds a Content-Type request header. + * + * @param state current state of http requests + * @param conn the connection to use for I/O + * + * @throws IOException when errors occur reading or writing to/from the + * connection + * @throws HttpException when a recoverable error occurs + */ + protected void addContentTypeRequestHeader(HttpState state, + HttpConnection conn) + throws IOException, HttpException { + LOG.trace("enter EntityEnclosingMethod.addContentTypeRequestHeader(" + + "HttpState, HttpConnection)"); + + if (!parameters.isEmpty()) { + StringBuffer buffer = new StringBuffer(MULTIPART_FORM_CONTENT_TYPE); + if (Part.getBoundary() != null) { + buffer.append("; boundary="); + buffer.append(Part.getBoundary()); + } + setRequestHeader("Content-Type", buffer.toString()); + } + } + + /** + * Populates the request headers map to with additional {@link Header + * headers} to be submitted to the given {@link HttpConnection}. + * + *

+ * This implementation adds tt>Content-Length and Content-Type + * headers, when appropriate. + *

+ * + *

+ * Subclasses may want to override this method to to add additional + * headers, and may choose to invoke this implementation (via + * super) to add the "standard" headers. + *

+ * * @param state the client state * @param conn the {@link HttpConnection} the headers will eventually be * written to - * * @throws IOException when an error occurs writing the request * @throws HttpException when a HTTP protocol error occurs + * + * @see #writeRequestHeaders */ protected void addRequestHeaders(HttpState state, HttpConnection conn) throws IOException, HttpException { LOG.trace("enter MultipartPostMethod.addRequestHeaders(HttpState state, " + "HttpConnection conn)"); super.addRequestHeaders(state, conn); - - if (!parameters.isEmpty()) { - StringBuffer buffer = new StringBuffer(MULTIPART_FORM_CONTENT_TYPE); - if (Part.getBoundary() != null) { - buffer.append("; boundary="); - buffer.append(Part.getBoundary()); - } - setRequestHeader("Content-Type", buffer.toString()); - } + addContentLengthRequestHeader(state, conn); + addContentTypeRequestHeader(state, conn); } /**