示例#1
0
        /// <summary>
        /// ボディー終端処理
        /// </summary>
        private void TerminateBody()
        {
            if (this.part != ParsePart.Body)
            {
                return;
            }

            if ((this.Headers.IsChunked || this.Headers.ContentLength.Exists) &&
                this.messageBody?.IsTerminated != true)
            {
                // RFC7230 3.4
                // Content-Length、Chunked に満たない場合は不完全なメッセージとして TCP Close する(その後 Resume されたりする)
                throw new IncompleteBodyException();
            }

            this.Body = this.messageBody.Body;
            HttpHeaders.TryParse(this.messageBody.Trailers, out var trailers);
            this.Trailers = trailers;

            this.messageBody.Dispose();
            this.messageBody = null;

            this.part = ParsePart.StartLine;
            this.InvokeReceivedBody();
        }
示例#2
0
        /// <summary>
        /// スタートラインデータを入力
        /// </summary>
        /// <param name="buffer">入力データ</param>
        private void InputStartLine(byte[] buffer)
        {
            if (buffer.Length < 1)
            {
                return;
            }

            foreach (var b in buffer)
            {
                this.startLineStream.WriteByte(b);
            }

            // StartLine, Headers の行終端は LF だけで識別して良い RFC7230 3.5
            if (buffer[buffer.Length - 1] != this.LF)
            {
                return;
            }

            this.startLine = Encoding.ASCII.GetString(this.startLineStream.ToArray());

            // StartLine に先行する空行は無視すべき RFC7230 3.5
            if (this.startLine.Trim().Length == 0)
            {
                this.startLineStream.Dispose();
                this.startLineStream = new MemoryStream();
                return;
            }

            this.startLineStream.Dispose();
            this.ParseStartLine(this.startLine);
            this.startLineStream = new MemoryStream();
            this.part            = ParsePart.Headers;
        }
示例#3
0
            public void Parse()
            {
                ParsePart parseFunc = ReadUnknown;

                for (pos = 0; pos < _fileContent.Length; pos++)
                {
                    parseFunc = parseFunc(_fileContent[pos]);
                }
            }
示例#4
0
            public void Parse(string aFileContent = null)
            {
                _fileContent = aFileContent ?? File.ReadAllText(FileName, ConfigFile.GetEncoding());

                ParsePart parseFunc = ReadUnknown;

                for (pos = 0; pos < _fileContent.Length; pos++)
                {
                    parseFunc = parseFunc(_fileContent[pos]);
                }

                if (_fileContent.Length > 0 && !_fileContent.EndsWith("\n"))
                {
                    parseFunc('\n');
                }
            }
示例#5
0
        /// <summary>
        /// ヘッダー終端処理
        /// </summary>
        private void TerminateHeaders()
        {
            this.ParseHeaders(Encoding.ASCII.GetString(this.headersStream.ToArray()));
            this.headersStream.Dispose();
            this.headersStream = new MemoryStream();

            this.InvokeReceivedHeaders();

            if (this.Headers.TransferEncoding.Exists ||
                this.Headers.ContentLength.Exists && 0 < this.Headers.ContentLength.Value)
            {
                // RFC7230 3.3.3
                // Transfer-Encoding, Content-Length 両方ある場合は TransferEncoding を使用する
                if (this.Headers.IsChunked)
                {
                    this.messageBody = new ChunkedBodyParser(this.isCaptureBody, this.maxCaptureSize);
                }
                else if (this.Headers.TransferEncoding.Exists)
                {
                    // RFC7230 3.3.3
                    // TransferEncoding があり chunked でないレスポンスの場合は Close により終端が決定される
                    this.messageBody = new TerminateWithCloseBodyParser(this.isCaptureBody, this.maxCaptureSize);
                }
                else if (this.Headers.ContentLength.Exists)
                {
                    this.messageBody = new ContentLengthBodyParser(this.isCaptureBody, this.maxCaptureSize, this.Headers.ContentLength.Value);
                }
                this.part = ParsePart.Body;
            }
            else
            {
                // 空の Body として扱う
                this.messageBody = new EmptyBodyParser();
                this.InvokeReceivedBody();
                this.part = ParsePart.StartLine;
            }
        }