Files
2026-06-04 11:42:34 +02:00

648 lines
23 KiB
C#

using System;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Runtime.Serialization;
namespace System.Net
{
/// <summary>Provides an HTTP-specific implementation of the <see cref="T:System.Net.WebResponse" /> class.</summary>
// 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);
}
}
/// <summary>Initializes a new instance of the <see cref="T:System.Net.HttpWebResponse" /> class from the specified <see cref="T:System.Runtime.Serialization.SerializationInfo" /> and <see cref="T:System.Runtime.Serialization.StreamingContext" /> instances.</summary>
/// <param name="serializationInfo">A <see cref="T:System.Runtime.Serialization.SerializationInfo" /> that contains the information required to serialize the new <see cref="T:System.Net.HttpWebRequest" />. </param>
/// <param name="streamingContext">A <see cref="T:System.Runtime.Serialization.StreamingContext" /> that contains the source of the serialized stream that is associated with the new <see cref="T:System.Net.HttpWebRequest" />. </param>
// 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)));
}
/// <summary>Serializes this instance into the specified <see cref="T:System.Runtime.Serialization.SerializationInfo" /> object.</summary>
/// <param name="serializationInfo">The object into which this <see cref="T:System.Net.HttpWebResponse" /> will be serialized. </param>
/// <param name="streamingContext">The destination of the serialization. </param>
// Token: 0x06001445 RID: 5189 RVA: 0x0004023C File Offset: 0x0003E43C
void ISerializable.GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)
{
this.GetObjectData(serializationInfo, streamingContext);
}
/// <summary>Releases all resources used by the <see cref="T:System.Net.HttpWebResponse" />.</summary>
// Token: 0x06001446 RID: 5190 RVA: 0x00040248 File Offset: 0x0003E448
void IDisposable.Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>Gets the character set of the response.</summary>
/// <returns>A string that contains the character set of the response.</returns>
/// <exception cref="T:System.ObjectDisposedException">The current instance has been disposed. </exception>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
/// </PermissionSet>
// 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);
}
}
/// <summary>Gets the method that is used to encode the body of the response.</summary>
/// <returns>A string that describes the method that is used to encode the body of the response.</returns>
/// <exception cref="T:System.ObjectDisposedException">The current instance has been disposed. </exception>
// 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;
}
}
/// <summary>Gets the length of the content returned by the request.</summary>
/// <returns>The number of bytes returned by the request. Content length does not include header information.</returns>
/// <exception cref="T:System.ObjectDisposedException">The current instance has been disposed. </exception>
// Token: 0x170006A8 RID: 1704
// (get) Token: 0x06001449 RID: 5193 RVA: 0x000402FC File Offset: 0x0003E4FC
public override long ContentLength
{
get
{
return this.contentLength;
}
}
/// <summary>Gets the content type of the response.</summary>
/// <returns>A string that contains the content type of the response.</returns>
/// <exception cref="T:System.ObjectDisposedException">The current instance has been disposed. </exception>
// 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;
}
}
/// <summary>Gets or sets the cookies that are associated with this response.</summary>
/// <returns>A <see cref="T:System.Net.CookieCollection" /> that contains the cookies that are associated with this response.</returns>
/// <exception cref="T:System.ObjectDisposedException">The current instance has been disposed. </exception>
// 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;
}
}
/// <summary>Gets the headers that are associated with this response from the server.</summary>
/// <returns>A <see cref="T:System.Net.WebHeaderCollection" /> that contains the header information returned with the response.</returns>
/// <exception cref="T:System.ObjectDisposedException">The current instance has been disposed. </exception>
// 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();
}
/// <summary>Gets a <see cref="T:System.Boolean" /> value that indicates whether both client and server were authenticated.</summary>
/// <returns>true if mutual authentication occurred; otherwise, false.</returns>
// 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();
}
}
/// <summary>Gets the last date and time that the contents of the response were modified.</summary>
/// <returns>A <see cref="T:System.DateTime" /> that contains the date and time that the contents of the response were modified.</returns>
/// <exception cref="T:System.ObjectDisposedException">The current instance has been disposed. </exception>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
/// </PermissionSet>
// 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;
}
}
/// <summary>Gets the method that is used to return the response.</summary>
/// <returns>A string that contains the HTTP method that is used to return the response.</returns>
/// <exception cref="T:System.ObjectDisposedException">The current instance has been disposed. </exception>
// Token: 0x170006AE RID: 1710
// (get) Token: 0x06001451 RID: 5201 RVA: 0x000403F0 File Offset: 0x0003E5F0
public string Method
{
get
{
this.CheckDisposed();
return this.method;
}
}
/// <summary>Gets the version of the HTTP protocol that is used in the response.</summary>
/// <returns>A <see cref="T:System.Version" /> that contains the HTTP protocol version of the response.</returns>
/// <exception cref="T:System.ObjectDisposedException">The current instance has been disposed. </exception>
// Token: 0x170006AF RID: 1711
// (get) Token: 0x06001452 RID: 5202 RVA: 0x00040400 File Offset: 0x0003E600
public Version ProtocolVersion
{
get
{
this.CheckDisposed();
return this.version;
}
}
/// <summary>Gets the URI of the Internet resource that responded to the request.</summary>
/// <returns>A <see cref="T:System.Uri" /> that contains the URI of the Internet resource that responded to the request.</returns>
/// <exception cref="T:System.ObjectDisposedException">The current instance has been disposed. </exception>
// 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;
}
}
/// <summary>Gets the name of the server that sent the response.</summary>
/// <returns>A string that contains the name of the server that sent the response.</returns>
/// <exception cref="T:System.ObjectDisposedException">The current instance has been disposed. </exception>
// Token: 0x170006B1 RID: 1713
// (get) Token: 0x06001454 RID: 5204 RVA: 0x00040420 File Offset: 0x0003E620
public string Server
{
get
{
this.CheckDisposed();
return this.webHeaders["Server"];
}
}
/// <summary>Gets the status of the response.</summary>
/// <returns>One of the <see cref="T:System.Net.HttpStatusCode" /> values.</returns>
/// <exception cref="T:System.ObjectDisposedException">The current instance has been disposed. </exception>
// Token: 0x170006B2 RID: 1714
// (get) Token: 0x06001455 RID: 5205 RVA: 0x00040438 File Offset: 0x0003E638
public HttpStatusCode StatusCode
{
get
{
return this.statusCode;
}
}
/// <summary>Gets the status description returned with the response.</summary>
/// <returns>A string that describes the status of the response.</returns>
/// <exception cref="T:System.ObjectDisposedException">The current instance has been disposed. </exception>
// Token: 0x170006B3 RID: 1715
// (get) Token: 0x06001456 RID: 5206 RVA: 0x00040440 File Offset: 0x0003E640
public string StatusDescription
{
get
{
this.CheckDisposed();
return this.statusDescription;
}
}
/// <summary>Gets the contents of a header that was returned with the response.</summary>
/// <returns>The contents of the specified header.</returns>
/// <param name="headerName">The header value to return. </param>
/// <exception cref="T:System.ObjectDisposedException">The current instance has been disposed. </exception>
// 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
{
}
}
/// <summary>Gets the stream that is used to read the body of the response from the server.</summary>
/// <returns>A <see cref="T:System.IO.Stream" /> containing the body of the response.</returns>
/// <exception cref="T:System.Net.ProtocolViolationException">There is no response stream. </exception>
/// <exception cref="T:System.ObjectDisposedException">The current instance has been disposed. </exception>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
/// </PermissionSet>
// 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;
}
/// <summary>Populates a <see cref="T:System.Runtime.Serialization.SerializationInfo" /> with the data needed to serialize the target object.</summary>
/// <param name="serializationInfo">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> to populate with data. </param>
/// <param name="streamingContext">A <see cref="T:System.Runtime.Serialization.StreamingContext" /> that specifies the destination for this serialization.</param>
// 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);
}
/// <summary>Closes the response stream.</summary>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
/// </PermissionSet>
// Token: 0x0600145B RID: 5211 RVA: 0x000405AC File Offset: 0x0003E7AC
public override void Close()
{
((IDisposable)this).Dispose();
}
/// <summary>Releases the unmanaged resources used by the <see cref="T:System.Net.HttpWebResponse" />, and optionally disposes of the managed resources.</summary>
/// <param name="disposing">true to release both managed and unmanaged resources; false to releases only unmanaged resources. </param>
// 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'" };
}
}