public bool Equals(KnownHttpVerb verb) { if (this != verb) { return(string.Compare(this.Name, verb.Name, StringComparison.OrdinalIgnoreCase) == 0); } return(true); }
public bool Equals(KnownHttpVerb verb) { if (this != verb) { return (string.Compare(this.Name, verb.Name, StringComparison.OrdinalIgnoreCase) == 0); } return true; }
public static KnownHttpVerb Parse(string name) { KnownHttpVerb verb = NamedHeaders[name] as KnownHttpVerb; if (verb == null) { verb = new KnownHttpVerb(name, false, false, false, false); } return verb; }
public static KnownHttpVerb Parse(string name) { KnownHttpVerb verb = NamedHeaders[name] as KnownHttpVerb; if (verb == null) { verb = new KnownHttpVerb(name, false, false, false, false); } return(verb); }
internal HttpWebResponse(Uri responseUri, KnownHttpVerb verb, CoreResponseData coreData, string mediaType, bool usesProxySemantics, DecompressionMethods decompressionMethod) { m_Uri = responseUri; m_Verb = verb; m_MediaType = mediaType; m_UsesProxySemantics = usesProxySemantics; m_ConnectStream = coreData.m_ConnectStream; m_HttpResponseHeaders = coreData.m_ResponseHeaders; m_ContentLength = coreData.m_ContentLength; m_StatusCode = coreData.m_StatusCode; m_StatusDescription = coreData.m_StatusDescription; m_IsVersionHttp11 = coreData.m_IsVersionHttp11; //if the returned contentlength is zero, preemptively invoke calldone on the stream. //this will wake up any pending reads. if (m_ContentLength == 0 && m_ConnectStream is ConnectStream) { ((ConnectStream)m_ConnectStream).CallDone(); } // handle Content-Location header, by combining it with the orginal request. string contentLocation = m_HttpResponseHeaders[HttpKnownHeaderNames.ContentLocation]; if (contentLocation != null) { try { m_Uri = new Uri(m_Uri, contentLocation); } catch (UriFormatException e) { GlobalLog.Assert("Exception on response Uri parsing.", e.ToString()); } } // decompress responses by hooking up a final response Stream - only if user required it if(decompressionMethod != DecompressionMethods.None) { string contentEncoding = m_HttpResponseHeaders[HttpKnownHeaderNames.ContentEncoding]; if (contentEncoding != null){ if(((decompressionMethod & DecompressionMethods.GZip) != 0) && contentEncoding.IndexOf(HttpWebRequest.GZipHeader) != -1) { m_ConnectStream = new GZipWrapperStream(m_ConnectStream, CompressionMode.Decompress); m_ContentLength = -1; // unknown on compressed streams // Setting a response header after parsing will ruin the Common Header optimization. // This seems like a corner case. ContentEncoding could be added as a common header, with a special // property allowing it to be nulled. m_HttpResponseHeaders[HttpKnownHeaderNames.ContentEncoding] = null; } else if (((decompressionMethod & DecompressionMethods.Deflate) != 0) && contentEncoding.IndexOf(HttpWebRequest.DeflateHeader) != -1) { m_ConnectStream = new DeflateWrapperStream(m_ConnectStream, CompressionMode.Decompress); m_ContentLength = -1; // unknown on compressed streams // Setting a response header after parsing will ruin the Common Header optimization. // This seems like a corner case. ContentEncoding could be added as a common header, with a special // property allowing it to be nulled. m_HttpResponseHeaders[HttpKnownHeaderNames.ContentEncoding] = null; } } } }
public static KnownHttpVerb Parse(string name) { KnownHttpVerb knownHttpVerb = NamedHeaders[name] as KnownHttpVerb; if (knownHttpVerb == null) { // unknown verb, default behaviour knownHttpVerb = new KnownHttpVerb(name, false, false, false, false); } return(knownHttpVerb); }
protected HttpWebResponse(SerializationInfo serializationInfo, StreamingContext streamingContext):base(serializationInfo, streamingContext) { m_HttpResponseHeaders = (WebHeaderCollection)serializationInfo.GetValue("m_HttpResponseHeaders", typeof(WebHeaderCollection)); m_Uri = (Uri)serializationInfo.GetValue("m_Uri", typeof(Uri)); Version version = (Version)serializationInfo.GetValue("m_Version", typeof(Version)); m_IsVersionHttp11 = version.Equals(HttpVersion.Version11); m_StatusCode = (HttpStatusCode)serializationInfo.GetInt32("m_StatusCode"); m_ContentLength = serializationInfo.GetInt64("m_ContentLength"); m_Verb = KnownHttpVerb.Parse(serializationInfo.GetString("m_Verb")); m_StatusDescription = serializationInfo.GetString("m_StatusDescription"); m_MediaType = serializationInfo.GetString("m_MediaType"); }
protected HttpWebResponse(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext) { this.m_HttpResponseHeaders = (WebHeaderCollection) serializationInfo.GetValue("m_HttpResponseHeaders", typeof(WebHeaderCollection)); this.m_Uri = (Uri) serializationInfo.GetValue("m_Uri", typeof(Uri)); this.m_Certificate = (X509Certificate) serializationInfo.GetValue("m_Certificate", typeof(X509Certificate)); this.m_IsVersionHttp11 = ((Version) serializationInfo.GetValue("m_Version", typeof(Version))).Equals(HttpVersion.Version11); this.m_StatusCode = (HttpStatusCode) serializationInfo.GetInt32("m_StatusCode"); this.m_ContentLength = serializationInfo.GetInt64("m_ContentLength"); this.m_Verb = KnownHttpVerb.Parse(serializationInfo.GetString("m_Verb")); this.m_StatusDescription = serializationInfo.GetString("m_StatusDescription"); this.m_MediaType = serializationInfo.GetString("m_MediaType"); }
internal HttpWebResponse(Uri responseUri, KnownHttpVerb verb, CoreResponseData coreData, string mediaType, bool usesProxySemantics, DecompressionMethods decompressionMethod) { this.m_Uri = responseUri; this.m_Verb = verb; this.m_MediaType = mediaType; this.m_UsesProxySemantics = usesProxySemantics; this.m_ConnectStream = coreData.m_ConnectStream; this.m_HttpResponseHeaders = coreData.m_ResponseHeaders; this.m_ContentLength = coreData.m_ContentLength; this.m_StatusCode = coreData.m_StatusCode; this.m_StatusDescription = coreData.m_StatusDescription; this.m_IsVersionHttp11 = coreData.m_IsVersionHttp11; if ((this.m_ContentLength == 0L) && (this.m_ConnectStream is ConnectStream)) { ((ConnectStream)this.m_ConnectStream).CallDone(); } string relativeUri = this.m_HttpResponseHeaders["Content-Location"]; if (relativeUri != null) { try { this.m_Uri = new Uri(this.m_Uri, relativeUri); } catch (UriFormatException) { } } if (decompressionMethod != DecompressionMethods.None) { string str2 = this.m_HttpResponseHeaders["Content-Encoding"]; if (str2 != null) { if (((decompressionMethod & DecompressionMethods.GZip) != DecompressionMethods.None) && (str2.IndexOf("gzip") != -1)) { this.m_ConnectStream = new GZipWrapperStream(this.m_ConnectStream, CompressionMode.Decompress); this.m_ContentLength = -1L; this.m_HttpResponseHeaders["Content-Encoding"] = null; } else if (((decompressionMethod & DecompressionMethods.Deflate) != DecompressionMethods.None) && (str2.IndexOf("deflate") != -1)) { this.m_ConnectStream = new DeflateWrapperStream(this.m_ConnectStream, CompressionMode.Decompress); this.m_ContentLength = -1L; this.m_HttpResponseHeaders["Content-Encoding"] = null; } } } }
// // InitializeKnownVerbs - Does basic init for this object, // such as creating defaultings and filling them // static KnownHttpVerb() { NamedHeaders = new ListDictionary(CaseInsensitiveAscii.StaticInstance); Get = new KnownHttpVerb("GET", false, true, false, false); Connect = new KnownHttpVerb("CONNECT", false, true, true, false); Head = new KnownHttpVerb("HEAD", false, true, false, true); Put = new KnownHttpVerb("PUT", true, false, false, false); Post = new KnownHttpVerb("POST", true, false, false, false); MkCol = new KnownHttpVerb("MKCOL", false, false, false, false); NamedHeaders[Get.Name] = Get; NamedHeaders[Connect.Name] = Connect; NamedHeaders[Head.Name] = Head; NamedHeaders[Put.Name] = Put; NamedHeaders[Post.Name] = Post; NamedHeaders[MkCol.Name] = MkCol; }
internal HttpWebResponse(Uri responseUri, KnownHttpVerb verb, CoreResponseData coreData, string mediaType, bool usesProxySemantics, DecompressionMethods decompressionMethod) { this.m_Uri = responseUri; this.m_Verb = verb; this.m_MediaType = mediaType; this.m_UsesProxySemantics = usesProxySemantics; this.m_ConnectStream = coreData.m_ConnectStream; this.m_HttpResponseHeaders = coreData.m_ResponseHeaders; this.m_ContentLength = coreData.m_ContentLength; this.m_StatusCode = coreData.m_StatusCode; this.m_StatusDescription = coreData.m_StatusDescription; this.m_IsVersionHttp11 = coreData.m_IsVersionHttp11; if ((this.m_ContentLength == 0L) && (this.m_ConnectStream is ConnectStream)) { ((ConnectStream) this.m_ConnectStream).CallDone(); } string relativeUri = this.m_HttpResponseHeaders["Content-Location"]; if (relativeUri != null) { try { this.m_Uri = new Uri(this.m_Uri, relativeUri); } catch (UriFormatException) { } } if (decompressionMethod != DecompressionMethods.None) { string str2 = this.m_HttpResponseHeaders["Content-Encoding"]; if (str2 != null) { if (((decompressionMethod & DecompressionMethods.GZip) != DecompressionMethods.None) && (str2.IndexOf("gzip") != -1)) { this.m_ConnectStream = new GZipWrapperStream(this.m_ConnectStream, CompressionMode.Decompress); this.m_ContentLength = -1L; this.m_HttpResponseHeaders["Content-Encoding"] = null; } else if (((decompressionMethod & DecompressionMethods.Deflate) != DecompressionMethods.None) && (str2.IndexOf("deflate") != -1)) { this.m_ConnectStream = new DeflateWrapperStream(this.m_ConnectStream, CompressionMode.Decompress); this.m_ContentLength = -1L; this.m_HttpResponseHeaders["Content-Encoding"] = null; } } } }
// // PERF: // removed some double initializations. // perf went from: // clocks per instruction CPI: 9,098.72 to 1,301.14 // %app exclusive time: 2.92 to 0.43 // /// <devdoc> /// <para> /// Basic Constructor for HTTP Protocol Class, Initializes to basic header state. /// </para> /// </devdoc> internal HttpWebRequest(Uri uri, ServicePoint servicePoint) { if(Logging.On)Logging.Enter(Logging.Web, this, "HttpWebRequest", uri); (new WebPermission(NetworkAccess.Connect, uri)).Demand(); // OOPS, This ctor can also be called with FTP scheme but then it should only allowed if going through the proxy // Something to think about... //if ((object)uri.Scheme != (object)Uri.UriSchemeHttp && (object)uri.Scheme != (object)Uri.UriSchemeHttps) //throw new ArgumentOutOfRangeException("uri"); GlobalLog.Print("HttpWebRequest#" + ValidationHelper.HashString(this) + "::.ctor(" + uri.ToString() + ")"); // // internal constructor, HttpWebRequest cannot be created directly // but only through WebRequest.Create() method // set defaults // _HttpRequestHeaders = new WebHeaderCollection(WebHeaderCollectionType.HttpWebRequest); _Proxy = WebRequest.InternalDefaultWebProxy; _HttpWriteMode = HttpWriteMode.Unknown; _MaximumAllowedRedirections = 50; _Timeout = WebRequest.DefaultTimeout; _TimerQueue = WebRequest.DefaultTimerQueue; _ReadWriteTimeout = DefaultReadWriteTimeout; _MaximumResponseHeadersLength = DefaultMaximumResponseHeadersLength; _ContentLength = -1; _OriginVerb = KnownHttpVerb.Get; _OriginUri = uri; _Uri = _OriginUri; _ServicePoint = servicePoint; _RequestIsAsync = TriState.Unspecified; SetupCacheProtocol(_OriginUri); if(Logging.On)Logging.Exit(Logging.Web, this, "HttpWebRequest", null); }
internal HttpWebRequest(Uri uri, ServicePoint servicePoint) { if(Logging.On)Logging.Enter(Logging.Web, this, "HttpWebRequest", uri); CheckConnectPermission(uri, false); m_StartTimestamp = NetworkingPerfCounters.GetTimestamp(); NetworkingPerfCounters.Instance.Increment(NetworkingPerfCounterName.HttpWebRequestCreated); // OOPS, This ctor can also be called with FTP scheme but then it should only allowed if going through the proxy // Something to think about... //if ((object)uri.Scheme != (object)Uri.UriSchemeHttp && (object)uri.Scheme != (object)Uri.UriSchemeHttps) //throw new ArgumentOutOfRangeException("uri"); GlobalLog.Print("HttpWebRequest#" + ValidationHelper.HashString(this) + "::.ctor(" + uri.ToString() + ")"); // // internal constructor, HttpWebRequest cannot be created directly // but only through WebRequest.Create() method // set defaults // _HttpRequestHeaders = new WebHeaderCollection(WebHeaderCollectionType.HttpWebRequest); _Proxy = WebRequest.InternalDefaultWebProxy; _HttpWriteMode = HttpWriteMode.Unknown; _MaximumAllowedRedirections = 50; _Timeout = WebRequest.DefaultTimeout; _TimerQueue = WebRequest.DefaultTimerQueue; _ReadWriteTimeout = DefaultReadWriteTimeout; _MaximumResponseHeadersLength = DefaultMaximumResponseHeadersLength; _ContentLength = -1; _originalContentLength = -1; _OriginVerb = KnownHttpVerb.Get; _OriginUri = uri; _Uri = _OriginUri; _ServicePoint = servicePoint; _RequestIsAsync = TriState.Unspecified; m_ContinueTimeout = DefaultContinueTimeout; m_ContinueTimerQueue = s_ContinueTimerQueue; SetupCacheProtocol(_OriginUri); #if HTTP_HEADER_EXTENSIONS_SUPPORTED _NextExtension = 10; #endif // HTTP_HEADER_EXTENSIONS_SUPPORTED if(Logging.On)Logging.Exit(Logging.Web, this, "HttpWebRequest", null); }
public bool Equals(KnownHttpVerb verb) { return this==verb || string.Compare(Name, verb.Name, StringComparison.OrdinalIgnoreCase)==0; }
public static KnownHttpVerb Parse(string name) { KnownHttpVerb knownHttpVerb = NamedHeaders[name] as KnownHttpVerb; if (knownHttpVerb==null) { // unknown verb, default behaviour knownHttpVerb = new KnownHttpVerb(name, false, false, false, false); } return knownHttpVerb; }
// // InitializeKnownVerbs - Does basic init for this object, // such as creating defaultings and filling them // static KnownHttpVerb() { NamedHeaders = new ListDictionary(CaseInsensitiveAscii.StaticInstance); Get = new KnownHttpVerb("GET", false, true, false, false); Connect = new KnownHttpVerb("CONNECT", false, true, true, false); Head = new KnownHttpVerb("HEAD", false, true, false, true); Put = new KnownHttpVerb("PUT", true, false, false, false); Post = new KnownHttpVerb("POST", true, false, false, false); MkCol = new KnownHttpVerb("MKCOL",false,false,false,false); NamedHeaders[Get.Name] = Get; NamedHeaders[Connect.Name] = Connect; NamedHeaders[Head.Name] = Head; NamedHeaders[Put.Name] = Put; NamedHeaders[Post.Name] = Post; NamedHeaders[MkCol.Name] = MkCol; }
private bool CanGetRequestStream() { return(!KnownHttpVerb.Parse(this.m_method).ContentBodyNotAllowed); }
public bool Equals(KnownHttpVerb verb) { return(this == verb || string.Compare(Name, verb.Name, StringComparison.OrdinalIgnoreCase) == 0); }
internal HttpWebRequest(Uri proxyUri, Uri requestUri, HttpWebRequest orginalRequest) : this(proxyUri, null) { GlobalLog.Enter("HttpWebRequest::HttpWebRequest", "proxyUri="+proxyUri+", requestUri="+requestUri ); _OriginVerb = KnownHttpVerb.Parse("CONNECT"); // // CONNECT requests cannot be pipelined // Pipelined = false; // // each CONNECT request has a unique connection group name to avoid // non-CONNECT requests being made over the same connection // _OriginUri = requestUri; IsTunnelRequest = true; _ConnectionGroupName = ServicePointManager.SpecialConnectGroupName + "(" + UniqueGroupId + ")"; m_InternalConnectionGroup = true; // // the CONNECT request must respond to a 407 as if it were a 401. // So we set up the server authentication state as if for a proxy // ServerAuthenticationState = new AuthenticationState(true); // CONNECT request is not suitable for caching CacheProtocol = null; m_ContinueTimeout = DefaultContinueTimeout; m_ContinueTimerQueue = s_ContinueTimerQueue; GlobalLog.Leave("HttpWebRequest::HttpWebRequest"); }
/*private*/ protected HttpWebRequest(SerializationInfo serializationInfo, StreamingContext streamingContext):base(serializationInfo, streamingContext) { #if DEBUG using (GlobalLog.SetThreadKind(ThreadKinds.User)) { #endif ExceptionHelper.WebPermissionUnrestricted.Demand(); if(Logging.On)Logging.Enter(Logging.Web, this, "HttpWebRequest", serializationInfo); _HttpRequestHeaders = (WebHeaderCollection)serializationInfo.GetValue("_HttpRequestHeaders", typeof(WebHeaderCollection)); _Proxy = (IWebProxy)serializationInfo.GetValue("_Proxy", typeof(IWebProxy)); KeepAlive = serializationInfo.GetBoolean("_KeepAlive"); Pipelined = serializationInfo.GetBoolean("_Pipelined"); AllowAutoRedirect = serializationInfo.GetBoolean("_AllowAutoRedirect"); if (!serializationInfo.GetBoolean("_AllowWriteStreamBuffering")) { _Booleans &= ~Booleans.AllowWriteStreamBuffering; } HttpWriteMode = (HttpWriteMode)serializationInfo.GetInt32("_HttpWriteMode"); _MaximumAllowedRedirections = serializationInfo.GetInt32("_MaximumAllowedRedirections"); _AutoRedirects = serializationInfo.GetInt32("_AutoRedirects"); _Timeout = serializationInfo.GetInt32("_Timeout"); m_ContinueTimeout = DefaultContinueTimeout; // This ctor is deprecated. Just set the default value. m_ContinueTimerQueue = s_ContinueTimerQueue; try { _ReadWriteTimeout = serializationInfo.GetInt32("_ReadWriteTimeout"); } catch { _ReadWriteTimeout = DefaultReadWriteTimeout; } try { _MaximumResponseHeadersLength = serializationInfo.GetInt32("_MaximumResponseHeadersLength"); } catch { _MaximumResponseHeadersLength = DefaultMaximumResponseHeadersLength; } _ContentLength = serializationInfo.GetInt64("_ContentLength"); _MediaType = serializationInfo.GetString("_MediaType"); _OriginVerb = KnownHttpVerb.Parse(serializationInfo.GetString("_OriginVerb")); _ConnectionGroupName = serializationInfo.GetString("_ConnectionGroupName"); ProtocolVersion = (Version)serializationInfo.GetValue("_Version", typeof(Version)); _OriginUri = (Uri)serializationInfo.GetValue("_OriginUri", typeof(Uri)); #if HTTP_HEADER_EXTENSIONS_SUPPORTED _NextExtension = serializationInfo.GetInt32("_NextExtension"); #endif // HTTP_HEADER_EXTENSIONS_SUPPORTED SetupCacheProtocol(_OriginUri); if(Logging.On)Logging.Exit(Logging.Web, this, "HttpWebRequest", null); #if DEBUG } #endif }