string GetRequestUriForCurrentRequest(HttpContext context)
        {
            // we need to pull off any http specific data plus the application v-dir name
            String rawUrl = context.Request.RawUrl;
            // here's where we pull off channel info
            String channelUri;
            String requestUri;

            channelUri = HttpChannelHelper.ParseURL(rawUrl, out requestUri);
            if (channelUri == null)
            {
                requestUri = rawUrl;
            }

            // here's where we pull off the application v-dir name
            String appName = RemotingConfiguration.ApplicationName;

            if (appName != null && appName.Length > 0 && requestUri.Length > appName.Length)
            {
                //  "/appname" should always be in front, otherwise we wouldn't
                //   be in this handler.
                requestUri = requestUri.Substring(appName.Length + 1);
            }

            return(requestUri);
        }
Example #2
0
        internal static String EncodeUriAsXLinkHref(String uri)
        {
            if (uri == null)
            {
                return(null);
            }

            // uses modified encoding rules from xlink href spec for encoding uri's.
            // http://www.w3.org/TR/2000/PR-xlink-20001220/#link-locators

            byte[] uriBytes = Encoding.UTF8.GetBytes(uri);

            StringBuilder sb = new StringBuilder(uri.Length);

            // iterate over uri bytes and build up an encoded string.
            foreach (byte b in uriBytes)
            {
                if (!EscapeInXLinkHref(b))
                {
                    sb.Append((char)b);
                }
                else
                {
                    // the character needs to be encoded as %HH
                    sb.Append('%');
                    sb.Append(HttpChannelHelper.DecimalToCharacterHexDigit(b >> 4));
                    sb.Append(HttpChannelHelper.DecimalToCharacterHexDigit(b & 0xF));
                }
            }

            return(sb.ToString());
        } // EncodeUriAsXLinkHref
