[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit HttpWebResponse.java,1.5,1.6
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2001-03-20 23:33:23
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv26791/src/com/meterware/httpunit
Modified Files:
HttpWebResponse.java
Log Message:
Clean up implementation dependancies
Index: HttpWebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpWebResponse.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- HttpWebResponse.java 2001/02/21 19:01:07 1.5
+++ HttpWebResponse.java 2001/03/20 23:35:42 1.6
@@ -48,7 +48,10 @@
HttpWebResponse( String target, URL url, URLConnection connection ) throws IOException {
super( target, url );
readHeaders( connection );
- if (((HttpURLConnection) connection).getResponseCode() == HttpURLConnection.HTTP_OK) loadResponseText( url, connection );
+
+
+ if (_responseCode == HttpURLConnection.HTTP_OK) loadResponseText( url, connection );
+ if (connection instanceof HttpURLConnection) ((HttpURLConnection) connection).disconnect();
}
@@ -115,18 +118,28 @@
}
+ private int getResponseCode( String statusHeader ) {
+ StringTokenizer st = new StringTokenizer( statusHeader );
+ st.nextToken();
+ if (!st.hasMoreTokens()) {
+ return HttpURLConnection.HTTP_OK;
+ } else try {
+ return Integer.parseInt( st.nextToken() );
+ } catch (NumberFormatException e) {
+ return HttpURLConnection.HTTP_INTERNAL_ERROR;
+ }
+ }
+
+
private void readHeaders( URLConnection connection ) {
loadHeaders( connection );
- try {
- if (connection instanceof HttpURLConnection) {
- _responseCode = ((HttpURLConnection) connection).getResponseCode();
- } else {
- _responseCode = HttpURLConnection.HTTP_OK;
- if (getContentType().startsWith( "text" )) {
- _headers.put( "Content-type".toUpperCase(), getContentType() + "; charset=" + _fileEncoding );
- }
+ if (connection instanceof HttpURLConnection) {
+ _responseCode = getResponseCode( connection.getHeaderField(0) );
+ } else {
+ _responseCode = HttpURLConnection.HTTP_OK;
+ if (getContentType().startsWith( "text" )) {
+ _headers.put( "Content-type".toUpperCase(), getContentType() + "; charset=" + _fileEncoding );
}
- } catch (IOException e) {
}
}
|