2 // System.Net.HttpWebResponse
\r
5 // Lawrence Pit (loz@cable.a2000.nl)
\r
10 using System.Runtime.Serialization;
\r
12 namespace System.Net
\r
15 public class HttpWebResponse : WebResponse, ISerializable, IDisposable
\r
18 private WebHeaderCollection webHeaders;
\r
19 private CookieCollection cookieCollection = null;
\r
20 private string method = null;
\r
21 private Version version = null;
\r
22 private HttpStatusCode statusCode;
\r
23 private string statusDescription = null;
\r
25 private Stream responseStream;
\r
26 private bool disposed = false;
\r
30 protected HttpWebResponse (Uri uri, Stream responseStream)
\r
33 this.responseStream = responseStream;
\r
36 protected HttpWebResponse (SerializationInfo serializationInfo, StreamingContext streamingContext)
\r
38 throw new NotSupportedException ();
\r
43 public string CharacterSet {
\r
44 // Content-Type = "Content-Type" ":" media-type
\r
45 // media-type = type "/" subtype *( ";" parameter )
\r
46 // parameter = attribute "=" value
\r
47 // 3.7.1. default is ISO-8859-1
\r
50 string contentType = ContentType;
\r
51 if (contentType == null)
\r
52 return "ISO-8859-1";
\r
53 string val = contentType.ToLower ();
\r
54 int pos = val.IndexOf ("charset=");
\r
56 return "ISO-8859-1";
\r
58 int pos2 = val.IndexOf (';', pos);
\r
60 ? contentType.Substring (pos)
\r
61 : contentType.Substring (pos, pos2 - pos);
\r
65 public string ContentEncoding {
\r
68 return webHeaders ["Content-Encoding"];
\r
72 public override long ContentLength {
\r
76 return Int64.Parse (webHeaders ["Content-Length"]);
\r
77 } catch (Exception) {
\r
83 public override string ContentType {
\r
86 return webHeaders ["Content-Type"];
\r
90 public CookieCollection Cookies {
\r
94 // LAMESPEC: a simple test reveal this always
\r
95 // returns an empty collection. It is not filled
\r
96 // with the values from the Set-Cookie or
\r
97 // Set-Cookie2 response headers, which is a bit
\r
99 if (cookieCollection == null)
\r
100 cookieCollection = new CookieCollection ();
\r
101 return cookieCollection;
\r
105 // ?? don't understand how you can set cookies on a response.
\r
106 throw new NotSupportedException ();
\r
110 public override WebHeaderCollection Headers {
\r
113 return webHeaders;
\r
117 public DateTime LastModified {
\r
121 string dtStr = webHeaders ["Last-Modified"];
\r
122 // TODO: accept more than rfc1123 dates
\r
123 DateTime dt = DateTime.ParseExact (dtStr, "r", null);
\r
125 } catch (Exception) {
\r
126 return DateTime.Now;
\r
131 public string Method {
\r
138 public Version ProtocolVersion {
\r
145 public override Uri ResponseUri {
\r
152 public string Server {
\r
155 return webHeaders ["Server"];
\r
159 public HttpStatusCode StatusCode {
\r
162 return statusCode;
\r
166 public string StatusDescription {
\r
169 return statusDescription;
\r
175 public override int GetHashCode ()
\r
178 return base.GetHashCode ();
\r
181 public string GetResponseHeader (string headerName)
\r
184 return webHeaders [headerName];
\r
188 public override Stream GetResponseStream ()
\r
191 throw new NotImplementedException ();
\r
195 void ISerializable.GetObjectData (SerializationInfo serializationInfo,
\r
196 StreamingContext streamingContext)
\r
199 throw new NotImplementedException ();
\r
203 // Cleaning up stuff
\r
205 ~HttpWebResponse ()
\r
210 public override void Close ()
\r
212 ((IDisposable) this).Dispose ();
\r
215 void IDisposable.Dispose ()
\r
219 // see spec, suppress finalization of this object.
\r
220 GC.SuppressFinalize (this);
\r
223 protected virtual void Dispose (bool disposing)
\r
227 this.disposed = true;
\r
230 // release managed resources
\r
233 cookieCollection = null;
\r
236 // statusCode = null;
\r
237 statusDescription = null;
\r
240 // release unmanaged resources
\r
241 Stream stream = responseStream;
\r
242 responseStream = null;
\r
243 if (stream != null)
\r
247 private void CheckDisposed ()
\r
250 throw new ObjectDisposedException ("HttpWebResponse");
\r