Exemple #1
0
        internal static string GetBoundary(string contentType)
        {
            if (string.IsNullOrEmpty(contentType))
            {
                throw new ArgumentNullException(nameof(contentType));
            }

            var elements = contentType.Split(' ');
            var element  = elements.First(entry => entry.StartsWith("boundary="));
            var boundary = new Microsoft.Extensions.Primitives.StringSegment(element.Substring("boundary=".Length));

            boundary = HeaderUtilities.RemoveQuotes(boundary);

            return(boundary.ToString());
        }
 public static int Compare(Microsoft.Extensions.Primitives.StringSegment a, Microsoft.Extensions.Primitives.StringSegment b, System.StringComparison comparisonType) => throw null;
Exemple #3
0
 public void Append(Microsoft.Extensions.Primitives.StringSegment segment)
 {
 }
 public HeaderSegment(Microsoft.Extensions.Primitives.StringSegment formatting, Microsoft.Extensions.Primitives.StringSegment data)
 {
     throw null;
 }
 public static bool TryParse(Microsoft.Extensions.Primitives.StringSegment input, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out Microsoft.Net.Http.Headers.StringWithQualityHeaderValue parsedValue)
 {
     throw null;
 }
 public static Microsoft.Net.Http.Headers.StringWithQualityHeaderValue Parse(Microsoft.Extensions.Primitives.StringSegment input)
 {
     throw null;
 }
 public SetCookieHeaderValue(Microsoft.Extensions.Primitives.StringSegment name, Microsoft.Extensions.Primitives.StringSegment value)
 {
 }
 public void SetAndEscapeValue(Microsoft.Extensions.Primitives.StringSegment value)
 {
 }
 public void SetMimeFileName(Microsoft.Extensions.Primitives.StringSegment fileName)
 {
 }
Exemple #10
0
 public static bool TryParse(Microsoft.Extensions.Primitives.StringSegment input, out Microsoft.Net.Http.Headers.StringWithQualityHeaderValue parsedValue)
 {
     throw null;
 }
 public static bool IsNullOrEmpty(Microsoft.Extensions.Primitives.StringSegment value) => throw null;
 public bool Equals(Microsoft.Extensions.Primitives.StringSegment other) => throw null;
 public bool Equals(Microsoft.Extensions.Primitives.StringSegment other, System.StringComparison comparisonType) => throw null;
 public NameValueHeaderValue(Microsoft.Extensions.Primitives.StringSegment name)
 {
 }
 public EntityTagHeaderValue(Microsoft.Extensions.Primitives.StringSegment tag, bool isWeak)
 {
 }
 public static Microsoft.Net.Http.Headers.NameValueHeaderValue?Find(System.Collections.Generic.IList <Microsoft.Net.Http.Headers.NameValueHeaderValue>?values, Microsoft.Extensions.Primitives.StringSegment name)
 {
     throw null;
 }
 public static bool IsQuoted(Microsoft.Extensions.Primitives.StringSegment input)
 {
     throw null;
 }
 public static Microsoft.Net.Http.Headers.CacheControlHeaderValue Parse(Microsoft.Extensions.Primitives.StringSegment input)
 {
     throw null;
 }
 public static Microsoft.Extensions.Primitives.StringSegment RemoveQuotes(Microsoft.Extensions.Primitives.StringSegment input)
 {
     throw null;
 }
 public StringWithQualityHeaderValue(Microsoft.Extensions.Primitives.StringSegment value, double quality)
 {
 }
 public static bool TryParseDate(Microsoft.Extensions.Primitives.StringSegment input, out System.DateTimeOffset result)
 {
     throw null;
 }
 public ContentDispositionHeaderValue(Microsoft.Extensions.Primitives.StringSegment dispositionType)
 {
 }
 public static bool TryParseNonNegativeInt64(Microsoft.Extensions.Primitives.StringSegment value, out long result)
 {
     throw null;
 }
 public ProviderCultureResult(Microsoft.Extensions.Primitives.StringSegment culture, Microsoft.Extensions.Primitives.StringSegment uiCulture)
 {
 }
 public static Microsoft.Extensions.Primitives.StringSegment UnescapeAsQuotedString(Microsoft.Extensions.Primitives.StringSegment input)
 {
     throw null;
 }
