Return-Path:
- * When a method's request may contain a body, subclasses will typically want
- * to override:
- *
- *
- *
* When a method requires additional request headers, subclasses will typically * want to override: *
- * 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 +1352,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 +1504,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 +1533,6 @@ addAuthorizationRequestHeader(state, conn); addProxyAuthorizationRequestHeader(state, conn); addProxyConnectionHeader(state, conn); - addContentLengthRequestHeader(state, conn); } /** 1.24 +39 -11 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java Index: EntityEnclosingMethod.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- EntityEnclosingMethod.java 17 Jul 2003 21:57:42 -0000 1.23 +++ EntityEnclosingMethod.java 25 Jul 2003 18:29:32 -0000 1.24 @@ -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); } @@ -296,8 +293,7 @@ } /** - * Override method of {@link org.apache.commons.httpclient.HttpMethodBase} - * to return the length of the request body. + * Return the length of the request body. * * @return number of bytes in the request body */ @@ -317,6 +313,38 @@ } /** + * Populates the request headers map to with additional + * {@link org.apache.commons.httpclient.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) 1.20 +73 -17 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/MultipartPostMethod.java Index: MultipartPostMethod.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/MultipartPostMethod.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- MultipartPostMethod.java 15 Jul 2003 12:40:57 -0000 1.19 +++ MultipartPostMethod.java 25 Jul 2003 18:29:32 -0000 1.20 @@ -195,32 +195,88 @@ 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 org.apache.commons.httpclient.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); } /** --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org