< Summary

Information
Class: System.Net.Http.MultipartFormDataContent
Assembly: System.Net.Http
File(s): D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\MultipartFormDataContent.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 35
Coverable lines: 35
Total lines: 72
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%110%
.ctor(...)100%110%
Add(...)0%220%
Add(...)100%110%
Add(...)100%110%
AddInternal(...)0%220%
SerializeToStreamAsync(...)0%220%

File(s)

D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\MultipartFormDataContent.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Diagnostics.CodeAnalysis;
 5using System.IO;
 6using System.Net.Http.Headers;
 7using System.Threading;
 8using System.Threading.Tasks;
 9
 10namespace System.Net.Http
 11{
 12    public class MultipartFormDataContent : MultipartContent
 13    {
 14        private const string formData = "form-data";
 15
 16        public MultipartFormDataContent()
 017            : base(formData)
 018        {
 019        }
 20
 21        public MultipartFormDataContent(string boundary)
 022            : base(formData, boundary)
 023        {
 024        }
 25
 26        public override void Add(HttpContent content)
 027        {
 028            ArgumentNullException.ThrowIfNull(content);
 29
 030            content.Headers.ContentDisposition ??= new ContentDispositionHeaderValue(formData);
 31
 032            base.Add(content);
 033        }
 34
 35        public void Add(HttpContent content, string name)
 036        {
 037            ArgumentNullException.ThrowIfNull(content);
 038            ArgumentException.ThrowIfNullOrWhiteSpace(name);
 39
 040            AddInternal(content, name, null);
 041        }
 42
 43        public void Add(HttpContent content, string name, string fileName)
 044        {
 045            ArgumentNullException.ThrowIfNull(content);
 046            ArgumentException.ThrowIfNullOrWhiteSpace(name);
 047            ArgumentException.ThrowIfNullOrWhiteSpace(fileName);
 48
 049            AddInternal(content, name, fileName);
 050        }
 51
 52        private void AddInternal(HttpContent content, string name, string? fileName)
 053        {
 054            if (content.Headers.ContentDisposition == null)
 055            {
 056                ContentDispositionHeaderValue header = new ContentDispositionHeaderValue(formData);
 057                header.Name = name;
 058                header.FileName = fileName;
 059                header.FileNameStar = fileName;
 60
 061                content.Headers.ContentDisposition = header;
 062            }
 063            base.Add(content);
 064        }
 65
 66        protected override Task SerializeToStreamAsync(Stream stream, TransportContext? context, CancellationToken cance
 67            // Only skip the original protected virtual SerializeToStreamAsync if this
 68            // isn't a derived type that may have overridden the behavior.
 069            GetType() == typeof(MultipartFormDataContent) ? SerializeToStreamAsyncCore(stream, context, cancellationToke
 070            base.SerializeToStreamAsync(stream, context, cancellationToken);
 71    }
 72}