Example #3
0
        /// <include file='doc\HttpServerChannel.uex' path='docs/doc[@for="HttpServerChannel.AddHookChannelUri"]/*' />
        public void AddHookChannelUri(String channelUri)
        {
            if (_channelData.ChannelUris != null)
            {
                throw new RemotingException(
                          CoreChannel.GetResourceString("Remoting_Http_LimitListenerOfOne"));
            }
            else
            {
                // replace machine name with explicitly configured
                //   machine name or ip address if necessary
                if (_forcedMachineName != null)
                {
                    channelUri =
                        HttpChannelHelper.ReplaceMachineNameWithThisString(channelUri, _forcedMachineName);
                }
                else
                if (_bUseIpAddress)
                {
                    channelUri =
                        HttpChannelHelper.ReplaceMachineNameWithThisString(channelUri, CoreChannel.GetMachineIp());
                }

                _channelData.ChannelUris = new String[] { channelUri };
                _wantsToListen           = false;
                _bHooked = true;
            }
        } // AddHookChannelUri
        internal static string DecodeUri(string uri)
        {
            int num;

            byte[] bytes = Encoding.UTF8.GetBytes(uri);
            HttpChannelHelper.DecodeUriInPlace(bytes, out num);
            return(Encoding.UTF8.GetString(bytes, 0, num));
        }
        bool CanServiceRequest(HttpContext context)
        {
            //Need to get the object uri first (cannot have query string)
            string requestUri = GetRequestUriForCurrentRequest(context);
            string objectUri  = HttpChannelHelper.GetObjectUriFromRequestUri(requestUri);

            context.Items["__requestUri"] = requestUri;

            if (String.Compare(context.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase) != 0)
            {
                //If the request backed by an existing object
                if (RemotingServices.GetServerTypeForUri(requestUri) != null)
                {
                    return(true);
                }
            }
            else
            {
                if (context.Request.QueryString.Count != 1)
                {
                    return(false);
                }

                string[] values = context.Request.QueryString.GetValues(0);
                if (values.Length != 1 || String.Compare(values[0], "wsdl", StringComparison.OrdinalIgnoreCase) != 0)
                {
                    return(false);
                }

                //If the request specifically asks for the wildcard
                if (String.Compare(objectUri, "RemoteApplicationMetadata.rem", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return(true);
                }

                // find last index of ?
                int index = requestUri.LastIndexOf('?');
                if (index != -1)
                {
                    requestUri = requestUri.Substring(0, index);
                }

                //If the request backed by an existing object
                if (RemotingServices.GetServerTypeForUri(requestUri) != null)
                {
                    return(true);
                }
            }

            //If the request is backed by an existing file on disk it should be serviced
            if (File.Exists(context.Request.PhysicalPath))
            {
                return(true);
            }

            return(false);
        }
        public BaseTransportHeaders ReadHeaders()
        {
            string str;
            string str2;
            string str3;
            string str5;
            bool   bSendContinue         = false;
            BaseTransportHeaders headers = new BaseTransportHeaders();

            this.ReadFirstLine(out str, out str2, out str3);
            if (((str == null) || (str2 == null)) || (str3 == null))
            {
                throw new RemotingException(CoreChannel.GetResourceString("Remoting_Http_UnableToReadFirstLine"));
            }
            if (str3.Equals("HTTP/1.1"))
            {
                this._version = System.Runtime.Remoting.Channels.Http.HttpVersion.V1_1;
            }
            else if (str3.Equals("HTTP/1.0"))
            {
                this._version = System.Runtime.Remoting.Channels.Http.HttpVersion.V1_0;
            }
            else
            {
                this._version = System.Runtime.Remoting.Channels.Http.HttpVersion.V1_1;
            }
            if (this._version == System.Runtime.Remoting.Channels.Http.HttpVersion.V1_1)
            {
                this._keepAlive = true;
            }
            else
            {
                this._keepAlive = false;
            }
            if (HttpChannelHelper.ParseURL(str2, out str5) == null)
            {
                str5 = str2;
            }
            headers["__RequestVerb"] = str;
            headers.RequestUri       = str5;
            headers["__HttpVersion"] = str3;
            if ((this._version == System.Runtime.Remoting.Channels.Http.HttpVersion.V1_1) && (str.Equals("POST") || str.Equals("PUT")))
            {
                bSendContinue = true;
            }
            base.ReadToEndOfHeaders(headers, out this._chunkedEncoding, out this._contentLength, ref this._keepAlive, ref bSendContinue);
            if (bSendContinue && (this._version != System.Runtime.Remoting.Channels.Http.HttpVersion.V1_0))
            {
                this.SendContinue();
            }
            headers["__IPAddress"]    = ((IPEndPoint)base.NetSocket.RemoteEndPoint).Address;
            headers["__ConnectionId"] = this._connectionId;
            return(headers);
        }
Example #7
0
        } // EscapeInXLinkHref

        internal static String DecodeUri(String uri)
        {
            byte[] uriBytes = Encoding.UTF8.GetBytes(uri);

            int length;

            HttpChannelHelper.DecodeUriInPlace(uriBytes, out length);

            String newUri = Encoding.UTF8.GetString(uriBytes, 0, length);

            return(newUri);
        } // DecodeUri
        private bool ReadFirstLine(out string verb, out string requestURI, out string version)
        {
            int num;

            verb       = null;
            requestURI = null;
            version    = null;
            verb       = base.ReadToChar(' ', s_validateVerbDelegate);
            byte[] uriBytes = base.ReadToByte(0x20);
            HttpChannelHelper.DecodeUriInPlace(uriBytes, out num);
            requestURI = Encoding.UTF8.GetString(uriBytes, 0, num);
            version    = base.ReadToEndOfLine();
            return(true);
        }
