Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cf081cd

Browse files
committedDec 4, 2015
Make Name and FileName getters lazy
It seems like both the Name and FileName does quite a bit of work in their getters. Let's fetch them lazily instead.
1 parent ecad19d commit cf081cd

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed
 

‎src/Microsoft.AspNet.Http/Features/FormFile.cs

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,24 @@
44
using System.IO;
55
using Microsoft.AspNet.Http.Internal;
66
using Microsoft.Net.Http.Headers;
7+
using static Microsoft.Net.Http.Headers.HeaderUtilities;
78

89
namespace Microsoft.AspNet.Http.Features.Internal
910
{
1011
public class FormFile : IFormFile
1112
{
1213
private readonly Stream _baseStream;
1314
private readonly long _baseStreamOffset;
15+
private readonly ContentDispositionHeaderValue _contentDisposition;
16+
private string _name;
17+
private string _fileName;
1418

1519
public FormFile(Stream baseStream, long baseStreamOffset, long length, ContentDispositionHeaderValue contentDisposition)
1620
{
1721
_baseStream = baseStream;
1822
_baseStreamOffset = baseStreamOffset;
23+
_contentDisposition = contentDisposition;
1924
Length = length;
20-
Name = HeaderUtilities.RemoveQuotes(contentDisposition.Name) ?? string.Empty;
21-
FileName = HeaderUtilities.RemoveQuotes(contentDisposition.FileName) ?? string.Empty;
2225
}
2326

2427
public string ContentDisposition
@@ -37,9 +40,9 @@ public string ContentType
3740

3841
public long Length { get; }
3942

40-
public string Name { get; }
43+
public string Name => _name ?? (_name = RemoveQuotes(_contentDisposition.Name) ?? string.Empty);
4144

42-
public string FileName { get; }
45+
public string FileName => _fileName ?? (_fileName = RemoveQuotes(_contentDisposition.FileName) ?? string.Empty);
4346

4447
public Stream OpenReadStream()
4548
{

0 commit comments

Comments
 (0)
This repository has been archived.