Files
Dec2017-Script-Dump/System/Net/FileWebRequest.cs
T
2026-06-04 11:42:34 +02:00

537 lines
22 KiB
C#

using System;
using System.IO;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Serialization;
using System.Threading;
namespace System.Net
{
/// <summary>Provides a file system implementation of the <see cref="T:System.Net.WebRequest" /> class.</summary>
// Token: 0x02000219 RID: 537
[Serializable]
public class FileWebRequest : WebRequest, ISerializable
{
// Token: 0x06001243 RID: 4675 RVA: 0x000372C4 File Offset: 0x000354C4
internal FileWebRequest(global::System.Uri uri)
{
this.uri = uri;
this.webHeaders = new WebHeaderCollection();
}
/// <summary>Initializes a new instance of the <see cref="T:System.Net.FileWebRequest" /> class from the specified instances of the <see cref="T:System.Runtime.Serialization.SerializationInfo" /> and <see cref="T:System.Runtime.Serialization.StreamingContext" /> classes.</summary>
/// <param name="serializationInfo">A <see cref="T:System.Runtime.Serialization.SerializationInfo" /> object that contains the information that is required to serialize the new <see cref="T:System.Net.FileWebRequest" /> object. </param>
/// <param name="streamingContext">A <see cref="T:System.Runtime.Serialization.StreamingContext" /> object that contains the source of the serialized stream that is associated with the new <see cref="T:System.Net.FileWebRequest" /> object. </param>
// Token: 0x06001244 RID: 4676 RVA: 0x000372FC File Offset: 0x000354FC
[Obsolete("Serialization is obsoleted for this type", false)]
protected FileWebRequest(SerializationInfo serializationInfo, StreamingContext streamingContext)
{
this.webHeaders = (WebHeaderCollection)serializationInfo.GetValue("headers", typeof(WebHeaderCollection));
this.proxy = (IWebProxy)serializationInfo.GetValue("proxy", typeof(IWebProxy));
this.uri = (global::System.Uri)serializationInfo.GetValue("uri", typeof(global::System.Uri));
this.connectionGroup = serializationInfo.GetString("connectionGroupName");
this.method = serializationInfo.GetString("method");
this.contentLength = serializationInfo.GetInt64("contentLength");
this.timeout = serializationInfo.GetInt32("timeout");
this.fileAccess = (FileAccess)((int)serializationInfo.GetValue("fileAccess", typeof(FileAccess)));
this.preAuthenticate = serializationInfo.GetBoolean("preauthenticate");
}
/// <summary>Populates a <see cref="T:System.Runtime.Serialization.SerializationInfo" /> object with the required data to serialize the <see cref="T:System.Net.FileWebRequest" />.</summary>
/// <param name="serializationInfo">A <see cref="T:System.Runtime.Serialization.SerializationInfo" /> that holds the serialized data for the <see cref="T:System.Net.FileWebRequest" />. </param>
/// <param name="streamingContext">A <see cref="T:System.Runtime.Serialization.StreamingContext" /> that contains the destination of the serialized stream that is associated with the new <see cref="T:System.Net.FileWebRequest" />. </param>
// Token: 0x06001245 RID: 4677 RVA: 0x00037404 File Offset: 0x00035604
void ISerializable.GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)
{
this.GetObjectData(serializationInfo, streamingContext);
}
/// <summary>Gets or sets the name of the connection group for the request. This property is reserved for future use.</summary>
/// <returns>The name of the connection group for the request.</returns>
// Token: 0x170005F0 RID: 1520
// (get) Token: 0x06001246 RID: 4678 RVA: 0x00037410 File Offset: 0x00035610
// (set) Token: 0x06001247 RID: 4679 RVA: 0x00037418 File Offset: 0x00035618
public override string ConnectionGroupName
{
get
{
return this.connectionGroup;
}
set
{
this.connectionGroup = value;
}
}
/// <summary>Gets or sets the content length of the data being sent.</summary>
/// <returns>The number of bytes of request data being sent.</returns>
/// <exception cref="T:System.ArgumentException">
/// <see cref="P:System.Net.FileWebRequest.ContentLength" /> is less than 0. </exception>
// Token: 0x170005F1 RID: 1521
// (get) Token: 0x06001248 RID: 4680 RVA: 0x00037424 File Offset: 0x00035624
// (set) Token: 0x06001249 RID: 4681 RVA: 0x0003742C File Offset: 0x0003562C
public override long ContentLength
{
get
{
return this.contentLength;
}
set
{
if (value < 0L)
{
throw new ArgumentException("The Content-Length value must be greater than or equal to zero.", "value");
}
this.contentLength = value;
}
}
/// <summary>Gets or sets the content type of the data being sent. This property is reserved for future use.</summary>
/// <returns>The content type of the data being sent.</returns>
// Token: 0x170005F2 RID: 1522
// (get) Token: 0x0600124A RID: 4682 RVA: 0x00037450 File Offset: 0x00035650
// (set) Token: 0x0600124B RID: 4683 RVA: 0x00037464 File Offset: 0x00035664
public override string ContentType
{
get
{
return this.webHeaders["Content-Type"];
}
set
{
this.webHeaders["Content-Type"] = value;
}
}
/// <summary>Gets or sets the credentials that are associated with this request. This property is reserved for future use.</summary>
/// <returns>An <see cref="T:System.Net.ICredentials" /> that contains the authentication credentials that are associated with this request. The default is null.</returns>
// Token: 0x170005F3 RID: 1523
// (get) Token: 0x0600124C RID: 4684 RVA: 0x00037478 File Offset: 0x00035678
// (set) Token: 0x0600124D RID: 4685 RVA: 0x00037480 File Offset: 0x00035680
public override ICredentials Credentials
{
get
{
return this.credentials;
}
set
{
this.credentials = value;
}
}
/// <summary>Gets a collection of the name/value pairs that are associated with the request. This property is reserved for future use.</summary>
/// <returns>A <see cref="T:System.Net.WebHeaderCollection" /> that contains header name/value pairs associated with this request.</returns>
// Token: 0x170005F4 RID: 1524
// (get) Token: 0x0600124E RID: 4686 RVA: 0x0003748C File Offset: 0x0003568C
public override WebHeaderCollection Headers
{
get
{
return this.webHeaders;
}
}
/// <summary>Gets or sets the protocol method used for the request. This property is reserved for future use.</summary>
/// <returns>The protocol method to use in this request.</returns>
// Token: 0x170005F5 RID: 1525
// (get) Token: 0x0600124F RID: 4687 RVA: 0x00037494 File Offset: 0x00035694
// (set) Token: 0x06001250 RID: 4688 RVA: 0x0003749C File Offset: 0x0003569C
public override string Method
{
get
{
return this.method;
}
set
{
if (value == null || value.Length == 0)
{
throw new ArgumentException("Cannot set null or blank methods on request.", "value");
}
this.method = value;
}
}
/// <summary>Gets or sets a value that indicates whether to preauthenticate a request. This property is reserved for future use.</summary>
/// <returns>true to preauthenticate; otherwise, false.</returns>
// Token: 0x170005F6 RID: 1526
// (get) Token: 0x06001251 RID: 4689 RVA: 0x000374D4 File Offset: 0x000356D4
// (set) Token: 0x06001252 RID: 4690 RVA: 0x000374DC File Offset: 0x000356DC
public override bool PreAuthenticate
{
get
{
return this.preAuthenticate;
}
set
{
this.preAuthenticate = value;
}
}
/// <summary>Gets or sets the network proxy to use for this request. This property is reserved for future use.</summary>
/// <returns>An <see cref="T:System.Net.IWebProxy" /> that indicates the network proxy to use for this request.</returns>
// Token: 0x170005F7 RID: 1527
// (get) Token: 0x06001253 RID: 4691 RVA: 0x000374E8 File Offset: 0x000356E8
// (set) Token: 0x06001254 RID: 4692 RVA: 0x000374F0 File Offset: 0x000356F0
public override IWebProxy Proxy
{
get
{
return this.proxy;
}
set
{
this.proxy = value;
}
}
/// <summary>Gets the Uniform Resource Identifier (URI) of the request.</summary>
/// <returns>A <see cref="T:System.Uri" /> that contains the URI of the request.</returns>
// Token: 0x170005F8 RID: 1528
// (get) Token: 0x06001255 RID: 4693 RVA: 0x000374FC File Offset: 0x000356FC
public override global::System.Uri RequestUri
{
get
{
return this.uri;
}
}
/// <summary>Gets or sets the length of time until the request times out.</summary>
/// <returns>The time, in milliseconds, until the request times out, or the value <see cref="F:System.Threading.Timeout.Infinite" /> to indicate that the request does not time out.</returns>
/// <exception cref="T:System.ArgumentOutOfRangeException">The value specified is less than or equal to zero and is not <see cref="F:System.Threading.Timeout.Infinite" />.</exception>
// Token: 0x170005F9 RID: 1529
// (get) Token: 0x06001256 RID: 4694 RVA: 0x00037504 File Offset: 0x00035704
// (set) Token: 0x06001257 RID: 4695 RVA: 0x0003750C File Offset: 0x0003570C
public override int Timeout
{
get
{
return this.timeout;
}
set
{
if (value < -1)
{
throw new ArgumentOutOfRangeException("Timeout can be only set to 'System.Threading.Timeout.Infinite' or a value >= 0.");
}
this.timeout = value;
}
}
/// <summary>Always throws a <see cref="T:System.NotSupportedException" />.</summary>
/// <returns>Always throws a <see cref="T:System.NotSupportedException" />.</returns>
/// <exception cref="T:System.NotSupportedException">Default credentials are not supported for file Uniform Resource Identifiers (URIs).</exception>
// Token: 0x170005FA RID: 1530
// (get) Token: 0x06001258 RID: 4696 RVA: 0x00037528 File Offset: 0x00035728
// (set) Token: 0x06001259 RID: 4697 RVA: 0x00037530 File Offset: 0x00035730
public override bool UseDefaultCredentials
{
get
{
throw new NotSupportedException();
}
set
{
throw new NotSupportedException();
}
}
// Token: 0x0600125A RID: 4698 RVA: 0x00037538 File Offset: 0x00035738
private static Exception GetMustImplement()
{
return new NotImplementedException();
}
/// <summary>Cancels a request to an Internet resource.</summary>
// Token: 0x0600125B RID: 4699 RVA: 0x00037540 File Offset: 0x00035740
[global::System.MonoTODO]
public override void Abort()
{
throw FileWebRequest.GetMustImplement();
}
/// <summary>Begins an asynchronous request for a <see cref="T:System.IO.Stream" /> object to use to write data.</summary>
/// <returns>An <see cref="T:System.IAsyncResult" /> that references the asynchronous request.</returns>
/// <param name="callback">The <see cref="T:System.AsyncCallback" /> delegate. </param>
/// <param name="state">An object that contains state information for this request. </param>
/// <exception cref="T:System.Net.ProtocolViolationException">The <see cref="P:System.Net.FileWebRequest.Method" /> property is GET and the application writes to the stream. </exception>
/// <exception cref="T:System.InvalidOperationException">The stream is being used by a previous call to <see cref="M:System.Net.FileWebRequest.BeginGetRequestStream(System.AsyncCallback,System.Object)" />. </exception>
/// <exception cref="T:System.ApplicationException">No write stream is available. </exception>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// </PermissionSet>
// Token: 0x0600125C RID: 4700 RVA: 0x00037548 File Offset: 0x00035748
public override IAsyncResult BeginGetRequestStream(AsyncCallback callback, object state)
{
if (string.Compare("GET", this.method, true) == 0 || string.Compare("HEAD", this.method, true) == 0 || string.Compare("CONNECT", this.method, true) == 0)
{
throw new ProtocolViolationException("Cannot send a content-body with this verb-type.");
}
lock (this)
{
if (this.asyncResponding || this.webResponse != null)
{
throw new InvalidOperationException("This operation cannot be performed after the request has been submitted.");
}
if (this.requesting)
{
throw new InvalidOperationException("Cannot re-call start of asynchronous method while a previous call is still in progress.");
}
this.requesting = true;
}
FileWebRequest.GetRequestStreamCallback getRequestStreamCallback = new FileWebRequest.GetRequestStreamCallback(this.GetRequestStreamInternal);
return getRequestStreamCallback.BeginInvoke(callback, state);
}
/// <summary>Ends an asynchronous request for a <see cref="T:System.IO.Stream" /> instance that the application uses to write data.</summary>
/// <returns>A <see cref="T:System.IO.Stream" /> object that the application uses to write data.</returns>
/// <param name="asyncResult">An <see cref="T:System.IAsyncResult" /> that references the pending request for a stream. </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="asyncResult" /> is null. </exception>
// Token: 0x0600125D RID: 4701 RVA: 0x00037628 File Offset: 0x00035828
public override Stream EndGetRequestStream(IAsyncResult asyncResult)
{
if (asyncResult == null)
{
throw new ArgumentNullException("asyncResult");
}
if (!asyncResult.IsCompleted)
{
asyncResult.AsyncWaitHandle.WaitOne();
}
AsyncResult asyncResult2 = (AsyncResult)asyncResult;
FileWebRequest.GetRequestStreamCallback getRequestStreamCallback = (FileWebRequest.GetRequestStreamCallback)asyncResult2.AsyncDelegate;
return getRequestStreamCallback.EndInvoke(asyncResult);
}
/// <summary>Returns a <see cref="T:System.IO.Stream" /> object for writing data to the file system resource.</summary>
/// <returns>A <see cref="T:System.IO.Stream" /> for writing data to the file system resource.</returns>
/// <exception cref="T:System.Net.WebException">The request times out. </exception>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// </PermissionSet>
// Token: 0x0600125E RID: 4702 RVA: 0x00037678 File Offset: 0x00035878
public override Stream GetRequestStream()
{
IAsyncResult asyncResult = this.BeginGetRequestStream(null, null);
if (!asyncResult.AsyncWaitHandle.WaitOne(this.timeout, false))
{
throw new WebException("The request timed out", WebExceptionStatus.Timeout);
}
return this.EndGetRequestStream(asyncResult);
}
// Token: 0x0600125F RID: 4703 RVA: 0x000376BC File Offset: 0x000358BC
internal Stream GetRequestStreamInternal()
{
this.requestStream = new FileWebRequest.FileWebStream(this, FileMode.Create, FileAccess.Write, FileShare.Read);
return this.requestStream;
}
/// <summary>Begins an asynchronous request for a file system resource.</summary>
/// <returns>An <see cref="T:System.IAsyncResult" /> that references the asynchronous request.</returns>
/// <param name="callback">The <see cref="T:System.AsyncCallback" /> delegate. </param>
/// <param name="state">An object that contains state information for this request. </param>
/// <exception cref="T:System.InvalidOperationException">The stream is already in use by a previous call to <see cref="M:System.Net.FileWebRequest.BeginGetResponse(System.AsyncCallback,System.Object)" />. </exception>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// </PermissionSet>
// Token: 0x06001260 RID: 4704 RVA: 0x000376D4 File Offset: 0x000358D4
public override IAsyncResult BeginGetResponse(AsyncCallback callback, object state)
{
lock (this)
{
if (this.asyncResponding)
{
throw new InvalidOperationException("Cannot re-call start of asynchronous method while a previous call is still in progress.");
}
this.asyncResponding = true;
}
FileWebRequest.GetResponseCallback getResponseCallback = new FileWebRequest.GetResponseCallback(this.GetResponseInternal);
return getResponseCallback.BeginInvoke(callback, state);
}
/// <summary>Ends an asynchronous request for a file system resource.</summary>
/// <returns>A <see cref="T:System.Net.WebResponse" /> that contains the response from the file system resource.</returns>
/// <param name="asyncResult">An <see cref="T:System.IAsyncResult" /> that references the pending request for a response. </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="asyncResult" /> is null. </exception>
// Token: 0x06001261 RID: 4705 RVA: 0x00037744 File Offset: 0x00035944
public override WebResponse EndGetResponse(IAsyncResult asyncResult)
{
if (asyncResult == null)
{
throw new ArgumentNullException("asyncResult");
}
if (!asyncResult.IsCompleted)
{
asyncResult.AsyncWaitHandle.WaitOne();
}
AsyncResult asyncResult2 = (AsyncResult)asyncResult;
FileWebRequest.GetResponseCallback getResponseCallback = (FileWebRequest.GetResponseCallback)asyncResult2.AsyncDelegate;
WebResponse webResponse = getResponseCallback.EndInvoke(asyncResult);
this.asyncResponding = false;
return webResponse;
}
/// <summary>Returns a response to a file system request.</summary>
/// <returns>A <see cref="T:System.Net.WebResponse" /> that contains the response from the file system resource.</returns>
/// <exception cref="T:System.Net.WebException">The request timed out. </exception>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// </PermissionSet>
// Token: 0x06001262 RID: 4706 RVA: 0x0003779C File Offset: 0x0003599C
public override WebResponse GetResponse()
{
IAsyncResult asyncResult = this.BeginGetResponse(null, null);
if (!asyncResult.AsyncWaitHandle.WaitOne(this.timeout, false))
{
throw new WebException("The request timed out", WebExceptionStatus.Timeout);
}
return this.EndGetResponse(asyncResult);
}
// Token: 0x06001263 RID: 4707 RVA: 0x000377E0 File Offset: 0x000359E0
private WebResponse GetResponseInternal()
{
if (this.webResponse != null)
{
return this.webResponse;
}
lock (this)
{
if (this.requesting)
{
this.requestEndEvent = new AutoResetEvent(false);
}
}
if (this.requestEndEvent != null)
{
this.requestEndEvent.WaitOne();
}
FileStream fileStream = null;
try
{
fileStream = new FileWebRequest.FileWebStream(this, FileMode.Open, FileAccess.Read, FileShare.Read);
}
catch (Exception ex)
{
throw new WebException(ex.Message, ex);
}
this.webResponse = new FileWebResponse(this.uri, fileStream);
return this.webResponse;
}
/// <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: 0x06001264 RID: 4708 RVA: 0x000378B4 File Offset: 0x00035AB4
protected override void GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)
{
serializationInfo.AddValue("headers", this.webHeaders, typeof(WebHeaderCollection));
serializationInfo.AddValue("proxy", this.proxy, typeof(IWebProxy));
serializationInfo.AddValue("uri", this.uri, typeof(global::System.Uri));
serializationInfo.AddValue("connectionGroupName", this.connectionGroup);
serializationInfo.AddValue("method", this.method);
serializationInfo.AddValue("contentLength", this.contentLength);
serializationInfo.AddValue("timeout", this.timeout);
serializationInfo.AddValue("fileAccess", this.fileAccess);
serializationInfo.AddValue("preauthenticate", false);
}
// Token: 0x06001265 RID: 4709 RVA: 0x0003797C File Offset: 0x00035B7C
internal void Close()
{
lock (this)
{
this.requesting = false;
if (this.requestEndEvent != null)
{
this.requestEndEvent.Set();
}
}
}
// Token: 0x04000FBD RID: 4029
private global::System.Uri uri;
// Token: 0x04000FBE RID: 4030
private WebHeaderCollection webHeaders;
// Token: 0x04000FBF RID: 4031
private ICredentials credentials;
// Token: 0x04000FC0 RID: 4032
private string connectionGroup;
// Token: 0x04000FC1 RID: 4033
private long contentLength;
// Token: 0x04000FC2 RID: 4034
private FileAccess fileAccess = FileAccess.Read;
// Token: 0x04000FC3 RID: 4035
private string method = "GET";
// Token: 0x04000FC4 RID: 4036
private IWebProxy proxy;
// Token: 0x04000FC5 RID: 4037
private bool preAuthenticate;
// Token: 0x04000FC6 RID: 4038
private int timeout = 100000;
// Token: 0x04000FC7 RID: 4039
private Stream requestStream;
// Token: 0x04000FC8 RID: 4040
private FileWebResponse webResponse;
// Token: 0x04000FC9 RID: 4041
private AutoResetEvent requestEndEvent;
// Token: 0x04000FCA RID: 4042
private bool requesting;
// Token: 0x04000FCB RID: 4043
private bool asyncResponding;
// Token: 0x0200021A RID: 538
internal class FileWebStream : FileStream
{
// Token: 0x06001266 RID: 4710 RVA: 0x000379D8 File Offset: 0x00035BD8
internal FileWebStream(FileWebRequest webRequest, FileMode mode, FileAccess access, FileShare share)
: base(webRequest.RequestUri.LocalPath, mode, access, share)
{
this.webRequest = webRequest;
}
// Token: 0x06001267 RID: 4711 RVA: 0x00037A04 File Offset: 0x00035C04
public override void Close()
{
base.Close();
FileWebRequest fileWebRequest = this.webRequest;
this.webRequest = null;
if (fileWebRequest != null)
{
fileWebRequest.Close();
}
}
// Token: 0x04000FCC RID: 4044
private FileWebRequest webRequest;
}
// Token: 0x02000315 RID: 789
// (Invoke) Token: 0x06001C2D RID: 7213
private delegate Stream GetRequestStreamCallback();
// Token: 0x02000316 RID: 790
// (Invoke) Token: 0x06001C31 RID: 7217
private delegate WebResponse GetResponseCallback();
}
}