Skip to content

Commit d901f89

Browse files
committed
removed dependency on IHttpContextAccessor because HasIso8601FractionBug was always returning true anyway, and it was the only place that used it
1 parent 1bb066a commit d901f89

File tree

3 files changed

+14
-28
lines changed

3 files changed

+14
-28
lines changed

NWebDav.Server/Props/DavTypedProperties.cs

+10-23
Original file line numberDiff line numberDiff line change
@@ -188,47 +188,34 @@ public abstract class DavIso8601Date<TEntry> : DavTypedProperty<TEntry, DateTime
188188
{
189189
private readonly Iso8601DateConverter _converter;
190190

191-
protected DavIso8601Date(IHttpContextAccessor httpContextAccessor)
191+
protected DavIso8601Date()
192192
{
193-
_converter = new Iso8601DateConverter(httpContextAccessor);
193+
_converter = Iso8601DateConverter.Instance;
194194
}
195195

196196
private class Iso8601DateConverter : IConverter
197197
{
198-
private readonly IHttpContextAccessor _httpContextAccessor;
199-
200-
public Iso8601DateConverter(IHttpContextAccessor httpContextAccessor)
198+
internal static readonly Iso8601DateConverter Instance = new();
199+
Iso8601DateConverter()
201200
{
202-
_httpContextAccessor = httpContextAccessor;
203201
}
204202

205203
public object ToXml(DateTime value)
206204
{
207205
// The older built-in Windows WebDAV clients have a problem, so
208206
// they cannot deal with more than 3 digits for the
209207
// milliseconds.
210-
if (HasIso8601FractionBug)
211-
{
212-
// We need to recreate the date again, because the Windows 7
213-
// WebDAV client cannot
214-
var dt = new DateTime(value.Year, value.Month, value.Day, value.Hour, value.Minute, value.Second, value.Millisecond, DateTimeKind.Utc);
215-
return XmlConvert.ToString(dt, XmlDateTimeSerializationMode.Utc);
216-
}
217208

218-
return XmlConvert.ToString(value, XmlDateTimeSerializationMode.Utc);
209+
// P.S. I think the previous comment meant "less than 3 digits".
210+
211+
// We need to recreate the date again, because the Windows 7
212+
// WebDAV client cannot
213+
var dt = new DateTime(value.Year, value.Month, value.Day, value.Hour, value.Minute, value.Second, value.Millisecond, DateTimeKind.Utc);
214+
return XmlConvert.ToString(dt, XmlDateTimeSerializationMode.Utc);
219215
}
220216

221217
public DateTime FromXml(object value) => XmlConvert.ToDateTime((string)value, XmlDateTimeSerializationMode.Utc);
222218

223-
private bool HasIso8601FractionBug
224-
{
225-
get
226-
{
227-
var userAgent = _httpContextAccessor.HttpContext?.Request.Headers.UserAgent.FirstOrDefault();
228-
_ = userAgent; // TODO: Determine if this bug is present based on the user-agent
229-
return true;
230-
}
231-
}
232219
}
233220

234221
/// <summary>

NWebDav.Server/Props/StandardProperties.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Xml.Linq;
2-
using Microsoft.AspNetCore.Http;
32
using NWebDav.Server.Stores;
43

54
namespace NWebDav.Server.Props;
@@ -25,7 +24,7 @@ public class DavCreationDate<TEntry> : DavIso8601Date<TEntry> where TEntry : ISt
2524
// ReSharper disable once StaticMemberInGenericType
2625
public static readonly XName PropertyName = WebDavNamespaces.DavNs + "creationdate";
2726

28-
public DavCreationDate(IHttpContextAccessor httpContextAccessor) : base(httpContextAccessor)
27+
public DavCreationDate() : base()
2928
{}
3029

3130
/// <summary>

NWebDav.Server/Stores/DiskStoreCollectionPropertyManager.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ public class DiskStoreCollectionPropertyManager : PropertyManager<DiskStoreColle
1111
{
1212
private static readonly XElement s_xDavCollection = new(WebDavNamespaces.DavNs + "collection");
1313

14-
public DiskStoreCollectionPropertyManager(IHttpContextAccessor httpContextAccessor, ILockingManager lockingManager) : base(GetProperties(httpContextAccessor, lockingManager))
14+
public DiskStoreCollectionPropertyManager(ILockingManager lockingManager) : base(GetProperties(lockingManager))
1515
{
1616
}
1717

18-
private static DavProperty<DiskStoreCollection>[] GetProperties(IHttpContextAccessor httpContextAccessor, ILockingManager lockingManager) => new DavProperty<DiskStoreCollection>[]
18+
private static DavProperty<DiskStoreCollection>[] GetProperties(ILockingManager lockingManager) => new DavProperty<DiskStoreCollection>[]
1919
{
2020
// RFC-2518 properties
21-
new DavCreationDate<DiskStoreCollection>(httpContextAccessor)
21+
new DavCreationDate<DiskStoreCollection>()
2222
{
2323
Getter = collection => collection.DirectoryInfo.CreationTimeUtc,
2424
Setter = (collection, value) =>

0 commit comments

Comments
 (0)