Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ internal static int GetNextNonEmptyOrWhitespaceIndex(string input, int startInde
return current;
}

internal static DateTimeOffset? GetDateTimeOffsetValue(HeaderDescriptor descriptor, HttpHeaders store)
internal static DateTimeOffset? GetDateTimeOffsetValue(HeaderDescriptor descriptor, HttpHeaders store, DateTimeOffset? defaultValue = null)
{
Debug.Assert(store != null);

Expand All @@ -300,6 +300,11 @@ internal static int GetNextNonEmptyOrWhitespaceIndex(string input, int startInde
{
return (DateTimeOffset)storedValue;
}
else if (defaultValue != null && store.Contains(descriptor))
{
return defaultValue;
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public MediaTypeHeaderValue ContentType

public DateTimeOffset? Expires
{
get { return HeaderUtilities.GetDateTimeOffsetValue(KnownHeaders.Expires.Descriptor, this); }
get { return HeaderUtilities.GetDateTimeOffsetValue(KnownHeaders.Expires.Descriptor, this, DateTimeOffset.MinValue); }
set { SetOrRemoveParsedValue(KnownHeaders.Expires.Descriptor, value); }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private enum StoreLocation
}

protected HttpHeaders()
: this(HttpHeaderType.All, HttpHeaderType.None)
: this(HttpHeaderType.None, HttpHeaderType.All)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http.Headers;
using System.Net.Test.Common;
using System.Text;
using System.Threading;
Expand All @@ -21,6 +22,8 @@ public abstract class HttpClientHandlerTest_Headers : HttpClientHandlerTestBase
{
public HttpClientHandlerTest_Headers(ITestOutputHelper output) : base(output) { }

internal sealed class DerivedHttpHeaders : HttpHeaders { }

[Fact]
public async Task SendAsync_UserAgent_CorrectlyWritten()
{
Expand Down Expand Up @@ -66,6 +69,55 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
});
}

[Fact]
public async Task GetAsync_MissingExpires_ReturnNull()
{
await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
{
using (var client = CreateHttpClient())
{
HttpResponseMessage response = await client.GetAsync(uri);
Assert.Null(response.Content.Headers.Expires);
}
},
async server =>
{
await server.HandleRequestAsync(HttpStatusCode.OK);
});
}

[Theory]
[InlineData("Thu, 01 Dec 1994 16:00:00 GMT")]
[InlineData("-1")]
[InlineData("0")]
public async Task SendAsync_Expires_Success(string value)
{
await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
{
using (var client = CreateHttpClient())
{
var message = new HttpRequestMessage(HttpMethod.Get, uri);
HttpResponseMessage response = await client.SendAsync(message);
Assert.NotNull(response.Content.Headers.Expires);
}
},
async server =>
{
IList<HttpHeaderData> headers = new HttpHeaderData[] { new HttpHeaderData("Expires", value) };

HttpRequestData requestData = await server.HandleRequestAsync(HttpStatusCode.OK, headers);
});
}

[Theory]
[InlineData("-1")]
[InlineData("Thu, 01 Dec 1994 16:00:00 GMT")]
public void SendAsync_CustomExpires_Success(string value)
{
var headers = new DerivedHttpHeaders();
headers.Add("Expires", value);
}

[OuterLoop("Uses external server")]
[Theory]
[InlineData(false)]
Expand Down