We need you! We're working hard on the next version of Developer Fusion -
Let us know what you think we should be up to!
- namespace System.Net
- {
- using System.Collections;
- using System.Collections.Specialized;
- using System.Globalization;
- using System.IO;
- using System.IO.Compression;
- using System.Net.Cache;
- using System.Net.Configuration;
- using System.Runtime.Serialization;
- using System.Security;
- using System.Security.Cryptography.X509Certificates;
- using System.Security.Permissions;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading;
- using System.Net.Security;
- using System.Reflection;
- using System.ComponentModel;
-
- /// <devdoc>
- /// <para>
- /// <see cref='System.Net.HttpWebRequest'/> is an HTTP-specific implementation of the <see cref='System.Net.WebRequest'/> class.
- ///
- /// Performs the major body of HTTP request processing. Handles
- /// everything between issuing the HTTP header request to parsing the
- /// the HTTP response. At that point, we hand off the request to the response
- /// object, where the programmer can query for headers or continue reading, usw.
- /// </para>
- /// </devdoc>
-
-
- [Flags()]
- public enum DecompressionMethods
- {
- None = 0,
- GZip = 1,
- Deflate = 2
- }
-
-
- [Serializable()]
- public class HttpWebRequest : WebRequest, ISerializable
- {
-
-
- bool m_Saw100Continue;
- bool m_KeepAlive = true;
- bool m_LockConnection;
- bool m_NtlmKeepAlive;
- bool m_PreAuthenticate;
- DecompressionMethods m_AutomaticDecompression;
-
- private static class AbortState
- {
- public const int Public = 1;
- public const int Internal = 2;
- }
-
- private int m_Aborted;
-
-
-
-
-
-
-
-
-
- bool m_OnceFailed;
-
- bool m_Pipelined = true;
- bool m_Retry = true;
- bool m_HeadersCompleted;
- bool m_IsCurrentAuthenticationStateProxy;
- bool m_SawInitialResponse;
- bool m_BodyStarted;
- bool m_RequestSubmitted;
- bool m_OriginallyBuffered;
- bool m_Extra401Retry;
-
-
- [Flags()]
- private enum Booleans : uint
- {
- AllowAutoRedirect = 1,
- AllowWriteStreamBuffering = 2,
- ExpectContinue = 4,
-
- ProxySet = 16,
-
- UnsafeAuthenticatedConnectionSharing = 64,
- IsVersionHttp10 = 128,
- SendChunked = 256,
- EnableDecompression = 512,
- IsTunnelRequest = 1024,
- Default = AllowAutoRedirect | AllowWriteStreamBuffering | ExpectContinue
- }
-
-
- internal const HttpStatusCode MaxOkStatus = (HttpStatusCode)299;
- private const HttpStatusCode MaxRedirectionStatus = (HttpStatusCode)399;
- private const int RequestLineConstantSize = 12;
- private const string ContinueHeader = "100-continue";
- internal const string ChunkedHeader = "chunked";
- internal const string GZipHeader = "gzip";
- internal const string DeflateHeader = "deflate";
-
-
-
- private const int DefaultReadWriteTimeout = 5 * 60 * 1000;
-
-
- internal const int DefaultContinueTimeout = 350;
-
-
-
-
-
- private static readonly byte[] HttpBytes = new byte[] {(byte)'H', (byte)'T', (byte)'T', (byte)'P', (byte)'/'};
-
-
- private static readonly WaitCallback s_EndWriteHeaders_Part2Callback = new WaitCallback(EndWriteHeaders_Part2Wrapper);
- private static readonly TimerThread.Callback s_ContinueTimeoutCallback = new TimerThread.Callback(ContinueTimeoutCallback);
- private static readonly TimerThread.Queue s_ContinueTimerQueue = TimerThread.GetOrCreateQueue(DefaultContinueTimeout);
- private static readonly TimerThread.Callback s_TimeoutCallback = new TimerThread.Callback(TimeoutCallback);
- private static readonly WaitCallback s_AbortWrapper = new WaitCallback(AbortWrapper);
-
- private static int s_UniqueGroupId;
-
- private Booleans _Booleans = Booleans.Default;
-
- private DateTime _CachedIfModifedSince = DateTime.MinValue;
-
-
- private TimerThread.Timer m_ContinueTimer;
- private InterlockedGate m_ContinueGate;
-
-
- private object m_PendingReturnResult;
-
-
- private LazyAsyncResult _WriteAResult;
- private LazyAsyncResult _ReadAResult;
-
-
- private LazyAsyncResult _ConnectionAResult;
-
- private LazyAsyncResult _ConnectionReaderAResult;
-
-
- private TriState _RequestIsAsync;
-
-
- private HttpContinueDelegate _ContinueDelegate;
-
-
- internal ServicePoint _ServicePoint;
-
-
- internal HttpWebResponse _HttpResponse;
-
-
-
- private object _CoreResponse;
- private int _NestedWriteSideCheck;
-
-
- private KnownHttpVerb _Verb;
-
- private KnownHttpVerb _OriginVerb;
-
-
- private WebHeaderCollection _HttpRequestHeaders;
-
-
- private byte[] _WriteBuffer;
-
-
- private HttpWriteMode _HttpWriteMode;
-
-
- private Uri _Uri;
-
- private Uri _OriginUri;
-
-
- private string _MediaType;
-
-
- private long _ContentLength;
-
-
- private IWebProxy _Proxy;
- private ProxyChain _ProxyChain;
-
- private string _ConnectionGroupName;
- private bool m_InternalConnectionGroup;
-
- private AuthenticationState _ProxyAuthenticationState;
- private AuthenticationState _ServerAuthenticationState;
-
- private ICredentials _AuthInfo;
- private HttpAbortDelegate _AbortDelegate;
-
-
-
-
-
- private ConnectStream _SubmitWriteStream;
- private ConnectStream _OldSubmitWriteStream;
- private int _MaximumAllowedRedirections;
- private int _AutoRedirects;
-
-
-
-
-
- private int _RerequestCount;
-
-
-
-
-
- private int _Timeout;
-
-
-
-
- private TimerThread.Timer _Timer;
-
-
-
-
- private TimerThread.Queue _TimerQueue;
-
- private int _RequestContinueCount;
-
-
-
-
-
- private int _ReadWriteTimeout;
-
- private CookieContainer _CookieContainer;
-
- private int _MaximumResponseHeadersLength;
-
- private UnlockConnectionDelegate _UnlockDelegate;
-
-
-
-
-
-
-
-
-
-
-
-
- internal TimerThread.Timer RequestTimer {
- get { return _Timer; }
- }
-
- internal bool Aborted {
- get { return m_Aborted != 0; }
- }
-
-
- /// <devdoc>
- /// <para>
- /// Enables or disables automatically following redirection responses.
- /// </para>
- /// </devdoc>
- public bool AllowAutoRedirect {
- get { return (_Booleans & Booleans.AllowAutoRedirect) != 0; }
- set {
- if (value) {
- _Booleans |= Booleans.AllowAutoRedirect;
- }
- else {
- _Booleans &= ~Booleans.AllowAutoRedirect;
- }
- }
- }
-
- /// <devdoc>
- /// <para>
- /// Enables or disables buffering the data stream sent to the server.
- /// </para>
- /// </devdoc>
- public bool AllowWriteStreamBuffering {
- get { return (_Booleans & Booleans.AllowWriteStreamBuffering) != 0; }
- set {
- if (value) {
- _Booleans |= Booleans.AllowWriteStreamBuffering;
- }
- else {
- _Booleans &= ~Booleans.AllowWriteStreamBuffering;
- }
- }
- }
-
- private bool ExpectContinue {
- get { return (_Booleans & Booleans.ExpectContinue) != 0; }
- set {
- if (value) {
- _Booleans |= Booleans.ExpectContinue;
- }
- else {
- _Booleans &= ~Booleans.ExpectContinue;
- }
- }
- }
-
- /// <devdoc>
- /// <para>
- /// Returns <see langword='true'/> if a response has been received from the
- /// server.
- /// </para>
- /// </devdoc>
- public bool HaveResponse {
- get { return _ReadAResult != null && _ReadAResult.InternalPeekCompleted; }
- }
-
-
-
- internal bool NtlmKeepAlive {
- get { return m_NtlmKeepAlive; }
- set { m_NtlmKeepAlive = value; }
- }
-
-
-
- internal bool SawInitialResponse {
- get {
- GlobalLog.Print("HttpWebRequest#" + ValidationHelper.HashString(this) + "::SawInitialResponse_get() :" + m_SawInitialResponse);
- return m_SawInitialResponse;
- }
- set {
- GlobalLog.Print("HttpWebRequest#" + ValidationHelper.HashString(this) + "::SawInitialResponse_set() :" + value);
- m_SawInitialResponse = value;
- }
- }
-
- internal bool BodyStarted {
- get { return m_BodyStarted; }
- }
-
-
-
- /// <devdoc>
- /// <para>
- /// Gets or sets the value of the Keep-Alive header.
- /// </para>
- /// </devdoc>
- public bool KeepAlive {
- get { return m_KeepAlive; }
- set { m_KeepAlive = value; }
- }
-
-
-
-
-
- internal bool LockConnection {
- get { return m_LockConnection; }
- set { m_LockConnection = value; }
- }
-
-
-
-
- /// <devdoc>
- /// <para>
- /// Gets or sets the value of Pipelined property.
- /// </para>
- /// </devdoc>
- public bool Pipelined {
- get { return m_Pipelined; }
- set { m_Pipelined = value; }
- }
-
- /// <devdoc>
- /// <para>
- /// Enables or disables pre-authentication.
- /// </para>
- /// </devdoc>
- public override bool PreAuthenticate {
- get { return m_PreAuthenticate; }
- set { m_PreAuthenticate = value; }
- }
-
- private bool ProxySet {
- get { return (_Booleans & Booleans.ProxySet) != 0; }
- set {
- if (value) {
- _Booleans |= Booleans.ProxySet;
- }
- else {
- _Booleans &= ~Booleans.ProxySet;
- }
- }
- }
-
- private bool RequestSubmitted {
- get { return m_RequestSubmitted; }
- }
-
-
- private bool SetRequestSubmitted()
- {
- bool ret = RequestSubmitted;
- m_RequestSubmitted = true;
- GlobalLog.Print("HttpWebRequest#" + ValidationHelper.HashString(this) + "::SetRequestSubmitted() returning:" + ret.ToString());
- return ret;
- }
-
-
-
-
-
-
-
-
-
-
- internal bool Saw100Continue {
- get { return m_Saw100Continue; }
- set { m_Saw100Continue = value; }
- }
-
- /// <devdoc>
- /// <para>Allows hi-speed NTLM connection sharing with keep-alive</para>
- /// </devdoc>
- public bool UnsafeAuthenticatedConnectionSharing {
- get { return (_Booleans & Booleans.UnsafeAuthenticatedConnectionSharing) != 0; }
- set {
- ExceptionHelper.WebPermissionUnrestricted.Demand();
- if (value) {
- _Booleans |= Booleans.UnsafeAuthenticatedConnectionSharing;
- }
- else {
- _Booleans &= ~Booleans.UnsafeAuthenticatedConnectionSharing;
- }
- }
- }
-
-
-
- internal bool UnsafeOrProxyAuthenticatedConnectionSharing {
- get { return m_IsCurrentAuthenticationStateProxy || UnsafeAuthenticatedConnectionSharing; }
- }
-
-
-
- private bool IsVersionHttp10 {
- get { return (_Booleans & Booleans.IsVersionHttp10) != 0; }
- set {
- if (value) {
- _Booleans |= Booleans.IsVersionHttp10;
- }
- else {
- _Booleans &= ~Booleans.IsVersionHttp10;
- }
- }
- }
-
-
-
-
-
-
- /// <devdoc>
- /// <para>
- /// Enable and disable sending chunked data to the server.
- /// </para>
- /// </devdoc>
- public bool SendChunked {
- get { return (_Booleans & Booleans.SendChunked) != 0; }
- set {
- if (RequestSubmitted) {
- throw new InvalidOperationException(SR.GetString(SR.net_writestarted));
- }
- if (value) {
- _Booleans |= Booleans.SendChunked;
- }
- else {
- _Booleans &= ~Booleans.SendChunked;
- }
- }
- }
-
- public DecompressionMethods AutomaticDecompression {
- get { return m_AutomaticDecompression; }
- set {
- if (RequestSubmitted) {
- throw new InvalidOperationException(SR.GetString(SR.net_writestarted));
- }
- m_AutomaticDecompression = value;
- }
- }
-
-
-
-
-
-
-
-
- internal HttpWriteMode HttpWriteMode {
- get { return _HttpWriteMode; }
- set { _HttpWriteMode = value; }
- }
-
-
- internal string AuthHeader(HttpResponseHeader header)
- {
- if (_HttpResponse == null) {
- return null;
- }
-
- return _HttpResponse.Headers[(int)header];
- }
-
-
-
-
- public