using System; using System.Globalization; using System.IO; using System.IO.Compression; using System.Runtime.Serialization; namespace System.Net { /// Provides an HTTP-specific implementation of the class. // Token: 0x02000239 RID: 569 [Serializable] public class HttpWebResponse : WebResponse, IDisposable, ISerializable { // Token: 0x06001443 RID: 5187 RVA: 0x0003FFBC File Offset: 0x0003E1BC internal HttpWebResponse(global::System.Uri uri, string method, WebConnectionData data, CookieContainer container) { this.uri = uri; this.method = method; this.webHeaders = data.Headers; this.version = data.Version; this.statusCode = (HttpStatusCode)data.StatusCode; this.statusDescription = data.StatusDescription; this.stream = data.stream; this.contentLength = -1L; try { string text = this.webHeaders["Content-Length"]; if (string.IsNullOrEmpty(text) || !long.TryParse(text, out this.contentLength)) { this.contentLength = -1L; } } catch (Exception) { this.contentLength = -1L; } if (container != null) { this.cookie_container = container; this.FillCookies(); } string text2 = this.webHeaders["Content-Encoding"]; if (text2 == "gzip" && (data.request.AutomaticDecompression & DecompressionMethods.GZip) != DecompressionMethods.None) { this.stream = new global::System.IO.Compression.GZipStream(this.stream, global::System.IO.Compression.CompressionMode.Decompress); } else if (text2 == "deflate" && (data.request.AutomaticDecompression & DecompressionMethods.Deflate) != DecompressionMethods.None) { this.stream = new global::System.IO.Compression.DeflateStream(this.stream, global::System.IO.Compression.CompressionMode.Decompress); } } /// Initializes a new instance of the class from the specified and instances. /// A that contains the information required to serialize the new . /// A that contains the source of the serialized stream that is associated with the new . // Token: 0x06001444 RID: 5188 RVA: 0x0004013C File Offset: 0x0003E33C [Obsolete("Serialization is obsoleted for this type", false)] protected HttpWebResponse(SerializationInfo serializationInfo, StreamingContext streamingContext) { this.uri = (global::System.Uri)serializationInfo.GetValue("uri", typeof(global::System.Uri)); this.contentLength = serializationInfo.GetInt64("contentLength"); this.contentType = serializationInfo.GetString("contentType"); this.method = serializationInfo.GetString("method"); this.statusDescription = serializationInfo.GetString("statusDescription"); this.cookieCollection = (CookieCollection)serializationInfo.GetValue("cookieCollection", typeof(CookieCollection)); this.version = (Version)serializationInfo.GetValue("version", typeof(Version)); this.statusCode = (HttpStatusCode)((int)serializationInfo.GetValue("statusCode", typeof(HttpStatusCode))); } /// Serializes this instance into the specified object. /// The object into which this will be serialized. /// The destination of the serialization. // Token: 0x06001445 RID: 5189 RVA: 0x0004023C File Offset: 0x0003E43C void ISerializable.GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext) { this.GetObjectData(serializationInfo, streamingContext); } /// Releases all resources used by the . // Token: 0x06001446 RID: 5190 RVA: 0x00040248 File Offset: 0x0003E448 void IDisposable.Dispose() { this.Dispose(true); GC.SuppressFinalize(this); } /// Gets the character set of the response. /// A string that contains the character set of the response. /// The current instance has been disposed. /// /// /// // Token: 0x170006A6 RID: 1702 // (get) Token: 0x06001447 RID: 5191 RVA: 0x00040258 File Offset: 0x0003E458 public string CharacterSet { get { string text = this.ContentType; if (text == null) { return "ISO-8859-1"; } string text2 = text.ToLower(); int num = text2.IndexOf("charset="); if (num == -1) { return "ISO-8859-1"; } num += 8; int num2 = text2.IndexOf(';', num); return (num2 != -1) ? text.Substring(num, num2 - num) : text.Substring(num); } } /// Gets the method that is used to encode the body of the response. /// A string that describes the method that is used to encode the body of the response. /// The current instance has been disposed. // Token: 0x170006A7 RID: 1703 // (get) Token: 0x06001448 RID: 5192 RVA: 0x000402C4 File Offset: 0x0003E4C4 public string ContentEncoding { get { this.CheckDisposed(); string text = this.webHeaders["Content-Encoding"]; return (text == null) ? string.Empty : text; } } /// Gets the length of the content returned by the request. /// The number of bytes returned by the request. Content length does not include header information. /// The current instance has been disposed. // Token: 0x170006A8 RID: 1704 // (get) Token: 0x06001449 RID: 5193 RVA: 0x000402FC File Offset: 0x0003E4FC public override long ContentLength { get { return this.contentLength; } } /// Gets the content type of the response. /// A string that contains the content type of the response. /// The current instance has been disposed. // Token: 0x170006A9 RID: 1705 // (get) Token: 0x0600144A RID: 5194 RVA: 0x00040304 File Offset: 0x0003E504 public override string ContentType { get { this.CheckDisposed(); if (this.contentType == null) { this.contentType = this.webHeaders["Content-Type"]; } return this.contentType; } } /// Gets or sets the cookies that are associated with this response. /// A that contains the cookies that are associated with this response. /// The current instance has been disposed. // Token: 0x170006AA RID: 1706 // (get) Token: 0x0600144B RID: 5195 RVA: 0x00040334 File Offset: 0x0003E534 // (set) Token: 0x0600144C RID: 5196 RVA: 0x00040364 File Offset: 0x0003E564 public CookieCollection Cookies { get { this.CheckDisposed(); if (this.cookieCollection == null) { this.cookieCollection = new CookieCollection(); } return this.cookieCollection; } set { this.CheckDisposed(); this.cookieCollection = value; } } /// Gets the headers that are associated with this response from the server. /// A that contains the header information returned with the response. /// The current instance has been disposed. // Token: 0x170006AB RID: 1707 // (get) Token: 0x0600144D RID: 5197 RVA: 0x00040374 File Offset: 0x0003E574 public override WebHeaderCollection Headers { get { return this.webHeaders; } } // Token: 0x0600144E RID: 5198 RVA: 0x0004037C File Offset: 0x0003E57C private static Exception GetMustImplement() { return new NotImplementedException(); } /// Gets a value that indicates whether both client and server were authenticated. /// true if mutual authentication occurred; otherwise, false. // Token: 0x170006AC RID: 1708 // (get) Token: 0x0600144F RID: 5199 RVA: 0x00040384 File Offset: 0x0003E584 [global::System.MonoTODO] public override bool IsMutuallyAuthenticated { get { throw HttpWebResponse.GetMustImplement(); } } /// Gets the last date and time that the contents of the response were modified. /// A that contains the date and time that the contents of the response were modified. /// The current instance has been disposed. /// /// /// // Token: 0x170006AD RID: 1709 // (get) Token: 0x06001450 RID: 5200 RVA: 0x0004038C File Offset: 0x0003E58C public DateTime LastModified { get { this.CheckDisposed(); DateTime dateTime; try { string text = this.webHeaders["Last-Modified"]; dateTime = MonoHttpDate.Parse(text); } catch (Exception) { dateTime = DateTime.Now; } return dateTime; } } /// Gets the method that is used to return the response. /// A string that contains the HTTP method that is used to return the response. /// The current instance has been disposed. // Token: 0x170006AE RID: 1710 // (get) Token: 0x06001451 RID: 5201 RVA: 0x000403F0 File Offset: 0x0003E5F0 public string Method { get { this.CheckDisposed(); return this.method; } } /// Gets the version of the HTTP protocol that is used in the response. /// A that contains the HTTP protocol version of the response. /// The current instance has been disposed. // Token: 0x170006AF RID: 1711 // (get) Token: 0x06001452 RID: 5202 RVA: 0x00040400 File Offset: 0x0003E600 public Version ProtocolVersion { get { this.CheckDisposed(); return this.version; } } /// Gets the URI of the Internet resource that responded to the request. /// A that contains the URI of the Internet resource that responded to the request. /// The current instance has been disposed. // Token: 0x170006B0 RID: 1712 // (get) Token: 0x06001453 RID: 5203 RVA: 0x00040410 File Offset: 0x0003E610 public override global::System.Uri ResponseUri { get { this.CheckDisposed(); return this.uri; } } /// Gets the name of the server that sent the response. /// A string that contains the name of the server that sent the response. /// The current instance has been disposed. // Token: 0x170006B1 RID: 1713 // (get) Token: 0x06001454 RID: 5204 RVA: 0x00040420 File Offset: 0x0003E620 public string Server { get { this.CheckDisposed(); return this.webHeaders["Server"]; } } /// Gets the status of the response. /// One of the values. /// The current instance has been disposed. // Token: 0x170006B2 RID: 1714 // (get) Token: 0x06001455 RID: 5205 RVA: 0x00040438 File Offset: 0x0003E638 public HttpStatusCode StatusCode { get { return this.statusCode; } } /// Gets the status description returned with the response. /// A string that describes the status of the response. /// The current instance has been disposed. // Token: 0x170006B3 RID: 1715 // (get) Token: 0x06001456 RID: 5206 RVA: 0x00040440 File Offset: 0x0003E640 public string StatusDescription { get { this.CheckDisposed(); return this.statusDescription; } } /// Gets the contents of a header that was returned with the response. /// The contents of the specified header. /// The header value to return. /// The current instance has been disposed. // Token: 0x06001457 RID: 5207 RVA: 0x00040450 File Offset: 0x0003E650 public string GetResponseHeader(string headerName) { this.CheckDisposed(); string text = this.webHeaders[headerName]; return (text == null) ? string.Empty : text; } // Token: 0x06001458 RID: 5208 RVA: 0x00040484 File Offset: 0x0003E684 internal void ReadAll() { WebConnectionStream webConnectionStream = this.stream as WebConnectionStream; if (webConnectionStream == null) { return; } try { webConnectionStream.ReadAll(); } catch { } } /// Gets the stream that is used to read the body of the response from the server. /// A containing the body of the response. /// There is no response stream. /// The current instance has been disposed. /// /// /// /// /// // Token: 0x06001459 RID: 5209 RVA: 0x000404D4 File Offset: 0x0003E6D4 public override Stream GetResponseStream() { this.CheckDisposed(); if (this.stream == null) { return Stream.Null; } if (string.Compare(this.method, "HEAD", true) == 0) { return Stream.Null; } return this.stream; } /// Populates a with the data needed to serialize the target object. /// The to populate with data. /// A that specifies the destination for this serialization. // Token: 0x0600145A RID: 5210 RVA: 0x00040510 File Offset: 0x0003E710 protected override void GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext) { serializationInfo.AddValue("uri", this.uri); serializationInfo.AddValue("contentLength", this.contentLength); serializationInfo.AddValue("contentType", this.contentType); serializationInfo.AddValue("method", this.method); serializationInfo.AddValue("statusDescription", this.statusDescription); serializationInfo.AddValue("cookieCollection", this.cookieCollection); serializationInfo.AddValue("version", this.version); serializationInfo.AddValue("statusCode", this.statusCode); } /// Closes the response stream. /// /// /// /// /// // Token: 0x0600145B RID: 5211 RVA: 0x000405AC File Offset: 0x0003E7AC public override void Close() { ((IDisposable)this).Dispose(); } /// Releases the unmanaged resources used by the , and optionally disposes of the managed resources. /// true to release both managed and unmanaged resources; false to releases only unmanaged resources. // Token: 0x0600145C RID: 5212 RVA: 0x000405B4 File Offset: 0x0003E7B4 private void Dispose(bool disposing) { if (this.disposed) { return; } this.disposed = true; if (disposing) { this.uri = null; this.cookieCollection = null; this.method = null; this.version = null; this.statusDescription = null; } Stream stream = this.stream; this.stream = null; if (stream != null) { stream.Close(); } } // Token: 0x0600145D RID: 5213 RVA: 0x00040618 File Offset: 0x0003E818 private void CheckDisposed() { if (this.disposed) { throw new ObjectDisposedException(base.GetType().FullName); } } // Token: 0x0600145E RID: 5214 RVA: 0x00040638 File Offset: 0x0003E838 private void FillCookies() { if (this.webHeaders == null) { return; } string[] array = this.webHeaders.GetValues("Set-Cookie"); if (array != null) { foreach (string text in array) { this.SetCookie(text); } } array = this.webHeaders.GetValues("Set-Cookie2"); if (array != null) { foreach (string text2 in array) { this.SetCookie2(text2); } } } // Token: 0x0600145F RID: 5215 RVA: 0x000406CC File Offset: 0x0003E8CC private void SetCookie(string header) { Cookie cookie = null; CookieParser cookieParser = new CookieParser(header); string text; string text2; while (cookieParser.GetNextNameValue(out text, out text2)) { if ((text != null && !(text == string.Empty)) || cookie != null) { if (cookie == null) { cookie = new Cookie(text, text2); } else { text = text.ToUpper(); string text3 = text; switch (text3) { case "COMMENT": if (cookie.Comment == null) { cookie.Comment = text2; } break; case "COMMENTURL": if (cookie.CommentUri == null) { cookie.CommentUri = new global::System.Uri(text2); } break; case "DISCARD": cookie.Discard = true; break; case "DOMAIN": if (cookie.Domain == string.Empty) { cookie.Domain = text2; } break; case "HTTPONLY": cookie.HttpOnly = true; break; case "MAX-AGE": if (cookie.Expires == DateTime.MinValue) { try { cookie.Expires = cookie.TimeStamp.AddSeconds(uint.Parse(text2)); } catch { } } break; case "EXPIRES": if (!(cookie.Expires != DateTime.MinValue)) { cookie.Expires = this.TryParseCookieExpires(text2); } break; case "PATH": cookie.Path = text2; break; case "PORT": if (cookie.Port == null) { cookie.Port = text2; } break; case "SECURE": cookie.Secure = true; break; case "VERSION": try { cookie.Version = (int)uint.Parse(text2); } catch { } break; } } } } if (cookie == null) { return; } if (this.cookieCollection == null) { this.cookieCollection = new CookieCollection(); } if (cookie.Domain == string.Empty) { cookie.Domain = this.uri.Host; } this.cookieCollection.Add(cookie); if (this.cookie_container != null) { this.cookie_container.Add(this.uri, cookie); } } // Token: 0x06001460 RID: 5216 RVA: 0x000409FC File Offset: 0x0003EBFC private void SetCookie2(string cookies_str) { string[] array = cookies_str.Split(new char[] { ',' }); foreach (string text in array) { this.SetCookie(text); } } // Token: 0x06001461 RID: 5217 RVA: 0x00040A3C File Offset: 0x0003EC3C private DateTime TryParseCookieExpires(string value) { if (value == null || value.Length == 0) { return DateTime.MinValue; } for (int i = 0; i < this.cookieExpiresFormats.Length; i++) { try { DateTime dateTime = DateTime.ParseExact(value, this.cookieExpiresFormats[i], CultureInfo.InvariantCulture); dateTime = DateTime.SpecifyKind(dateTime, DateTimeKind.Utc); return TimeZone.CurrentTimeZone.ToLocalTime(dateTime); } catch { } } return DateTime.MinValue; } // Token: 0x04001158 RID: 4440 private global::System.Uri uri; // Token: 0x04001159 RID: 4441 private WebHeaderCollection webHeaders; // Token: 0x0400115A RID: 4442 private CookieCollection cookieCollection; // Token: 0x0400115B RID: 4443 private string method; // Token: 0x0400115C RID: 4444 private Version version; // Token: 0x0400115D RID: 4445 private HttpStatusCode statusCode; // Token: 0x0400115E RID: 4446 private string statusDescription; // Token: 0x0400115F RID: 4447 private long contentLength; // Token: 0x04001160 RID: 4448 private string contentType; // Token: 0x04001161 RID: 4449 private CookieContainer cookie_container; // Token: 0x04001162 RID: 4450 private bool disposed; // Token: 0x04001163 RID: 4451 private Stream stream; // Token: 0x04001164 RID: 4452 private string[] cookieExpiresFormats = new string[] { "r", "ddd, dd'-'MMM'-'yyyy HH':'mm':'ss 'GMT'", "ddd, dd'-'MMM'-'yy HH':'mm':'ss 'GMT'" }; } }