httpclient-interception icon indicating copy to clipboard operation
httpclient-interception copied to clipboard

WIP - Improve additional matching for requests with the same URL

Open Demetrios-loutsios opened this issue 3 years ago • 4 comments

Implements https://github.com/justeat/httpclient-interception/issues/249

Demetrios-loutsios avatar Oct 06 '22 16:10 Demetrios-loutsios

Codecov Report

Merging #486 (8300340) into main (fafd2ad) will decrease coverage by 2.09%. The diff coverage is 64.00%.

:exclamation: Current head 8300340 differs from pull request most recent head 802cced. Consider uploading reports for the commit 802cced to get more accurate results

@@            Coverage Diff             @@
##             main     #486      +/-   ##
==========================================
- Coverage   99.49%   97.39%   -2.10%     
==========================================
  Files          15       15              
  Lines         796      846      +50     
==========================================
+ Hits          792      824      +32     
- Misses          4       22      +18     
Flag Coverage Δ
linux 97.39% <64.00%> (-2.10%) :arrow_down:
macos 97.39% <64.00%> (-2.10%) :arrow_down:
windows 97.39% <64.00%> (-2.10%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/HttpClientInterception/DelegateHelpers.cs 76.47% <63.63%> (-23.53%) :arrow_down:
...ientInterception/HttpRequestInterceptionBuilder.cs 98.17% <66.66%> (-0.71%) :arrow_down:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

codecov-commenter avatar Oct 06 '22 16:10 codecov-commenter

I'm looking for suggestions concerning this implementation.

The issue suggests implementing something like:

  int requestCount = 0;
  var builder429 = new HttpRequestInterceptionBuilder()
            .Requests()
            .ForHttps()
            .ForHost("api.github.com")
            .ForPath("orgs/justeat")
            .AndFor(() => ++requestCount % 2 > 0)
            .Responds()
            .WithStatus(HttpStatusCode.TooManyRequests)
            .WithJsonContent(new { error = "Too many requests" });

The AndFor() predicate evaluates the condition, incrementing the counter each time. Two interceptors mean the counter is always incremented too many times, resulting in no match.

I have two options:

  • Do nothing
  • Add an additional optional parameter to the AndFor() to run on successful match ie .AndFor(() => requestCount % 2 > 0, () => requestCount++)

@martincostello, do you have an opinion?

Demetrios-loutsios avatar Oct 06 '22 16:10 Demetrios-loutsios

I'll try and read the original issue and remember the details and then review this tomorrow and have a think.

martincostello avatar Oct 06 '22 17:10 martincostello

Sorry - won't get to this today. Will look next week (unless I get bored over the weekend).

martincostello avatar Oct 07 '22 13:10 martincostello

Thanks @martincostello I'll action the rest of your feedback when I'm back from Holiday next week.

Demetrios-loutsios avatar Nov 16 '22 17:11 Demetrios-loutsios