This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +45
-0
lines changed
2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -249,6 +249,34 @@ end of the container containing the ngMessages directive).
249
249
</div>
250
250
```
251
251
252
+ - **$http:** due to [5da1256](https://github.com/angular/angular.js/commit/5da1256fc2812d5b28fb0af0de81256054856369),
253
+
254
+ `transformRequest` functions can no longer modify request headers.
255
+
256
+ Before this commit `transformRequest` could modify request headers, ex.:
257
+
258
+ ```javascript
259
+ function requestTransform(data, headers) {
260
+ headers = angular.extend(headers(), {
261
+ 'X-MY_HEADER': 'abcd'
262
+ });
263
+ }
264
+ return angular.toJson(data);
265
+ }
266
+ ```
267
+
268
+ This behavior was unintended and undocumented, so the change should affect very few applications. If one
269
+ needs to dynamically add / remove headers it should be done in a header function, for example:
270
+
271
+ ```javascript
272
+ $http.get(url, {
273
+ headers: {
274
+ 'X-MY_HEADER': function(config) {
275
+ return 'abcd'; //you've got access to a request config object to specify header value dynamically
276
+ }
277
+ }
278
+ })
279
+ ```
252
280
253
281
<a name="1.3.14"></a>
254
282
# 1.3.14 instantaneous-browserification (2015-02-24)
Original file line number Diff line number Diff line change @@ -1128,6 +1128,23 @@ describe('$http', function() {
1128
1128
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
1129
1129
} ) ;
1130
1130
1131
+ it ( 'should not allow modifications to headers in a transform functions' , function ( ) {
1132
+ var config = {
1133
+ headers : { 'Accept' : 'bar' } ,
1134
+ transformRequest : function ( data , headers ) {
1135
+ angular . extend ( headers ( ) , {
1136
+ 'Accept' : 'foo'
1137
+ } ) ;
1138
+ }
1139
+ } ;
1140
+
1141
+ $httpBackend . expect ( 'GET' , '/url' , undefined , { Accept : 'bar' } ) . respond ( 200 ) ;
1142
+ $http . get ( '/url' , config ) . success ( callback ) ;
1143
+ $httpBackend . flush ( ) ;
1144
+
1145
+ expect ( callback ) . toHaveBeenCalledOnce ( ) ;
1146
+ } ) ;
1147
+
1131
1148
it ( 'should pipeline more functions' , function ( ) {
1132
1149
function first ( d , h ) { return d + '-first' + ':' + h ( 'h1' ) ; }
1133
1150
function second ( d ) { return uppercase ( d ) ; }
You can’t perform that action at this time.
0 commit comments