Example #9
0
        }         // ParseContentType

        internal static String ReplaceChannelUriWithThisString(String url, String channelUri)
        {
            // NOTE: channelUri is assumed to be scheme://machinename:port
            //   with NO trailing slash.

            String oldChannelUri;
            String objUri;

            oldChannelUri = HttpChannelHelper.ParseURL(url, out objUri);
            InternalRemotingServices.RemotingAssert(oldChannelUri != null, "http url expected.");
            InternalRemotingServices.RemotingAssert(objUri != null, "non-null objUri expected.");

            return(channelUri + objUri);
        } // ReplaceChannelUriWithThisString
Example #10
0
        private string GetRequestUriForCurrentRequest(HttpContext context)
        {
            string str3;
            string rawUrl = context.Request.RawUrl;

            if (HttpChannelHelper.ParseURL(rawUrl, out str3) == null)
            {
                str3 = rawUrl;
            }
            string applicationName = RemotingConfiguration.ApplicationName;

            if (((applicationName != null) && (applicationName.Length > 0)) && (str3.Length > applicationName.Length))
            {
                str3 = str3.Substring(applicationName.Length + 1);
            }
            return(str3);
        }
 public void AddHookChannelUri(string channelUri)
 {
     if (this._channelData.ChannelUris != null)
     {
         throw new RemotingException(CoreChannel.GetResourceString("Remoting_Http_LimitListenerOfOne"));
     }
     if (this._forcedMachineName != null)
     {
         channelUri = HttpChannelHelper.ReplaceMachineNameWithThisString(channelUri, this._forcedMachineName);
     }
     else if (this._bUseIpAddress)
     {
         channelUri = HttpChannelHelper.ReplaceMachineNameWithThisString(channelUri, CoreChannel.GetMachineIp());
     }
     this._channelData.ChannelUris = new string[] { channelUri };
     this._wantsToListen           = false;
     this._bHooked = true;
 }
Example #12
0
        } // GetResponseStream

        private bool ReadFirstLine(out String verb, out String requestURI, out String version)
        {
            verb       = null;
            requestURI = null;
            version    = null;

            verb = ReadToChar(' ', s_validateVerbDelegate);

            byte[] requestUriBytes = ReadToByte((byte)' ');
            int    decodedUriLength;

            HttpChannelHelper.DecodeUriInPlace(requestUriBytes, out decodedUriLength);
            requestURI = Encoding.UTF8.GetString(requestUriBytes, 0, decodedUriLength);

            version = ReadToEndOfLine();

            return(true);
        } // ReadFirstLine
Example #13
0
        private bool CanServiceRequest(HttpContext context)
        {
            string requestUriForCurrentRequest = this.GetRequestUriForCurrentRequest(context);
            string objectUriFromRequestUri     = HttpChannelHelper.GetObjectUriFromRequestUri(requestUriForCurrentRequest);

            context.Items["__requestUri"] = requestUriForCurrentRequest;
            if (string.Compare(context.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase) != 0)
            {
                if (RemotingServices.GetServerTypeForUri(requestUriForCurrentRequest) != null)
                {
                    return(true);
                }
            }
            else
            {
                if (context.Request.QueryString.Count != 1)
                {
                    return(false);
                }
                string[] values = context.Request.QueryString.GetValues(0);
                if ((values.Length != 1) || (string.Compare(values[0], "wsdl", StringComparison.OrdinalIgnoreCase) != 0))
                {
                    return(false);
                }
                if (string.Compare(objectUriFromRequestUri, "RemoteApplicationMetadata.rem", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return(true);
                }
                int length = requestUriForCurrentRequest.LastIndexOf('?');
                if (length != -1)
                {
                    requestUriForCurrentRequest = requestUriForCurrentRequest.Substring(0, length);
                }
                if (RemotingServices.GetServerTypeForUri(requestUriForCurrentRequest) != null)
                {
                    return(true);
                }
            }
            return(File.Exists(context.Request.PhysicalPath));
        }
        internal static string EncodeUriAsXLinkHref(string uri)
        {
            if (uri == null)
            {
                return(null);
            }
            byte[]        bytes   = Encoding.UTF8.GetBytes(uri);
            StringBuilder builder = new StringBuilder(uri.Length);

            foreach (byte num in bytes)
            {
                if (!EscapeInXLinkHref(num))
                {
                    builder.Append((char)num);
                }
                else
                {
                    builder.Append('%');
                    builder.Append(HttpChannelHelper.DecimalToCharacterHexDigit(num >> 4));
                    builder.Append(HttpChannelHelper.DecimalToCharacterHexDigit(num & 15));
                }
            }
            return(builder.ToString());
        }
        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);
        }
