} // OnInputStreamClosed

        public BaseTransportHeaders ReadHeaders()
        {
            BaseTransportHeaders headers = new BaseTransportHeaders();

            UInt16 operation;

            ReadVersionAndOperation(out operation);

            // At this point, we're always expecting a Reply, so check for that.
            if (operation != TcpOperations.Reply)
            {
                throw new RemotingException(
                          String.Format(
                              CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Tcp_ExpectingReplyOp"),
                              operation.ToString(CultureInfo.CurrentCulture)));
            }

            // content length must come next (may be chunked or a specific length)
            ReadContentLength(out _bChunked, out _contentLength);

            // read to end of headers
            ReadToEndOfHeaders(headers);

            return(headers);
        } // ReadHeaders
Ejemplo n.º 2
0
        public ITransportHeaders ReadHeaders()
        {
            ushort num;
            BaseTransportHeaders headers = new BaseTransportHeaders();

            base.ReadVersionAndOperation(out num);
            switch (num)
            {
            case 0:
                this._bOneWayRequest = false;
                break;

            case 1:
                this._bOneWayRequest = true;
                break;

            default:
                throw new RemotingException(string.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Tcp_ExpectingRequestOp"), new object[] { num.ToString(CultureInfo.CurrentCulture) }));
            }
            base.ReadContentLength(out this._bChunked, out this._contentLength);
            base.ReadToEndOfHeaders(headers);
            headers.IPAddress    = ((IPEndPoint)base.NetSocket.RemoteEndPoint).Address;
            headers.ConnectionId = this._connectionId;
            return(headers);
        }
        } // HttpSocketHandler


        protected void ReadToEndOfHeaders(BaseTransportHeaders headers, 
                                          out bool bChunked,
                                          out int contentLength,
                                          ref bool bKeepAlive,
                                          ref bool bSendContinue)
        {
            bChunked = false;
            contentLength = 0;
        
            // read and process headers
            for (;;)
            {
                String header = ReadToEndOfLine();

                // stop reading headers at first blank line
                if (header.Length == 0)
                    break;
                
                int sep = header.IndexOf(":");
                String headerName = header.Substring(0,sep);
                String headerValue = header.Substring(sep+1+1); // skip semi-colon and space

                if (String.Compare(headerName, "Transfer-Encoding", StringComparison.OrdinalIgnoreCase) == 0)          
                {
                    if (String.Compare(headerValue, "chunked", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        bChunked = true;
                    }
                }
                else
                if (String.Compare(headerName, "Connection", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    if (String.Compare(headerValue, "Keep-Alive", StringComparison.OrdinalIgnoreCase) == 0)
                        bKeepAlive = true;
                    else
                    if (String.Compare(headerValue, "Close", StringComparison.OrdinalIgnoreCase) == 0)
                        bKeepAlive = false;
                }
                else
                if (String.Compare(headerName, "Expect", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    if (String.Compare(headerValue, "100-continue", StringComparison.OrdinalIgnoreCase) == 0)
                        bSendContinue = true;
                }
                else
                if (String.Compare(headerName, "Content-Length", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    contentLength = Int32.Parse(headerValue, CultureInfo.InvariantCulture);
                }
                else
                {                
                    headers[headerName] = headerValue;
                }
            }
        } // ReadToEndOfHeaders
        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);
        }
Ejemplo n.º 5
0
        } // ReadToEndOfHeaders

        protected void WriteHeaders(ITransportHeaders headers, Stream outputStream)
        {
            IEnumerator          it        = null;
            BaseTransportHeaders wkHeaders = headers as BaseTransportHeaders;

            if (wkHeaders != null)
            {
                // write out well known headers
                //   NOTE: RequestUri is written out elsewhere.

                if (wkHeaders.ContentType != null)
                {
                    WriteContentTypeHeader(wkHeaders.ContentType, outputStream);
                }

                it = wkHeaders.GetOtherHeadersEnumerator();
            }
            else
            {
                it = headers.GetEnumerator();
            }


            // write custom headers
            if (it != null)
            {
                while (it.MoveNext())
                {
                    DictionaryEntry header = (DictionaryEntry)it.Current;

                    String headerName = (String)header.Key;

                    if (!StringHelper.StartsWithDoubleUnderscore(headerName)) // exclude special headers
                    {
                        String headerValue = header.Value.ToString();

                        if (wkHeaders == null)
                        {
                            if (String.Compare(headerName, "Content-Type", StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                WriteContentTypeHeader(headerValue, outputStream);
                                continue;
                            }
                        }

                        WriteCustomHeader(headerName, headerValue, outputStream);
                    }
                } // while (it.MoveNext())
            }

            // write EndOfHeaders token
            WriteUInt16(TcpHeaders.EndOfHeaders, outputStream);
        } // WriteHeaders
Ejemplo n.º 6
0
        public BaseTransportHeaders ReadHeaders()
        {
            ushort num;
            BaseTransportHeaders headers = new BaseTransportHeaders();

            base.ReadVersionAndOperation(out num);
            if (num != 2)
            {
                throw new RemotingException(string.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Tcp_ExpectingReplyOp"), new object[] { num.ToString(CultureInfo.CurrentCulture) }));
            }
            base.ReadContentLength(out this._bChunked, out this._contentLength);
            base.ReadToEndOfHeaders(headers);
            return(headers);
        }
Ejemplo n.º 7
0
 protected void ReadToEndOfHeaders(BaseTransportHeaders headers, out bool bChunked, out int contentLength, ref bool bKeepAlive, ref bool bSendContinue)
 {
     bChunked      = false;
     contentLength = 0;
     while (true)
     {
         string str = base.ReadToEndOfLine();
         if (str.Length == 0)
         {
             return;
         }
         int    index = str.IndexOf(":");
         string strA  = str.Substring(0, index);
         string str3  = str.Substring((index + 1) + 1);
         if (string.Compare(strA, "Transfer-Encoding", StringComparison.OrdinalIgnoreCase) == 0)
         {
             if (string.Compare(str3, "chunked", StringComparison.OrdinalIgnoreCase) == 0)
             {
                 bChunked = true;
             }
         }
         else if (string.Compare(strA, "Connection", StringComparison.OrdinalIgnoreCase) == 0)
         {
             if (string.Compare(str3, "Keep-Alive", StringComparison.OrdinalIgnoreCase) == 0)
             {
                 bKeepAlive = true;
             }
             else if (string.Compare(str3, "Close", StringComparison.OrdinalIgnoreCase) == 0)
             {
                 bKeepAlive = false;
             }
         }
         else if (string.Compare(strA, "Expect", StringComparison.OrdinalIgnoreCase) == 0)
         {
             if (string.Compare(str3, "100-continue", StringComparison.OrdinalIgnoreCase) == 0)
             {
                 bSendContinue = true;
             }
         }
         else if (string.Compare(strA, "Content-Length", StringComparison.OrdinalIgnoreCase) == 0)
         {
             contentLength = int.Parse(str3, CultureInfo.InvariantCulture);
         }
         else
         {
             headers[strA] = str3;
         }
     }
 }
        internal ITransportHeaders ReadHeaders()
        {
            ushort num;
            BaseTransportHeaders headers = new BaseTransportHeaders();

            base.ReadVersionAndOperation(out num);
            if (num == 1)
            {
                this._bOneWayRequest = true;
            }
            bool chunked = false;

            base.ReadContentLength(out chunked, out this._contentLength);
            this.ReadToEndOfHeaders(headers);
            return(headers);
        }
        public void HandleRequest(HttpContext context)
        {
            IMessage             message;
            ITransportHeaders    headers2;
            Stream               stream2;
            HttpRequest          request        = context.Request;
            HttpResponse         httpResponse   = context.Response;
            BaseTransportHeaders requestHeaders = new BaseTransportHeaders();

            requestHeaders["__RequestVerb"]         = request.HttpMethod;
            requestHeaders["__CustomErrorsEnabled"] = HttpRemotingHandler.CustomErrorsEnabled(context);
            requestHeaders.RequestUri = (string)context.Items["__requestUri"];
            NameValueCollection headers = request.Headers;

            foreach (string str in headers.AllKeys)
            {
                string str2 = headers[str];
                requestHeaders[str] = str2;
            }
            requestHeaders.IPAddress = IPAddress.Parse(request.UserHostAddress);
            Stream inputStream = request.InputStream;
            ServerChannelSinkStack sinkStack = new ServerChannelSinkStack();

            sinkStack.Push(this, null);
            switch (this._nextSink.ProcessMessage(sinkStack, null, requestHeaders, inputStream, out message, out headers2, out stream2))
            {
            case ServerProcessing.Complete:
                this.SendResponse(httpResponse, 200, headers2, stream2);
                return;

            case ServerProcessing.OneWay:
                this.SendResponse(httpResponse, 0xca, headers2, stream2);
                break;

            case ServerProcessing.Async:
                break;

            default:
                return;
            }
        }
Ejemplo n.º 10
0
        internal ITransportHeaders ReadHeaders()
        {
            BaseTransportHeaders headers = new BaseTransportHeaders();

            UInt16 operation;
            ReadVersionAndOperation(out operation);

            if (operation == TcpOperations.OneWayRequest)
            {
                _bOneWayRequest = true;
            }

            bool bChunked = false;
            // content length must come next (may be chunked or a specific length)
            ReadContentLength(out bChunked, out _contentLength);

            // read to end of headers  
            ReadToEndOfHeaders(headers);   
                           
            return headers;
        }
Ejemplo n.º 11
0
        protected void WriteHeaders(ITransportHeaders headers, Stream outputStream)
        {
            IEnumerator          otherHeadersEnumerator = null;
            BaseTransportHeaders headers2 = headers as BaseTransportHeaders;

            if (headers2 != null)
            {
                if (headers2.ContentType != null)
                {
                    this.WriteContentTypeHeader(headers2.ContentType, outputStream);
                }
                otherHeadersEnumerator = headers2.GetOtherHeadersEnumerator();
            }
            else
            {
                otherHeadersEnumerator = headers.GetEnumerator();
            }
            if (otherHeadersEnumerator != null)
            {
                while (otherHeadersEnumerator.MoveNext())
                {
                    DictionaryEntry current = (DictionaryEntry)otherHeadersEnumerator.Current;
                    string          key     = (string)current.Key;
                    if (!StringHelper.StartsWithDoubleUnderscore(key))
                    {
                        string str2 = current.Value.ToString();
                        if ((headers2 == null) && (string.Compare(key, "Content-Type", StringComparison.OrdinalIgnoreCase) == 0))
                        {
                            this.WriteContentTypeHeader(str2, outputStream);
                        }
                        else
                        {
                            this.WriteCustomHeader(key, str2, outputStream);
                        }
                    }
                }
            }
            base.WriteUInt16(0, outputStream);
        }
Ejemplo n.º 12
0
        } // SendErrorMessageIfPossible

        // read headers
        public ITransportHeaders ReadHeaders()
        {
            BaseTransportHeaders headers = new BaseTransportHeaders();

            UInt16 operation;

            ReadVersionAndOperation(out operation);

            // make sure the operation is Request or OneWayRequest.
            if (operation == TcpOperations.Request)
            {
                _bOneWayRequest = false;
            }
            else
            if (operation == TcpOperations.OneWayRequest)
            {
                _bOneWayRequest = true;
            }
            else
            {
                throw new RemotingException(
                          String.Format(
                              CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Tcp_ExpectingRequestOp"),
                              operation.ToString(CultureInfo.CurrentCulture)));
            }

            // content length must come next (may be chunked or a specific length)
            ReadContentLength(out _bChunked, out _contentLength);

            // read to end of headers
            ReadToEndOfHeaders(headers);

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

            return(headers);
        } // ReadHeaders
        internal ITransportHeaders ReadHeaders()
        {
            BaseTransportHeaders headers = new BaseTransportHeaders();

            UInt16 operation;

            ReadVersionAndOperation(out operation);

            if (operation == TcpOperations.OneWayRequest)
            {
                _bOneWayRequest = true;
            }

            bool bChunked = false;

            // content length must come next (may be chunked or a specific length)
            ReadContentLength(out bChunked, out _contentLength);

            // read to end of headers
            ReadToEndOfHeaders(headers);

            return(headers);
        }
        } // OnInputStreamClosed



        public BaseTransportHeaders ReadHeaders()
        {           
            BaseTransportHeaders headers = new BaseTransportHeaders();

            UInt16 operation;
            ReadVersionAndOperation(out operation);

            // At this point, we're always expecting a Reply, so check for that.
            if (operation != TcpOperations.Reply)
            {
                throw new RemotingException(
                    String.Format(
                        CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Tcp_ExpectingReplyOp"),
                        operation.ToString(CultureInfo.CurrentCulture)));
            }                        
                   
            // content length must come next (may be chunked or a specific length)
            ReadContentLength(out _bChunked, out _contentLength);
            
            // read to end of headers  
            ReadToEndOfHeaders(headers); 
                               
            return headers;
        } // ReadHeaders  
Ejemplo n.º 15
0
        protected void ReadToEndOfHeaders(BaseTransportHeaders headers)
        {
            bool   flag = false;
            string str  = null;

            for (ushort i = base.ReadUInt16(); i != 0; i = base.ReadUInt16())
            {
                switch (i)
                {
                case 1:
                {
                    string str2 = this.ReadCountedString();
                    string str3 = this.ReadCountedString();
                    headers[str2] = str3;
                    break;
                }

                case 4:
                {
                    string str6;
                    this.ReadAndVerifyHeaderFormat("RequestUri", 1);
                    string url = this.ReadCountedString();
                    if (TcpChannelHelper.ParseURL(url, out str6) == null)
                    {
                        str6 = url;
                    }
                    headers.RequestUri = str6;
                    break;
                }

                case 2:
                    this.ReadAndVerifyHeaderFormat("StatusCode", 3);
                    if (base.ReadUInt16() != 0)
                    {
                        flag = true;
                    }
                    break;

                case 3:
                    this.ReadAndVerifyHeaderFormat("StatusPhrase", 1);
                    str = this.ReadCountedString();
                    break;

                case 6:
                {
                    this.ReadAndVerifyHeaderFormat("Content-Type", 1);
                    string str7 = this.ReadCountedString();
                    headers.ContentType = str7;
                    break;
                }

                default:
                {
                    byte num3 = (byte)base.ReadByte();
                    switch (num3)
                    {
                    case 1:
                    {
                        this.ReadCountedString();
                        continue;
                    }

                    case 2:
                    {
                        base.ReadByte();
                        continue;
                    }

                    case 3:
                    {
                        base.ReadUInt16();
                        continue;
                    }

                    case 4:
                    {
                        base.ReadInt32();
                        continue;
                    }
                    }
                    throw new RemotingException(string.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Tcp_UnknownHeaderType"), new object[] { i, num3 }));
                }
                }
            }
            if (flag)
            {
                if (str == null)
                {
                    str = "";
                }
                throw new RemotingException(string.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Tcp_GenericServerError"), new object[] { str }));
            }
        }
        } // HttpHandlerTransportSink

        public void HandleRequest(HttpContext context)
        {
            HttpRequest  httpRequest  = context.Request;
            HttpResponse httpResponse = context.Response;

            // get headers
            BaseTransportHeaders requestHeaders = new BaseTransportHeaders();

            requestHeaders["__RequestVerb"]         = httpRequest.HttpMethod;
            requestHeaders["__CustomErrorsEnabled"] = HttpRemotingHandler.CustomErrorsEnabled(context);
            requestHeaders.RequestUri = (string)context.Items["__requestUri"];

            NameValueCollection headers = httpRequest.Headers;

            String[] allKeys = headers.AllKeys;

            for (int httpKeyCount = 0; httpKeyCount < allKeys.Length; httpKeyCount++)
            {
                String headerName  = allKeys[httpKeyCount];
                String headerValue = headers[headerName];
                requestHeaders[headerName] = headerValue;
            }

            // add ip address to headers list
            requestHeaders.IPAddress = IPAddress.Parse(httpRequest.UserHostAddress);

            // get request stream
            Stream requestStream = httpRequest.InputStream;

            // process message
            ServerChannelSinkStack sinkStack = new ServerChannelSinkStack();

            sinkStack.Push(this, null);

            IMessage          responseMessage;
            ITransportHeaders responseHeaders;
            Stream            responseStream;

            ServerProcessing processing =
                _nextSink.ProcessMessage(sinkStack, null, requestHeaders, requestStream,
                                         out responseMessage,
                                         out responseHeaders, out responseStream);

            // handle response
            switch (processing)
            {
            case ServerProcessing.Complete:
            {
                // Send the response. Call completed synchronously.
                SendResponse(httpResponse, 200, responseHeaders, responseStream);
                break;
            } // case ServerProcessing.Complete

            case ServerProcessing.OneWay:
            {
                // Just send back a 202 Accepted
                SendResponse(httpResponse, 202, responseHeaders, responseStream);
                break;
            } // case ServerProcessing.OneWay

            case ServerProcessing.Async:
            {
                // Async dispatching was cut from V.1.
                //sinkStack.StoreAndDispatch(this, streamManager);
                break;
            } // case ServerProcessing.Async
            } // switch (processing)
        }     // HandleRequest
        } // HttpSocketHandler

        protected void ReadToEndOfHeaders(BaseTransportHeaders headers,
                                          out bool bChunked,
                                          out int contentLength,
                                          ref bool bKeepAlive,
                                          ref bool bSendContinue)
        {
            bChunked      = false;
            contentLength = 0;

            // read and process headers
            for (;;)
            {
                String header = ReadToEndOfLine();

                // stop reading headers at first blank line
                if (header.Length == 0)
                {
                    break;
                }

                int    sep         = header.IndexOf(":");
                String headerName  = header.Substring(0, sep);
                String headerValue = header.Substring(sep + 1 + 1); // skip semi-colon and space

                if (String.Compare(headerName, "Transfer-Encoding", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    if (String.Compare(headerValue, "chunked", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        bChunked = true;
                    }
                }
                else
                if (String.Compare(headerName, "Connection", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    if (String.Compare(headerValue, "Keep-Alive", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        bKeepAlive = true;
                    }
                    else
                    if (String.Compare(headerValue, "Close", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        bKeepAlive = false;
                    }
                }
                else
                if (String.Compare(headerName, "Expect", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    if (String.Compare(headerValue, "100-continue", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        bSendContinue = true;
                    }
                }
                else
                if (String.Compare(headerName, "Content-Length", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    contentLength = Int32.Parse(headerValue, CultureInfo.InvariantCulture);
                }
                else
                {
                    headers[headerName] = headerValue;
                }
            }
        } // ReadToEndOfHeaders
        protected new void ReadToEndOfHeaders(BaseTransportHeaders headers)
        {
            bool   bError       = false;
            String statusPhrase = null;

            UInt16 headerType = ReadUInt16();

            while (headerType != TcpHeaders.EndOfHeaders)
            {
                if (headerType == TcpHeaders.Custom)
                {
                    String headerName  = ReadCountedString();
                    String headerValue = ReadCountedString();

                    headers[headerName] = headerValue;
                }
                else
                if (headerType == TcpHeaders.RequestUri)
                {
                    ReadAndVerifyHeaderFormat("RequestUri", TcpHeaderFormat.CountedString);

                    // read uri (and make sure that no channel specific data is present)
                    String uri = ReadCountedString();

                    String channelURI;
                    String objectURI;
                    channelURI = IpcChannelHelper.ParseURL(uri, out objectURI);
                    if (channelURI == null)
                    {
                        objectURI = uri;
                    }

                    headers.RequestUri = objectURI;
                }
                else
                if (headerType == TcpHeaders.StatusCode)
                {
                    ReadAndVerifyHeaderFormat("StatusCode", TcpHeaderFormat.UInt16);

                    UInt16 statusCode = ReadUInt16();
                    // We'll throw an exception here if there was an error. If an error
                    //   occurs above the transport level, the status code will still be
                    //   success here.
                    if (statusCode != TcpStatusCode.Success)
                    {
                        bError = true;
                    }
                }
                else
                if (headerType == TcpHeaders.StatusPhrase)
                {
                    ReadAndVerifyHeaderFormat("StatusPhrase", TcpHeaderFormat.CountedString);

                    statusPhrase = ReadCountedString();
                }
                else
                if (headerType == TcpHeaders.ContentType)
                {
                    ReadAndVerifyHeaderFormat("Content-Type", TcpHeaderFormat.CountedString);

                    String contentType = ReadCountedString();
                    headers.ContentType = contentType;
                }
                else
                {
                    // unknown header: Read header format and ignore rest of data
                    byte headerFormat = (byte)ReadByte();

                    switch (headerFormat)
                    {
                    case TcpHeaderFormat.Void: break;

                    case TcpHeaderFormat.CountedString: ReadCountedString(); break;

                    case TcpHeaderFormat.Byte: ReadByte(); break;

                    case TcpHeaderFormat.UInt16: ReadUInt16(); break;

                    case TcpHeaderFormat.Int32: ReadInt32(); break;

                    default:
                    {
                        // unknown format
                        throw new RemotingException(
                                  String.Format(
                                      CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Tcp_UnknownHeaderType"),
                                      headerType, headerFormat));
                    }
                    } // switch (format)
                }

                // read next header token
                headerType = ReadUInt16();
            } // loop until end of headers

            // if an error occurred, throw an exception
            if (bError)
            {
                if (statusPhrase == null)
                {
                    statusPhrase = "";
                }

                throw new RemotingException(
                          String.Format(
                              CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Tcp_GenericServerError"),
                              statusPhrase));
            }
        } // ReadToEndOfHeaders
Ejemplo n.º 19
0
        } // SendErrorMessageIfPossible
            

        // read headers
        public ITransportHeaders ReadHeaders()
        {        
            BaseTransportHeaders headers = new BaseTransportHeaders();

            UInt16 operation;
            ReadVersionAndOperation(out operation);

            // make sure the operation is Request or OneWayRequest.
            if (operation == TcpOperations.Request)
            {
                _bOneWayRequest = false;
            }
            else
            if (operation == TcpOperations.OneWayRequest)
            {
                _bOneWayRequest = true;
            }
            else
            {
                throw new RemotingException(
                    String.Format(
                        CoreChannel.GetResourceString("Remoting_Tcp_ExpectingRequestOp"),
                        operation.ToString()));
            }            

            // content length must come next (may be chunked or a specific length)
            ReadContentLength(out _bChunked, out _contentLength);

            // read to end of headers  
            ReadToEndOfHeaders(headers);   
                           
            // add IP address and Connection Id to headers
            headers.IPAddress = ((IPEndPoint)NetSocket.RemoteEndPoint).Address;
            headers.ConnectionId = _connectionId;
            
            return headers;
        } // ReadHeaders
Ejemplo n.º 20
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
Ejemplo n.º 21
0
        } // ReadContentLength 


        protected void ReadToEndOfHeaders(BaseTransportHeaders headers)
        {
            bool bError = false;
            String statusPhrase = null; 
        
            UInt16 headerType = ReadUInt16();
            while (headerType != TcpHeaders.EndOfHeaders)
            {
                if (headerType == TcpHeaders.Custom)
                {
                    String headerName = ReadCountedString();
                    String headerValue = ReadCountedString();

                    headers[headerName] = headerValue;
                }
                else
                if (headerType == TcpHeaders.RequestUri)
                {         
                    ReadAndVerifyHeaderFormat("RequestUri", TcpHeaderFormat.CountedString);
                
                    // read uri (and make sure that no channel specific data is present)
                    String uri = ReadCountedString();
                    
                    String channelURI;
                    String objectURI;
                    channelURI = TcpChannelHelper.ParseURL(uri, out objectURI);
                    if (channelURI == null)
                        objectURI = uri;              
            
                    headers.RequestUri = objectURI;
                }
                else
                if (headerType == TcpHeaders.StatusCode)
                {
                    ReadAndVerifyHeaderFormat("StatusCode", TcpHeaderFormat.UInt16);
                    
                    UInt16 statusCode = ReadUInt16();
                    // We'll throw an exception here if there was an error. If an error
                    //   occurs above the transport level, the status code will still be
                    //   success here.
                    if (statusCode != TcpStatusCode.Success)
                        bError = true;
                }
                else
                if (headerType == TcpHeaders.StatusPhrase)
                {
                    ReadAndVerifyHeaderFormat("StatusPhrase", TcpHeaderFormat.CountedString);
                
                    statusPhrase = ReadCountedString();
                }
                else
                if (headerType == TcpHeaders.ContentType)
                {
                    ReadAndVerifyHeaderFormat("Content-Type", TcpHeaderFormat.CountedString);
                
                    String contentType = ReadCountedString();
                    headers.ContentType = contentType;
                }
                else
                {
                    // unknown header: Read header format and ignore rest of data
                    byte headerFormat = (byte)ReadByte();

                    switch (headerFormat)
                    {
                    case TcpHeaderFormat.Void: break;
                    case TcpHeaderFormat.CountedString: ReadCountedString(); break;
                    case TcpHeaderFormat.Byte: ReadByte(); break;
                    case TcpHeaderFormat.UInt16: ReadUInt16(); break;
                    case TcpHeaderFormat.Int32: ReadInt32(); break;

                    default:
                    {
                        // unknown format
                        throw new RemotingException(
                            String.Format(
                                CoreChannel.GetResourceString("Remoting_Tcp_UnknownHeaderType"),
                                headerType, headerFormat));
                    }
                    
                    } // switch (format)
                
                }

                // read next header token
                headerType = ReadUInt16();
            } // loop until end of headers         

            // if an error occurred, throw an exception
            if (bError)
            {
                if (statusPhrase == null)
                    statusPhrase = "";
                    
                throw new RemotingException(
                    String.Format(
                        CoreChannel.GetResourceString("Remoting_Tcp_GenericServerError"),
                        statusPhrase));
            }
        } // ReadToEndOfHeaders