Flurl: HttpCallAssertException when User-Agent contains a space

Created on 5 Apr 2018  路  3Comments  路  Source: tmenier/Flurl

Hello,

Thanks for this great library, you've done some really great work here :+1:

I have the following unit test:

using( var http = new HttpTest()){

   http.RespondWith("OK!");

   await "http://foo.com"
           .WithHeader("User-Agent", "Hello World")
           .GetStringAsync();

   http.ShouldHaveMadeACall()
      .WithHeader("User-Agent", "Hello World");
}

And I think it should work, but instead I get an exception:

Expected any calls to be made with header User-Agent: Hello World, but no  matching calls were made.

If you remove the space between Hello World the unit test passes.

:car: :blue_car: "Let the good times roll..."

bug

All 3 comments

Digging a little deeper, I think the problem is related to HttpClient breaking up the User-Agent string into multiple values when a space is detected.

https://stackoverflow.com/questions/43215527/c-sharp-httpclient-adding-user-agent-header-shows-up-as-several-different-head/43216319

Specifically, these lines here:
https://github.com/tmenier/Flurl/blob/49db9d65ede8ffb1ef9eb619eade6256961fa6fa/src/Flurl.Http/Testing/HttpCallAssertion.cs#L215-L216

Basically, vals.Any() tries Hello to match against Hello World and finally World matches against Hello World. :cactus:

:dash: :walking: "Bubbles of gas in my brain... Send me off balance, it's not enough"

Thanks for reporting (and for the kind words!) I'll look into this when I get a chance. Easily reproducable usually means easily fixable.

This is fixed and released in Flurl.Http 2.3.1.

Was this page helpful?
0 / 5 - 0 ratings