-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix content negotiation #1009
base: main
Are you sure you want to change the base?
Fix content negotiation #1009
Conversation
Fix inability to return different responses based on content negotiation via HTTP request headers by including a hash of their names and values in the key for the registration.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1009 +/- ##
==========================================
+ Coverage 99.30% 99.32% +0.01%
==========================================
Files 15 15
Lines 868 886 +18
Branches 198 204 +6
==========================================
+ Hits 862 880 +18
Misses 4 4
Partials 2 2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
- Test changes from justeattakeaway/httpclient-interception#1009 to fix getting a pull request and its diff at the same time. - Make HTTP interceptions for the GitHub API always specify the `Accept` header that is expected.
Tested the changes in the app where I found this, and with the build from the PR it works as I'd expect now: martincostello/costellobot#2068 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
- Test changes from justeattakeaway/httpclient-interception#1009 to fix getting a pull request and its diff at the same time. - Make HTTP interceptions for the GitHub API always specify the `Accept` header that is expected.
Test changes from justeattakeaway/httpclient-interception#1009 to fix getting a pull request and its diff at the same time.
Fix inability to return different responses based on content negotiation via HTTP request headers by including a hash of their names and values in the key for the registration.
As per the test, I found this while doing some work where I needed to intercept responses to the GitHub API. The Get a pull request has a behaviour where different values for the
Accept
header change the format of the response.I had the need to get the JSON representation of a pull request and the diff for it in the same operation. This isn't currently possible using the "simple" API as the HTTP request headers aren't taken into account when storing the interception registrations, which created a Last-One-Wins situation meaning you couldn't have a response for the same HTTP method and URL.
While it was possible using the
For()
overloads, this has the user fall off a cliff in terms of usability and needs them to write all the matching logic themselves.In addition to the key changes, the collections used for header collections weren't being copied, meaning that the values also got mutated by reference when the user changed the registration. This part could potentially be a breaking behaviour change if someone is mutating a builder post-request expecting the matched values to change, but I don't think that's the behaviour originally intended in the design so is accidental.