StartsWithHttp() static private method

static private StartsWithHttp ( String url ) : int
url String
return int
Example #1
0
        private HttpWebRequest SetupWebRequest(IMessage msg, ITransportHeaders headers)
        {
            IMethodCallMessage mcMsg = msg as IMethodCallMessage;

            String msgUri = (String)headers[CommonTransportKeys.RequestUri];

            InternalRemotingServices.RemotingTrace("HttpClientChannel::SetupWebRequest Message uri is " + msgUri);

            if (msgUri == null)
            {
                if (mcMsg != null)
                {
                    msgUri = mcMsg.Uri;
                }
                else
                {
                    msgUri = (String)msg.Properties["__Uri"];
                }
            }

            String fullPath;

            if (HttpChannelHelper.StartsWithHttp(msgUri) != -1)
            {
                // this is the full path
                fullPath = msgUri;
            }
            else
            {
                // this is not the full path (_channelURI never has trailing slash)
                if (!msgUri.StartsWith("/", StringComparison.Ordinal))
                {
                    msgUri = "/" + msgUri;
                }

                fullPath = _channelURI + msgUri;
            }
            InternalRemotingServices.RemotingTrace("HttpClientChannel::SetupWebRequest FullPath " + fullPath);

            // based on headers, initialize the network stream

            String verb = (String)headers["__RequestVerb"];

            if (verb == null)
            {
                verb = s_defaultVerb;
            }

            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(fullPath);

            httpWebRequest.AllowAutoRedirect = _bAllowAutoRedirect;
            httpWebRequest.Method            = verb;
            httpWebRequest.SendChunked       = _useChunked;
            httpWebRequest.KeepAlive         = _useKeepAlive;
            httpWebRequest.Pipelined         = false;
            httpWebRequest.UserAgent         = s_userAgent;
            httpWebRequest.Timeout           = _timeout;
            httpWebRequest.CachePolicy       = s_requestCachePolicy;

            // see if we should use a proxy object
            IWebProxy proxy = _proxyObject;

            if (proxy == null) // use channel proxy if one hasn't been explicity set for this sink
            {
                proxy = _channel.ProxyObject;
            }
            if (proxy != null)
            {
                httpWebRequest.Proxy = proxy;
            }

            // see if security should be used
            //   order of applying credentials is:
            //   1. check for explicitly set credentials
            //   2. else check for explicitly set username, password, domain
            //   3. else use default credentials if channel is configured to do so.
            if (_credentials != null)
            {
                httpWebRequest.Credentials     = _credentials;
                httpWebRequest.PreAuthenticate = _bSecurityPreAuthenticate;
                httpWebRequest.UnsafeAuthenticatedConnectionSharing = _bUnsafeAuthenticatedConnectionSharing;
                if (_connectionGroupName != null)
                {
                    httpWebRequest.ConnectionGroupName = _connectionGroupName;
                }
            }
            else
            if (_securityUserName != null)
            {
                if (_securityDomain == null)
                {
                    httpWebRequest.Credentials = new NetworkCredential(_securityUserName, _securityPassword);
                }
                else
                {
                    httpWebRequest.Credentials = new NetworkCredential(_securityUserName, _securityPassword, _securityDomain);
                }

                httpWebRequest.PreAuthenticate = _bSecurityPreAuthenticate;
                httpWebRequest.UnsafeAuthenticatedConnectionSharing = _bUnsafeAuthenticatedConnectionSharing;
                if (_connectionGroupName != null)
                {
                    httpWebRequest.ConnectionGroupName = _connectionGroupName;
                }
            }
            else
            if (_channel.UseDefaultCredentials)
            {
                if (_channel.UseAuthenticatedConnectionSharing)
                {
#if !FEATURE_PAL
                    httpWebRequest.ConnectionGroupName = CoreChannel.GetCurrentSidString();
#endif
                    httpWebRequest.UnsafeAuthenticatedConnectionSharing = true;
                }

#if !FEATURE_PAL
                httpWebRequest.Credentials = CredentialCache.DefaultCredentials;
#endif // !FEATURE_PAL
                httpWebRequest.PreAuthenticate = _bSecurityPreAuthenticate;
            }

#if !FEATURE_PAL
            if (_certificates != null)
            {
                // attach certificates to the outgoing web request
                foreach (X509Certificate certificate in _certificates)
                {
                    httpWebRequest.ClientCertificates.Add(certificate);
                }
                httpWebRequest.PreAuthenticate = _bSecurityPreAuthenticate;
            }
#endif

            InternalRemotingServices.RemotingTrace("HttpClientTransportSink::SetupWebRequest - Get Http Request Headers");

            // add headers
            foreach (DictionaryEntry header in headers)
            {
                String key = header.Key as String;

                // if header name starts with "__", it is a special value that shouldn't be
                //   actually sent out.
                if ((key != null) && !key.StartsWith("__", StringComparison.Ordinal))
                {
                    if (key.Equals("Content-Type"))
                    {
                        httpWebRequest.ContentType = header.Value.ToString();
                    }
                    else
                    {
                        httpWebRequest.Headers[key] = header.Value.ToString();
                    }
                }
            }

            return(httpWebRequest);
        } // SetupWebRequest
        private HttpWebRequest SetupWebRequest(IMessage msg, ITransportHeaders headers)
        {
            string             str2;
            IMethodCallMessage message = msg as IMethodCallMessage;
            string             url     = (string)headers["__RequestUri"];

            if (url == null)
            {
                if (message != null)
                {
                    url = message.Uri;
                }
                else
                {
                    url = (string)msg.Properties["__Uri"];
                }
            }
            if (HttpChannelHelper.StartsWithHttp(url) != -1)
            {
                str2 = url;
            }
            else
            {
                if (!url.StartsWith("/", StringComparison.Ordinal))
                {
                    url = "/" + url;
                }
                str2 = this._channelURI + url;
            }
            string str3 = (string)headers["__RequestVerb"];

            if (str3 == null)
            {
                str3 = "POST";
            }
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(str2);

            request.AllowAutoRedirect = this._bAllowAutoRedirect;
            request.Method            = str3;
            request.SendChunked       = this._useChunked;
            request.KeepAlive         = this._useKeepAlive;
            request.Pipelined         = false;
            request.UserAgent         = s_userAgent;
            request.Timeout           = this._timeout;
            request.CachePolicy       = s_requestCachePolicy;
            IWebProxy proxyObject = this._proxyObject;

            if (proxyObject == null)
            {
                proxyObject = this._channel.ProxyObject;
            }
            if (proxyObject != null)
            {
                request.Proxy = proxyObject;
            }
            if (this._credentials != null)
            {
                request.Credentials     = this._credentials;
                request.PreAuthenticate = this._bSecurityPreAuthenticate;
                request.UnsafeAuthenticatedConnectionSharing = this._bUnsafeAuthenticatedConnectionSharing;
                if (this._connectionGroupName != null)
                {
                    request.ConnectionGroupName = this._connectionGroupName;
                }
            }
            else if (this._securityUserName != null)
            {
                if (this._securityDomain == null)
                {
                    request.Credentials = new NetworkCredential(this._securityUserName, this._securityPassword);
                }
                else
                {
                    request.Credentials = new NetworkCredential(this._securityUserName, this._securityPassword, this._securityDomain);
                }
                request.PreAuthenticate = this._bSecurityPreAuthenticate;
                request.UnsafeAuthenticatedConnectionSharing = this._bUnsafeAuthenticatedConnectionSharing;
                if (this._connectionGroupName != null)
                {
                    request.ConnectionGroupName = this._connectionGroupName;
                }
            }
            else if (this._channel.UseDefaultCredentials)
            {
                if (this._channel.UseAuthenticatedConnectionSharing)
                {
                    request.ConnectionGroupName = CoreChannel.GetCurrentSidString();
                    request.UnsafeAuthenticatedConnectionSharing = true;
                }
                request.Credentials     = CredentialCache.DefaultCredentials;
                request.PreAuthenticate = this._bSecurityPreAuthenticate;
            }
            if (this._certificates != null)
            {
                foreach (X509Certificate certificate in this._certificates)
                {
                    request.ClientCertificates.Add(certificate);
                }
                request.PreAuthenticate = this._bSecurityPreAuthenticate;
            }
            foreach (DictionaryEntry entry in headers)
            {
                string key = entry.Key as string;
                if ((key != null) && !key.StartsWith("__", StringComparison.Ordinal))
                {
                    if (key.Equals("Content-Type"))
                    {
                        request.ContentType = entry.Value.ToString();
                    }
                    else
                    {
                        request.Headers[key] = entry.Value.ToString();
                    }
                }
            }
            return(request);
        }