#307 asserting headers with spaces

This commit is contained in:
Todd Menier 2018-04-16 17:27:22 -05:00
parent d61d899d3a
commit 5025cef1f4
2 changed files with 11 additions and 3 deletions

View File

@ -131,11 +131,19 @@ namespace Flurl.Test.Http
[Test]
public async Task can_assert_headers() {
await "http://api.com".WithHeaders(new { h1 = "val1", h2 = "val2" }).GetAsync();
await "http://api.com"
.WithHeaders(new { h1 = "val1", h2 = "val2" })
.WithHeader("User-Agent", "two words") // #307
.WithHeader("x", "dos words") // crazier than #307
.WithHeader("y", "hi; there") // crazier still
.GetAsync();
HttpTest.ShouldHaveMadeACall().WithHeader("h1");
HttpTest.ShouldHaveMadeACall().WithHeader("h2", "val2");
HttpTest.ShouldHaveMadeACall().WithHeader("h1", "val*");
HttpTest.ShouldHaveMadeACall().WithHeader("User-Agent", "two words");
HttpTest.ShouldHaveMadeACall().WithHeader("x", "dos words");
HttpTest.ShouldHaveMadeACall().WithHeader("y", "hi; there");
HttpTest.ShouldHaveMadeACall().WithoutHeader("h3");
HttpTest.ShouldHaveMadeACall().WithoutHeader("h2", "val1");

View File

@ -211,9 +211,9 @@ namespace Flurl.Http.Testing
/// <returns></returns>
public HttpCallAssertion WithHeader(string name, string valuePattern = "*") {
_expectedConditions.Add($"header {name}: {valuePattern}");
return With(c =>
return With(c =>
c.Request.Headers.TryGetValues(name, out var vals) &&
vals.Any(v => MatchesPattern(v, valuePattern)));
MatchesPattern(string.Join(" ", vals), valuePattern));
}
/// <summary>