private bool ParseHeaders() { if (!_continuation) { _headers = new Headers <RequestHeader>(2); } _continuation = false; while (true) { var maybeHeaderLine = NextLine(ResponseStatus.BadRequest.GetDescription(), "\n\nHeader is required."); if (!maybeHeaderLine.IsPresent) { return(true); } var headerLine = maybeHeaderLine.Get(); if (string.IsNullOrEmpty(headerLine)) { break; } var header = RequestHeader.FromString(headerLine); _headers.Add(header); if (_contentLength == 0) { var maybeContentLength = header.IfContentLength; if (maybeContentLength > 0) { _contentLength = maybeContentLength; } } } if (_headers.Count == 0) { throw new ArgumentException(ResponseStatus.BadRequest.GetDescription() + "\n\nHeader is required."); } return(NextStep()); }
/// <summary> /// Answer myself as <see cref="RequestHeader"/>. /// </summary> /// <returns><see cref="RequestHeader"/></returns> public RequestHeader ToRequestHeader() => RequestHeader.WithContentType(ToString());