[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit HttpUnitOptions.java,1.8,1.9 WebResponse.
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2001-08-08 19:18:17
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv2695/src/com/meterware/httpunit
Modified Files:
HttpUnitOptions.java WebResponse.java
Log Message:
Added defaultContentType to HttpUnitOptions
Index: HttpUnitOptions.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- HttpUnitOptions.java 2001/07/17 12:50:47 1.8
+++ HttpUnitOptions.java 2001/08/08 19:18:12 1.9
@@ -22,16 +22,33 @@
/**
- * A collection of global options to control testing.
+ * A collection of global options to control HttpUnit's behavior.
*
- * @author Russell Gold
+ * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:dg...@ss...">Dave Glowacki</a>
**/
abstract
public class HttpUnitOptions {
+ /**
+ * Resets all options to their default values.
+ */
+ public static void reset() {
+ _parserWarningsEnabled = false;
+ _exceptionsOnErrorStatus = true;
+ _parameterValuesValidated = true;
+ _imagesTreatedAsAltText = false;
+ _loggingHttpHeaders = false;
+ _matchesIgnoreCase = true;
+ _autoRefresh = false;
+ _redirectDelay = 0;
+ _characterSet = DEFAULT_CHARACTER_SET;
+ _contentType = DEFAULT_CONTENT_TYPE;
+ }
+
/**
- * Resets the default character set to the platform default encoding.
+ * Resets the default character set to the HTTP default encoding.
**/
public static void resetDefaultCharacterSet() {
_characterSet = DEFAULT_CHARACTER_SET;
@@ -39,6 +56,14 @@
/**
+ * Resets the default content type to plain text.
+ **/
+ public static void resetDefaultContentType() {
+ _contentType = DEFAULT_CONTENT_TYPE;
+ }
+
+
+ /**
* Sets the default character set for pages which do not specify one. By default, HttpUnit uses the platform
* default encoding.
**/
@@ -56,6 +81,22 @@
/**
+ * Sets the default content type for pages which do not specify one.
+ **/
+ public static void setDefaultContentType( String contentType ) {
+ _contentType = contentType;
+ }
+
+
+ /**
+ * Returns the content type to be used for pages which do not specify one.
+ **/
+ public static String getDefaultContentType() {
+ return _contentType;
+ }
+
+
+ /**
* Returns true if parser warnings are enabled.
**/
public static boolean getParserWarningsEnabled() {
@@ -196,26 +237,12 @@
}
-//------------------------------ package methods ----------------------------------------
-
-
- static void reset() {
- _parserWarningsEnabled = false;
- _exceptionsOnErrorStatus = true;
- _parameterValuesValidated = true;
- _imagesTreatedAsAltText = false;
- _loggingHttpHeaders = false;
- _matchesIgnoreCase = true;
- _autoRefresh = false;
- _redirectDelay = 0;
- _characterSet = DEFAULT_CHARACTER_SET;
- }
-
-
//--------------------------------- private members --------------------------------------
- private static String DEFAULT_CHARACTER_SET = "iso-8859-1";
+ private static String DEFAULT_CONTENT_TYPE = "text/plain";
+ private static String DEFAULT_CONTENT_HEADER = DEFAULT_CONTENT_TYPE;
+ private static String DEFAULT_CHARACTER_SET = "iso-8859-1";
private static boolean _parserWarningsEnabled;
@@ -235,5 +262,6 @@
private static String _characterSet = DEFAULT_CHARACTER_SET;
+ private static String _contentType = DEFAULT_CONTENT_TYPE;
}
Index: WebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- WebResponse.java 2001/07/31 16:08:59 1.43
+++ WebResponse.java 2001/08/08 19:18:13 1.44
@@ -54,6 +54,7 @@
*
* @author <a href="mailto:rus...@ac...">Russell Gold</a>
* @author <a href="mailto:DRE...@or...">Drew Varner</a>
+ * @author <a href="mailto:dg...@ss...">Dave Glowacki</a>
**/
abstract
public class WebResponse implements HTMLSegment {
@@ -130,10 +131,7 @@
* Returns the content type of this response.
**/
public String getContentType() {
- if (_contentType == null) {
- readContentTypeHeader();
- if (_contentType == null) _contentType = DEFAULT_CONTENT_TYPE;
- }
+ if (_contentType == null) readContentTypeHeader();
return _contentType;
}
@@ -445,9 +443,6 @@
**/
final private static int IETF_RFC2965 = 1;
- final private static String DEFAULT_CONTENT_TYPE = "text/plain";
- final private static String DEFAULT_CONTENT_HEADER = DEFAULT_CONTENT_TYPE;
-
final private static String HTML_CONTENT = "text/html";
private WebFrame[] _frames;
@@ -686,10 +681,15 @@
private void readContentTypeHeader() {
String contentHeader = (_contentHeader != null) ? _contentHeader
: getHeaderField( "Content-type" );
- if (contentHeader == null) contentHeader = DEFAULT_CONTENT_HEADER;
- String[] parts = HttpUnitUtils.parseContentTypeHeader( contentHeader );
- _contentType = parts[0];
- if (parts[1] != null) _characterSet = parts[1];
+ if (contentHeader == null) {
+ _contentType = HttpUnitOptions.getDefaultContentType();
+ _characterSet = HttpUnitOptions.getDefaultCharacterSet();
+ _contentHeader = _contentType + ";charset=" + _characterSet;
+ } else {
+ String[] parts = HttpUnitUtils.parseContentTypeHeader( contentHeader );
+ _contentType = parts[0];
+ if (parts[1] != null) _characterSet = parts[1];
+ }
}
|