feat($http): provide a config object as an argument to header functions #10622

Closed
wants to merge 1 commit into
from

Projects

None yet

5 participants

@pkozlowski-opensource

This is a cleaned up / alternative version for #7235

@googlebot googlebot added the cla: yes label Jan 2, 2015
@fundon
fundon commented Jan 5, 2015

+1, Nice!

Please merge!

@pkozlowski-opensource

@caitp / @petebacondarwin / @lgalfaso (or anyone else!) - would you guys mind reviewing this one - it is pretty minimal

@caitp
Contributor
caitp commented Jan 9, 2015

taking a quick gander

@caitp caitp and 1 other commented on an outdated diff Jan 9, 2015
test/ng/httpSpec.js
+ config.bar = 'baz';
+ return config.foo;
+ }}
+ };
+
+ function checkHeaders(headers) {
+ return headers['Accept'] == 'Rewritten';
+ }
+
+ $httpBackend.expect('GET', '/url', undefined, checkHeaders).respond('');
+ $http.get('/url', config);
+ $httpBackend.flush();
+
+ expect(config.bar).toBeUndefined();
+ });
+
@caitp
caitp Jan 9, 2015 Contributor

should we also test the main functionality of this feature? :p

@pkozlowski-opensource
pkozlowski-opensource Jan 9, 2015 Member

@caitp it is tested as otherwise a mocked request would fail, no?

@caitp
caitp Jan 9, 2015 Contributor

let me check ngMock one sec... But in spite of that, I think you should have a different spec for that, because it's not explicitly testing that, it's explicitly testing that the passed in config object is a shallow copy

@pkozlowski-opensource
pkozlowski-opensource Jan 9, 2015 Member

Yep, I thought of splitting it into 2 separate specs when I saw your comment. Will create 2 separate specs.

@petebacondarwin
Member

Can you guys triage your own PRs please!

@petebacondarwin petebacondarwin added this to the 1.4.0-beta.1 / 1.3.10 milestone Jan 15, 2015
@pkozlowski-opensource pkozlowski-opensource self-assigned this Jan 16, 2015
@googlebot

We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm.

@googlebot googlebot added cla: no and removed cla: yes labels Jan 17, 2015
@pkozlowski-opensource pkozlowski-opensource feat($http): provide a config object as an argument to header functions
d88e863
@googlebot

CLAs look good, thanks!

@googlebot googlebot added cla: yes and removed cla: no labels Jan 17, 2015
@pkozlowski-opensource

I've rebased this one and split tests based on the review comments.
@caitp do you want to have another look at this one?

@caitp
Contributor
caitp commented Jan 17, 2015

I'll take a look on Monday

@caitp caitp assigned caitp and unassigned pkozlowski-opensource Jan 17, 2015
@caitp caitp commented on the diff Jan 20, 2015
test/ng/httpSpec.js
@@ -781,6 +781,34 @@ describe('$http', function() {
$httpBackend.flush();
});
+ it('should expose a config object to header functions', function() {
+ var config = {
+ foo: 'Rewritten',
+ headers: {'Accept': function(config) {
+ return config.foo;
+ }}
+ };
+
+ $httpBackend.expect('GET', '/url', undefined, {Accept: 'Rewritten'}).respond('');
+ $http.get('/url', config);
+ $httpBackend.flush();
+ });
+
+ it('should not allow modifications to a config object in header functions', function() {
@caitp
caitp Jan 20, 2015 Contributor

should ignore modifications (but no big deal)

@caitp
caitp Jan 20, 2015 Contributor

this will also only "ignore" changes to root properties of the config object, so changes to child object properties won't be ignored :( but I don't think it's worth worrying about it until someone complains

@pkozlowski-opensource
pkozlowski-opensource Jan 20, 2015 Member

yeh... but I agree that we shouldn't worry about it too much right now...

@caitp
Contributor
caitp commented Jan 20, 2015

still lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment