public override string ToString() { switch (type) { case IfRangeType.EntityTag: return(EntityTag.ToString()); case IfRangeType.LastModified: return(LastModified.AsHttpDateTime()); default: throw new InvalidProgramException("Unknown IfRangeType." + type); } }
public async Task PreconditionIfNoneMatchPutFailTest() { // Arrange Client.DefaultRequestHeaders.Add("If-None-Match", EntityTag.ToString()); // Act HttpResponseMessage response = await Client.PutAsync("/file/file", new StringContent(string.Empty)); string responseString = await response.Content.ReadAsStringAsync(); // Assert Assert.Equal(HttpStatusCode.NotModified, response.StatusCode); Assert.Equal(string.Empty, responseString); Assert.NotEqual("bytes", response.Headers.AcceptRanges.ToString()); Assert.Equal(EntityTag, response.Headers.ETag); Assert.Null(response.Content.Headers.ContentRange); }
public async Task PreconditionIfNoneMatchHeadFailTest() { // Arrange Client.DefaultRequestHeaders.Add("If-None-Match", EntityTag.ToString()); // Act HttpResponseMessage response = await Client.SendAsync(new HttpRequestMessage(HttpMethod.Head, "/file/file")); string responseString = await response.Content.ReadAsStringAsync(); // Assert Assert.Equal(HttpStatusCode.NotModified, response.StatusCode); Assert.Equal(string.Empty, responseString); Assert.NotEqual("bytes", response.Headers.AcceptRanges.ToString()); Assert.Equal(EntityTag, response.Headers.ETag); Assert.Null(response.Content.Headers.ContentRange); Assert.Equal("attachment", response.Content.Headers.ContentDisposition.DispositionType); }
public async Task PreconditionIfUnmodifiedSinceIfMatchFailTest() { // Arrange Client.DefaultRequestHeaders.Add("If-Match", EntityTag.ToString()); Client.DefaultRequestHeaders.Add("If-Unmodified-Since", HeaderUtilities.FormatDate(LastModified.AddSeconds(-1))); // Act HttpResponseMessage response = await Client.GetAsync("/file/physical/true/true"); string responseString = await response.Content.ReadAsStringAsync(); // Assert Assert.Equal(HttpStatusCode.PreconditionFailed, response.StatusCode); Assert.Equal(string.Empty, responseString); Assert.NotEqual("bytes", response.Headers.AcceptRanges.ToString()); Assert.Equal(EntityTag, response.Headers.ETag); Assert.Null(response.Content.Headers.ContentRange); }
public async Task PreconditionIfMatchSuccessTest() { // Arrange Client.DefaultRequestHeaders.Add("If-Match", EntityTag.ToString()); // Act HttpResponseMessage response = await Client.GetAsync("/file/physical/true/true"); response.EnsureSuccessStatusCode(); string responseString = await response.Content.ReadAsStringAsync(); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal("0123456789abcdefghijklmnopgrstuvwxyzABCDEFGHIJKLMNOPGRSTUVWXYZ", responseString); Assert.Equal("bytes", response.Headers.AcceptRanges.ToString()); Assert.Equal(EntityTag, response.Headers.ETag); Assert.Null(response.Content.Headers.ContentRange); }
public async Task PreconditionIfRangeIgnoreEtagEmptyTest() { // Arrange Client.DefaultRequestHeaders.Add("Range", "bytes=1-1"); Client.DefaultRequestHeaders.Add("If-Range", EntityTag.ToString()); // Act HttpResponseMessage response = await Client.GetAsync("/file/physical/true/false"); response.EnsureSuccessStatusCode(); string responseString = await response.Content.ReadAsStringAsync(); // Assert Assert.Equal(HttpStatusCode.PartialContent, response.StatusCode); Assert.Equal("1", responseString); Assert.Equal("bytes", response.Headers.AcceptRanges.ToString()); Assert.Null(response.Headers.ETag); }
public async Task PreconditionIfMatchFailWeakTest() { // Arrange string entityTag = EntityTag.ToString(); var tmpNewEntityTag = new EntityTagHeaderValue(entityTag, true); Client.DefaultRequestHeaders.Add("If-Match", tmpNewEntityTag.ToString()); // Act HttpResponseMessage response = await Client.GetAsync("/file/physical/true/true"); string responseString = await response.Content.ReadAsStringAsync(); // Assert Assert.Equal(HttpStatusCode.PreconditionFailed, response.StatusCode); Assert.Equal(string.Empty, responseString); Assert.NotEqual("bytes", response.Headers.AcceptRanges.ToString()); Assert.Equal(EntityTag, response.Headers.ETag); Assert.Null(response.Content.Headers.ContentRange); }
public async Task PreconditionIfRangeIgnoreWeakEtagTest() { // Arrange var tmpNewEntityTag = new EntityTagHeaderValue(EntityTag.ToString(), true); Client.DefaultRequestHeaders.Add("Range", "bytes=1-1"); Client.DefaultRequestHeaders.Add("If-Range", tmpNewEntityTag.ToString()); // Act HttpResponseMessage response = await Client.GetAsync("/file/physical/true/true"); response.EnsureSuccessStatusCode(); string responseString = await response.Content.ReadAsStringAsync(); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal("0123456789abcdefghijklmnopgrstuvwxyzABCDEFGHIJKLMNOPGRSTUVWXYZ", responseString); Assert.Equal("bytes", response.Headers.AcceptRanges.ToString()); Assert.Equal(EntityTag, response.Headers.ETag); Assert.Null(response.Content.Headers.ContentRange); Assert.Equal("attachment", response.Content.Headers.ContentDisposition.DispositionType); }