Ejemplo n.º 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();
        }
Ejemplo n.º 2
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;
            }
        }