Example #16
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
Example #17
0
 public String Parse(String url, out String objectURI)
 {
     return(HttpChannelHelper.ParseURL(url, out objectURI));
 } // Parse
        public override int Read(byte[] buffer, int offset, int count)
        {
            int num = 0;

            while (!this._bFoundEnd && (count > 0))
            {
                if (this._bytesLeft == 0)
                {
                    while (true)
                    {
                        byte b = (byte)this._inputStream.ReadByte();
                        if (b == 13)
                        {
                            if (((ushort)this._inputStream.ReadByte()) != 10)
                            {
                                throw new RemotingException(CoreChannel.GetResourceString("Remoting_Http_ChunkedEncodingError"));
                            }
                            break;
                        }
                        int num3 = HttpChannelHelper.CharacterHexDigitToDecimal(b);
                        if ((num3 < 0) || (num3 > 15))
                        {
                            throw new RemotingException(CoreChannel.GetResourceString("Remoting_Http_ChunkedEncodingError"));
                        }
                        this._bytesLeft = (this._bytesLeft * 0x10) + num3;
                    }
                    if (this._bytesLeft == 0)
                    {
                        while (this._inputStream.ReadToEndOfLine().Length != 0)
                        {
                        }
                        this._bFoundEnd = true;
                    }
                }
                if (!this._bFoundEnd)
                {
                    int num4 = Math.Min(this._bytesLeft, count);
                    int num5 = this._inputStream.Read(buffer, offset, num4);
                    if (num5 <= 0)
                    {
                        throw new RemotingException(CoreChannel.GetResourceString("Remoting_Http_ChunkedEncodingError"));
                    }
                    this._bytesLeft -= num5;
                    count           -= num5;
                    offset          += num5;
                    num             += num5;
                    if (this._bytesLeft != 0)
                    {
                        continue;
                    }
                    char ch = (char)this._inputStream.ReadByte();
                    if (ch != '\r')
                    {
                        throw new RemotingException(CoreChannel.GetResourceString("Remoting_Http_ChunkedEncodingError"));
                    }
                    ch = (char)this._inputStream.ReadByte();
                    if (ch != '\n')
                    {
                        throw new RemotingException(CoreChannel.GetResourceString("Remoting_Http_ChunkedEncodingError"));
                    }
                }
            }
            return(num);
        }
