XmlRpc_Wrapper.HTTPHeader.Append C# (CSharp) Méthode

Append() public méthode

Either HTTPRequest contains the header AND some data, or it contains part or all of the header. Accumulate pieces of the header in case it spans multiple reads.
public Append ( string HTTPRequest ) : STATUS
HTTPRequest string
Résultat STATUS
        public STATUS Append(string HTTPRequest)
        {
            if (m_headerStatus != STATUS.COMPLETE_HEADER)
            {
                int betweenHeaderAndData = HTTPRequest.IndexOf("\r\n\r\n", StringComparison.OrdinalIgnoreCase);
                if (betweenHeaderAndData > 0)
                {
                    m_headerStatus = STATUS.COMPLETE_HEADER;
                    //found the boundary between header and data
                    m_headerSoFar += HTTPRequest.Substring(0, betweenHeaderAndData);
                    HTTPHeaderParse(m_headerSoFar);

                    //shorten the request so we can fall through
                    HTTPRequest = HTTPRequest.Substring(betweenHeaderAndData + 4);
                    //
                    // FALL THROUGH to header complete case
                    //
                }
                else
                {
                    m_headerSoFar += HTTPRequest;
                    m_headerStatus = STATUS.PARTIAL_HEADER;
                    HTTPHeaderParse(m_headerSoFar);
                    return m_headerStatus;
                }
            }

            if (m_headerStatus == STATUS.COMPLETE_HEADER)
            {
                if (ContentComplete)
                {
                    //this isn't right... restart with empty header and see if it works
                    m_headerStatus = STATUS.UNINITIALIZED;
                    Data = new byte[0];
                    DataString = "";
                    m_headerSoFar = "";
                    m_StrHTTPField.Clear();
                    return Append(HTTPRequest);
                }

                DataString += HTTPRequest;
                if (ContentComplete)
                {
                    Data = Encoding.ASCII.GetBytes(DataString);
                    XmlRpcUtil.log(XmlRpcUtil.XMLRPC_LOG_LEVEL.INFO, "DONE READING CONTENT");
                }
            }
            return m_headerStatus;
        }

Usage Example

        private bool readRequest()
        {
            int left    = header.ContentLength - header.DataString.Length;
            int dataLen = 0;

            if (left > 0)
            {
                byte[] data = new byte[left];
                try
                {
                    dataLen = stream.Read(data, 0, left);
                    if (dataLen == 0)
                    {
                        XmlRpcUtil.error("XmlRpcServerConnection::readRequest: Stream was closed");
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    XmlRpcUtil.error("XmlRpcServerConnection::readRequest: error while reading the rest of data ({0}).", ex.Message);
                    return(false);
                }
                header.Append(Encoding.ASCII.GetString(data, 0, dataLen));
            }
            // Otherwise, parse and dispatch the request
            XmlRpcUtil.log(XmlRpcUtil.XMLRPC_LOG_LEVEL.DEBUG, "XmlRpcServerConnection::readRequest read {0} bytes.", dataLen);

            if (!header.ContentComplete)
            {
                return(false);
            }
            _connectionState = ServerConnectionState.WRITE_RESPONSE;

            return(true); // Continue monitoring this source
        }
All Usage Examples Of XmlRpc_Wrapper.HTTPHeader::Append