rwaldhoff 01/08/17 12:19:11
Modified: httpclient/src/java/org/apache/commons/httpclient Tag:
rlwrefactoring HttpClient.java HttpMethodBase.java
httpclient/src/java/org/apache/commons/httpclient/methods
Tag: rlwrefactoring PutMethod.java
Log:
Removing final dependency between HttpClient and HttpMethodBase by pushing user
agent header down to HttpMethodBase
Removing instance variable dependencies between HttpMethodBase and children by:
* adding protected http11 setter and getter
* making all HttpMethodBase instance variables private
* converting PutMethod to use method calls in a couple of places in which it was
access HttpMethodBase attributes directly
Revision Changes Path
No revision
No revision
1.31.2.6 +3 -9
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java
Index: HttpClient.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v
retrieving revision 1.31.2.5
retrieving revision 1.31.2.6
diff -u -r1.31.2.5 -r1.31.2.6
--- HttpClient.java 2001/08/16 23:56:13 1.31.2.5
+++ HttpClient.java 2001/08/17 19:19:10 1.31.2.6
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v
1.31.2.5 2001/08/16 23:56:13 rwaldhoff Exp $
- * $Revision: 1.31.2.5 $
- * $Date: 2001/08/16 23:56:13 $
+ * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v
1.31.2.6 2001/08/17 19:19:10 rwaldhoff Exp $
+ * $Revision: 1.31.2.6 $
+ * $Date: 2001/08/17 19:19:10 $
*
* ====================================================================
*
@@ -50,12 +50,6 @@
/** <tt>org.apache.commons.httpclient.HttpClient</tt> log. */
static private final Log log =
LogSource.getInstance("org.apache.commons.httpclient.HttpClient");
-
- /**
- * User Agent header.
- */
- public static final Header USER_AGENT =
- new Header("User-Agent", "Jakarta HTTP Client/1.0");
// ----------------------------------------------------------- Constructors
1.10.2.20 +34 -17
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java
Index: HttpMethodBase.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
retrieving revision 1.10.2.19
retrieving revision 1.10.2.20
diff -u -r1.10.2.19 -r1.10.2.20
--- HttpMethodBase.java 2001/08/16 23:59:14 1.10.2.19
+++ HttpMethodBase.java 2001/08/17 19:19:10 1.10.2.20
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
1.10.2.19 2001/08/16 23:59:14 rwaldhoff Exp $
- * $Revision: 1.10.2.19 $
- * $Date: 2001/08/16 23:59:14 $
+ * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
1.10.2.20 2001/08/17 19:19:10 rwaldhoff Exp $
+ * $Revision: 1.10.2.20 $
+ * $Date: 2001/08/17 19:19:10 $
* ====================================================================
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -62,7 +62,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a>
* @author Rodney Waldhoff
- * @version $Id: HttpMethodBase.java,v 1.10.2.19 2001/08/16 23:59:14 rwaldhoff Exp $
+ * @version $Id: HttpMethodBase.java,v 1.10.2.20 2001/08/17 19:19:10 rwaldhoff Exp $
*/
public abstract class HttpMethodBase implements HttpMethod {
@@ -643,7 +643,7 @@
// add default user agent
if (!requestHeaders.containsKey("user-agent")) {
- setRequestHeader(HttpClient.USER_AGENT);
+ setRequestHeader(HttpMethodBase.USER_AGENT);
}
// add host (should do this conditionally?, i.e., don't send to http/1.0?)
@@ -907,7 +907,7 @@
if(setCookieHeader != null) {
try {
- Cookie[] cookies = Cookie.parse(conn.getHost(), setCookieHeader);
+ Cookie[] cookies = Cookie.parse(conn.getHost(), getPath(),
conn.isSecure(), setCookieHeader);
state.addCookies(cookies);
} catch (Exception e) {
log.error("processResponseHeaders(State,HttpConnection)",e);
@@ -1021,6 +1021,14 @@
// ---------------------------------------------- Protected Utility Methods
+ protected boolean isHttp11() {
+ return http11;
+ }
+
+ protected void setHttp11(boolean http11) {
+ this.http11 = http11;
+ }
+
/**
* Throws an {@link IllegalStateException} if
* {@link #used}.
@@ -1082,18 +1090,27 @@
}
// ----------------------------------------------------- Instance Variables
+
+ private String path = null;
+ private boolean followRedirects = false;
+ private String queryString = null;
+ private HashMap requestHeaders = new HashMap();
+ private HashMap responseHeaders = new HashMap();
+ private int statusCode = -1;
+ private String statusText = null;
+ private boolean used = false;
+ private boolean http11 = true;
+ private boolean bodySent = false;
+ private byte[] responseBody = null;
- protected String path = null;
- protected boolean followRedirects = false;
- protected String queryString = null;
- protected HashMap requestHeaders = new HashMap();
- protected HashMap responseHeaders = new HashMap();
- protected int statusCode = -1;
- protected String statusText = null;
- protected boolean used = false;
- protected boolean http11 = true;
- protected boolean bodySent = false;
- protected byte[] responseBody = null;
+
+ // -------------------------------------------------------------- Constants
+
+ /**
+ * User Agent header.
+ */
+ public static final Header USER_AGENT =
+ new Header("User-Agent", "Jakarta HTTP Client/1.0");
}
No revision
No revision
1.3.2.10 +6 -6
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PutMethod.java
Index: PutMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PutMethod.java,v
retrieving revision 1.3.2.9
retrieving revision 1.3.2.10
diff -u -r1.3.2.9 -r1.3.2.10
--- PutMethod.java 2001/08/16 23:55:27 1.3.2.9
+++ PutMethod.java 2001/08/17 19:19:11 1.3.2.10
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PutMethod.java,v
1.3.2.9 2001/08/16 23:55:27 rwaldhoff Exp $
- * $Revision: 1.3.2.9 $
- * $Date: 2001/08/16 23:55:27 $
+ * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PutMethod.java,v
1.3.2.10 2001/08/17 19:19:11 rwaldhoff Exp $
+ * $Revision: 1.3.2.10 $
+ * $Date: 2001/08/17 19:19:11 $
*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
@@ -197,7 +197,7 @@
protected void generateRequestHeaders(State state, HttpConnection conn) throws
IOException, HttpException {
super.generateRequestHeaders(state,conn);
// Send expectation header
- if(http11 && !requestHeaders.containsKey("expect")) {
+ if(isHttp11() && null == getRequestHeader("expect")) {
setRequestHeader("Expect","100-continue");
}
}
@@ -209,11 +209,11 @@
* read.
*/
protected boolean writeRequestBody(State state, HttpConnection conn) throws
IOException, HttpException {
- if(requestHeaders.containsKey("expect") && statusCode !=
HttpStatus.SC_CONTINUE) {
+ if(null != getRequestHeader("expect") && getStatusCode() !=
HttpStatus.SC_CONTINUE) {
return false;
}
RequestOutputStream out = conn.getRequestOutputStream();
- if((http11) && (getRequestHeader("Content-Length") == null)) {
+ if(isHttp11() && (null == getRequestHeader("Content-Length"))) {
out.setUseChunking(true);
}