This commit is contained in:
Brennan 2016-01-13 14:29:45 -08:00
parent 5165163c2c
commit e05469a989
2 changed files with 22 additions and 3 deletions

View File

@ -140,7 +140,7 @@ namespace Microsoft.AspNet.StaticFiles
DateTimeOffset last = _fileInfo.LastModified;
// Truncate to the second.
_lastModified = new DateTimeOffset(last.Year, last.Month, last.Day, last.Hour, last.Minute, last.Second, last.Offset);
_lastModified = new DateTimeOffset(last.Year, last.Month, last.Day, last.Hour, last.Minute, last.Second, last.Offset).ToUniversalTime();
long etagHash = _lastModified.ToFileTime() ^ _length;
_etag = new EntityTagHeaderValue('\"' + Convert.ToString(etagHash, 16) + '\"');

View File

@ -138,6 +138,8 @@ namespace Microsoft.AspNet.StaticFiles
HttpResponseMessage response = await server.CreateClient().GetAsync("http://localhost/SubFolder/extra.xml");
Assert.NotNull(response.Content.Headers.LastModified);
// Verify that DateTimeOffset is UTC
Assert.Equal(response.Content.Headers.LastModified.Value.Offset, TimeSpan.Zero);
}
// 13.3.4
@ -234,7 +236,7 @@ namespace Microsoft.AspNet.StaticFiles
// Modified) response.
[Fact]
public async Task IfModifiedSinceDateEqualsLastModifiedShouldReturn304()
public async Task IfModifiedSinceDateGreaterThanLastModifiedShouldReturn304()
{
TestServer server = StaticFilesTestServer.Create(app => app.UseFileServer());
@ -244,10 +246,27 @@ namespace Microsoft.AspNet.StaticFiles
HttpResponseMessage res2 = await server
.CreateRequest("/SubFolder/extra.xml")
.And(req => req.Headers.IfModifiedSince = res1.Content.Headers.LastModified)
.And(req => req.Headers.IfModifiedSince = DateTimeOffset.Now)
.GetAsync();
Assert.Equal(HttpStatusCode.NotModified, res2.StatusCode);
}
[Fact]
public async Task IfModifiedSinceDateLessThanLastModifiedShouldReturn200()
{
TestServer server = StaticFilesTestServer.Create(app => app.UseFileServer());
HttpResponseMessage res1 = await server
.CreateRequest("/SubFolder/extra.xml")
.GetAsync();
HttpResponseMessage res2 = await server
.CreateRequest("/SubFolder/extra.xml")
.And(req => req.Headers.IfModifiedSince = DateTimeOffset.MinValue)
.GetAsync();
Assert.Equal(HttpStatusCode.OK, res2.StatusCode);
}
}
}