/// <summary>
        /// Drains the response until <see cref="HttpReadType.EndOfStream"/> or a maximum amount of content is read.
        /// </summary>
        /// <param name="maximumContentSize">The maximum content to drain before returning false.</param>
        /// <param name="cancellationToken">A cancellation token for the asynchronous operation.</param>
        /// <returns>
        /// If the request was fully drained, true.
        /// Otherwise, false.
        /// </returns>
        public async ValueTask <bool> DrainAsync(int maximumContentSize, CancellationToken cancellationToken = default)
        {
            byte[]? readBuffer = null;

            HttpReadType readType = _request.ReadType;

            while (true)
            {
                switch (readType)
                {
                case HttpReadType.Content:
                    readBuffer ??= ArrayPool <byte> .Shared.Rent(8192);

                    int readLen;
                    while ((readLen = await _request.ReadContentAsync(_requestVersion, readBuffer, cancellationToken).ConfigureAwait(false)) != 0)
                    {
                        maximumContentSize -= readLen;
                        if (maximumContentSize < 0)
                        {
                            return(false);
                        }
                    }
                    break;

                case HttpReadType.EndOfStream:
                    if (readBuffer != null)
                    {
                        ArrayPool <byte> .Shared.Return(readBuffer);
                    }
                    return(true);
                }
                readType = await _request.ReadAsync(_requestVersion, cancellationToken).ConfigureAwait(false);
            }
        }
        /// <summary>
        /// Drains the response until <see cref="HttpReadType.EndOfStream"/> is reached.
        /// </summary>
        /// <param name="cancellationToken">A cancellation token for the asynchronous operation.</param>
        /// <returns>A <see cref="ValueTask"/> representing the asynchronous operation.</returns>
        public async ValueTask DrainAsync(CancellationToken cancellationToken = default)
        {
            HttpReadType currentReadType = ReadType;

            while (currentReadType != HttpReadType.EndOfStream)
            {
                currentReadType = await _request.ReadAsync(_requestVersion, cancellationToken).ConfigureAwait(false);
            }
        }
示例#3
0
        public PdfResult(PdfLoadedDocument pdfLoadedDocument, string filename, HttpResponse respone, HttpReadType type)
        {
            m_pdfDocument = null;

            m_pdfLoadedDocument = pdfLoadedDocument;

            FileName = filename;

            Response = respone;

            ReadType = type;
        }
            protected internal override async ValueTask <HttpReadType> ReadAsync(int version, CancellationToken cancellationToken)
            {
                ThrowIfDisposed(version);

                HttpReadType readType = await _request.ReadAsync(cancellationToken).ConfigureAwait(false);

                ReadType = readType;

                if (readType == HttpReadType.FinalResponse)
                {
                    StatusCode = _request.StatusCode;
                    Version    = _request.Version;
                }

                return(readType);
            }
        /// <summary>
        /// Reads until a <see cref="HttpReadType.TrailingHeaders"/> is encountered.
        /// </summary>
        /// <param name="cancellationToken">A cancellation token for the asynchronous operation.</param>
        /// <returns>
        /// If trailing headers were found before end of stream, true.
        /// Otherwise, false.
        /// </returns>
        public async ValueTask <bool> ReadToTrailingHeadersAsync(CancellationToken cancellationToken = default)
        {
            HttpReadType readType = _request.ReadType;

            while (true)
            {
                switch (readType)
                {
                case HttpReadType.TrailingHeaders:
                    return(true);

                case HttpReadType.EndOfStream:
                    return(false);
                }
                readType = await _request.ReadAsync(_requestVersion, cancellationToken).ConfigureAwait(false);
            }
        }
        /// <summary>
        /// Reads until the final <see cref="HttpReadType.Response"/> is encountered, skipping any informational responses.
        /// </summary>
        /// <param name="cancellationToken">A cancellation token for the asynchronous operation.</param>
        /// <returns>
        /// If a response was found before end of stream, true.
        /// Otherwise, false.
        /// </returns>
        public async ValueTask <bool> ReadToFinalResponseAsync(CancellationToken cancellationToken = default)
        {
            HttpReadType readType = _request.ReadType;

            while (true)
            {
                switch (readType)
                {
                case HttpReadType.Response:
                    if ((int)_request.StatusCode >= 200)
                    {
                        return(true);
                    }
                    break;

                case HttpReadType.Headers:
                case HttpReadType.Content:
                case HttpReadType.TrailingHeaders:
                case HttpReadType.EndOfStream:
                    return(false);
                }
                readType = await _request.ReadAsync(_requestVersion, cancellationToken).ConfigureAwait(false);
            }
        }
 public static PdfResult ExportAsActionResult(this PdfLoadedXfaDocument pdfdoc, string filename, HttpResponse response, HttpReadType type, bool isxfa)
 {
     return(new PdfResult(pdfdoc, filename, response, type, isxfa));
 }
 public static PdfResult ExportAsActionResult(this PdfXfaDocument PdfDoc, string filename, PdfXfaType xfaType, HttpResponse response, HttpReadType type)
 {
     return(new PdfResult(PdfDoc, filename, xfaType, response, type));
 }
示例#9
0
 public PdfResult(PdfLoadedXfaDocument pdfLoadedDocument, string filename, HttpResponse respone, HttpReadType type, bool isxfa)
 {
     this.m_pdfDocument       = null;
     this.m_loadedXfaDocument = pdfLoadedDocument;
     this.m_xfaDocument       = null;
     this.m_pdfDocument       = null;
     this.m_pdfLoadedDocument = null;
     this.FileName            = filename;
     this.m_response          = respone;
     this.ReadType            = type;
 }
        protected void ExportAsImage(System.Drawing.Image image, string fileName, ImageFormat imageFormat, HttpResponse response, HttpReadType type)
        {
            if (ControllerContext == null)
            {
                throw new ArgumentNullException("Context");
            }
            string disposition = "content-disposition";

            if (type == HttpReadType.Open)
            {
                response.AddHeader(disposition, "inline; filename=" + fileName);
            }
            else if (type == HttpReadType.Save)
            {
                response.AddHeader(disposition, "attachment; filename=\"" + fileName + "\"");
            }
            image.Save(Response.OutputStream, imageFormat);
            Response.End();
        }