Exemple #26
0
 public static System.Text.StringBuilder Append(this System.Text.StringBuilder builder, Microsoft.Extensions.Primitives.StringSegment segment)
 {
     throw null;
 }
 public MediaTypeHeaderValue(Microsoft.Extensions.Primitives.StringSegment mediaType, double quality)
 {
 }
Exemple #28
0
 public static bool MatchesAny(Microsoft.Extensions.Primitives.StringSegment value, System.Collections.Generic.IList <Microsoft.Extensions.Primitives.StringSegment> patterns)
 {
     throw null;
 }
        public static async Task <FormValueProvider> StreamFile(this HttpRequest request, Stream targetStream, int bufferSize)
        {
            if (!MultipartRequestHelper.IsMultipartContentType(request.ContentType))
            {
                throw new Exception($"Expected a multipart request, but got {request.ContentType}");
            }

            // Used to accumulate all the form url encoded key value pairs in the
            // request.
            KeyValueAccumulator formAccumulator = new KeyValueAccumulator();
            // string targetFilePath = null;

            string boundary = MultipartRequestHelper.GetBoundary(
                MediaTypeHeaderValue.Parse(request.ContentType),
                _defaultFormOptions.MultipartBoundaryLengthLimit);
            MultipartReader reader = new MultipartReader(boundary, request.Body);

            MultipartSection section = await reader.ReadNextSectionAsync();

            while (section != null)
            {
                bool hasContentDispositionHeader = ContentDispositionHeaderValue.TryParse(section.ContentDisposition, out ContentDispositionHeaderValue contentDisposition);

                if (hasContentDispositionHeader)
                {
                    if (MultipartRequestHelper.HasFileContentDisposition(contentDisposition))
                    {
                        await section.Body.CopyToAsync(targetStream);
                    }
                    else if (MultipartRequestHelper.HasFormDataContentDisposition(contentDisposition))
                    {
                        // Content-Disposition: form-data; name="key"
                        //
                        // value

                        // Do not limit the key name length here because the
                        // multipart headers length limit is already in effect.
                        Microsoft.Extensions.Primitives.StringSegment key = HeaderUtilities.RemoveQuotes(contentDisposition.Name);
                        Encoding encoding = GetEncoding(section);
                        using (StreamReader streamReader = new StreamReader(
                                   section.Body,
                                   encoding,
                                   detectEncodingFromByteOrderMarks: true,
                                   bufferSize: bufferSize,
                                   leaveOpen: true))
                        {
                            // The value length limit is enforced by MultipartBodyLengthLimit
                            string value = await streamReader.ReadToEndAsync();

                            if (string.Equals(value, "undefined", StringComparison.OrdinalIgnoreCase))
                            {
                                value = string.Empty;
                            }
                            formAccumulator.Append(key.Value, value); // For .NET Core <2.0 remove ".Value" from key

                            if (formAccumulator.ValueCount > _defaultFormOptions.ValueCountLimit)
                            {
                                throw new InvalidDataException($"Form key count limit {_defaultFormOptions.ValueCountLimit} exceeded.");
                            }
                        }
                    }
                }

                // Drains any remaining section body that has not been consumed and
                // reads the headers for the next section.
                section = await reader.ReadNextSectionAsync();
            }

            // Bind form data to a model
            FormValueProvider formValueProvider = new FormValueProvider(
                BindingSource.Form,
                new FormCollection(formAccumulator.GetResults()),
                CultureInfo.CurrentCulture);

            return(formValueProvider);
        }