Example #19
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            int bytesRead = 0;

            while (!_bFoundEnd && (count > 0))
            {
                // see if we need to start reading a new chunk
                if (_bytesLeft == 0)
                {
                    // this loop stops when the end of line is found
                    for (;;)
                    {
                        byte b = (byte)_inputStream.ReadByte();

                        // see if this is the end of the length
                        if (b == '\r')
                        {
                            // This had better be '\n'
                            if ((char)_inputStream.ReadByte() != '\n')
                            {
                                throw new RemotingException(
                                          CoreChannel.GetResourceString(
                                              "Remoting_Http_ChunkedEncodingError"));
                            }
                            else
                            {
                                break; // we've finished reading the length
                            }
                        }
                        else
                        {
                            int value = HttpChannelHelper.CharacterHexDigitToDecimal(b);
                            // make sure value is a hex-digit
                            if ((value < 0) || (value > 15))
                            {
                                throw new RemotingException(
                                          CoreChannel.GetResourceString(
                                              "Remoting_Http_ChunkedEncodingError"));
                            }

                            // update _bytesLeft value to account for new digit on the right
                            _bytesLeft = (_bytesLeft * 16) + value;
                        }
                    }

                    if (_bytesLeft == 0)
                    {
                        // read off trailing headers and end-line
                        String trailerHeader;
                        do
                        {
                            trailerHeader = _inputStream.ReadToEndOfLine();
                        } while (!(trailerHeader.Length == 0));

                        _bFoundEnd = true;
                    }
                }

                if (!_bFoundEnd)
                {
                    int readCount         = min(_bytesLeft, count);
                    int bytesReadThisTime = _inputStream.Read(buffer, offset, readCount);
                    if (bytesReadThisTime <= 0)
                    {
                        throw new RemotingException(
                                  CoreChannel.GetResourceString(
                                      "Remoting_Http_ChunkedEncodingError"));
                    }

                    _bytesLeft -= bytesReadThisTime;
                    count      -= bytesReadThisTime;
                    offset     += bytesReadThisTime;
                    bytesRead  += bytesReadThisTime;

                    // see if the end of the chunk was found
                    if (_bytesLeft == 0)
                    {
                        // read off "\r\n"
                        char ch = (char)_inputStream.ReadByte();
                        if (ch != '\r')
                        {
                            throw new RemotingException(
                                      CoreChannel.GetResourceString(
                                          "Remoting_Http_ChunkedEncodingError"));
                        }
                        ch = (char)_inputStream.ReadByte();
                        if (ch != '\n')
                        {
                            throw new RemotingException(
                                      CoreChannel.GetResourceString(
                                          "Remoting_Http_ChunkedEncodingError"));
                        }
                    }
                }
            } // while (count > 0)

            return(bytesRead);
        } // Read
 public string Parse(string url, out string objectURI)
 {
     return(HttpChannelHelper.ParseURL(url, out objectURI));
 }
Example #21
0
        } // ValidateVerbCharacter

        // read headers
        public BaseTransportHeaders ReadHeaders()
        {
            bool bSendContinue = false;

            BaseTransportHeaders headers = new BaseTransportHeaders();

            // read first line
            String verb, requestURI, version;

            ReadFirstLine(out verb, out requestURI, out version);

            if ((verb == null) || (requestURI == null) || (version == null))
            {
                throw new RemotingException(
                          CoreChannel.GetResourceString(
                              "Remoting_Http_UnableToReadFirstLine"));
            }

            if (version.Equals("HTTP/1.1")) // most common case
            {
                _version = HttpVersion.V1_1;
            }
            else
            if (version.Equals("HTTP/1.0"))
            {
                _version = HttpVersion.V1_0;
            }
            else
            {
                _version = HttpVersion.V1_1; // (assume it will understand 1.1)
            }
            if (_version == HttpVersion.V1_1)
            {
                _allowChunkedResponse = true;
                _keepAlive            = true;
            }
            else // it's a 1.0 client
            {
                _allowChunkedResponse = false;
                _keepAlive            = false;
            }


            // update request uri to be sure that it has no channel data
            String channelURI;
            String objectURI;

            channelURI = HttpChannelHelper.ParseURL(requestURI, out objectURI);
            if (channelURI == null)
            {
                objectURI = requestURI;
            }

            headers["__RequestVerb"] = verb;
            headers.RequestUri       = objectURI;
            headers["__HttpVersion"] = version;

            // check to see if we must send continue
            if ((_version == HttpVersion.V1_1) &&
                (verb.Equals("POST") || verb.Equals("PUT")))
            {
                bSendContinue = true;
            }

            ReadToEndOfHeaders(headers, out _chunkedEncoding, out _contentLength,
                               ref _keepAlive, ref bSendContinue);

            if (bSendContinue && (_version != HttpVersion.V1_0))
            {
                SendContinue();
            }

            // add IP address and Connection Id to headers
            headers[CommonTransportKeys.IPAddress]    = ((IPEndPoint)NetSocket.RemoteEndPoint).Address;
            headers[CommonTransportKeys.ConnectionId] = _connectionId;

            return(headers);
        } // ReadHeaders