public void Parse() { // Request = Request-Line // *(( general-header // | request-header // | entity-header ) CRLF) // CRLF // [ message-body ] HeaderOctetsCount = GetHeaderOctetsCount(); string header = Encoding.UTF8.GetString(OriginalHttpResponseBytes, 0, HeaderOctetsCount); int headerLength = header.Length; int statusLineLength = header.IndexOf(CRLF, StringComparison.Ordinal) + CRLF.Length; string statusLine = header.Substring(0, statusLineLength); ParseStatusLine(statusLine); int headersLength = headerLength - statusLineLength; string headers = header.Substring(statusLineLength, headersLength); // sometimes lacks end tag if (!headers.EndsWith(HeaderEndTag)) { headers += HeaderEndTag; } ParseHeaders(headers); Content = OriginalHttpResponseBytes.Skip(HeaderOctetsCount).ToArray(); }
private int GetHeaderOctetsCount() { for (int i = 0; i < OriginalHttpResponseBytes.Length - HeaderEndTagBytes.Length; i++) { if (OriginalHttpResponseBytes.Skip(i).Take(HeaderEndTag.Length).SequenceEqual(HeaderEndTagBytes)) { return(i + HeaderEndTagBytes.Length); } } // no end tag return(OriginalHttpResponseBytes.Length); }