Exemple #1
0
        /// <summary>
        /// Read the request body as a form with the given options. These options will only be used
        /// if the form has not already been read.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="options">Options for reading the form.</param>
        /// <param name="cancellationToken"></param>
        /// <returns>The parsed form.</returns>
        public static Task <IFormCollection> ReadFormAsync(this ProtoRequest request, FormOptions options,
                                                           CancellationToken cancellationToken = new CancellationToken())
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (!request.HasFormContentType)
            {
                throw new InvalidOperationException("Incorrect Content-Type: " + request.ContentType);
            }

            var features    = request.ProtoContext.Features;
            var formFeature = features.Get <IFormFeature>();

            if (formFeature == null || formFeature.Form == null)
            {
                // We haven't read the form yet, replace the reader with one using our own options.
                features.Set <IFormFeature>(new FormFeature(request, options));
            }
            return(request.ReadFormAsync(cancellationToken));
        }
 public static RequestHeaders GetTypedHeaders(this ProtoRequest request)
 {
     return(new RequestHeaders(request.Headers));
 }
Exemple #3
0
 /// <summary>
 /// Ensure the <paramref name="request"/> <see cref="ProtoRequest.Body"/> can be read multiple times. Normally
 /// buffers request bodies in memory; writes requests larger than <paramref name="bufferThreshold"/> bytes to
 /// disk.
 /// </summary>
 /// <param name="request">The <see cref="ProtoRequest"/> to prepare.</param>
 /// <param name="bufferThreshold">
 /// The maximum size in bytes of the in-memory <see cref="System.Buffers.ArrayPool{Byte}"/> used to buffer the
 /// stream. Larger request bodies are written to disk.
 /// </param>
 /// <param name="bufferLimit">
 /// The maximum size in bytes of the request body. An attempt to read beyond this limit will cause an
 /// <see cref="System.IO.IOException"/>.
 /// </param>
 /// <remarks>
 /// Temporary files for larger requests are written to the location named in the <c>ASPNETCORE_TEMP</c>
 /// environment variable, if any. If that environment variable is not defined, these files are written to the
 /// current user's temporary folder. Files are automatically deleted at the end of their associated requests.
 /// </remarks>
 public static void EnableBuffering(this ProtoRequest request, int bufferThreshold, long bufferLimit)
 {
     BufferingHelper.EnableRewind(request, bufferThreshold, bufferLimit);
 }
Exemple #4
0
 /// <summary>
 /// Ensure the <paramref name="request"/> <see cref="ProtoRequest.Body"/> can be read multiple times. Normally
 /// buffers request bodies in memory; writes requests larger than 30K bytes to disk.
 /// </summary>
 /// <param name="request">The <see cref="ProtoRequest"/> to prepare.</param>
 /// <remarks>
 /// Temporary files for larger requests are written to the location named in the <c>ASPNETCORE_TEMP</c>
 /// environment variable, if any. If that environment variable is not defined, these files are written to the
 /// current user's temporary folder. Files are automatically deleted at the end of their associated requests.
 /// </remarks>
 public static void EnableBuffering(this ProtoRequest request)
 {
     BufferingHelper.EnableRewind(request);
 }