mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-19 12:01:07 +00:00
parent
2e1539356a
commit
209b67df6a
2 changed files with 34 additions and 7 deletions
|
|
@ -88,7 +88,7 @@ function $HttpProvider() {
|
||||||
JSON_END = /[\}\]]\s*$/,
|
JSON_END = /[\}\]]\s*$/,
|
||||||
PROTECTION_PREFIX = /^\)\]\}',?\n/;
|
PROTECTION_PREFIX = /^\)\]\}',?\n/;
|
||||||
|
|
||||||
var $config = this.defaults = {
|
var defaults = this.defaults = {
|
||||||
// transform incoming response data
|
// transform incoming response data
|
||||||
transformResponse: [function(data) {
|
transformResponse: [function(data) {
|
||||||
if (isString(data)) {
|
if (isString(data)) {
|
||||||
|
|
@ -475,9 +475,9 @@ function $HttpProvider() {
|
||||||
function $http(config) {
|
function $http(config) {
|
||||||
config.method = uppercase(config.method);
|
config.method = uppercase(config.method);
|
||||||
|
|
||||||
var reqTransformFn = config.transformRequest || $config.transformRequest,
|
var reqTransformFn = config.transformRequest || defaults.transformRequest,
|
||||||
respTransformFn = config.transformResponse || $config.transformResponse,
|
respTransformFn = config.transformResponse || defaults.transformResponse,
|
||||||
defHeaders = $config.headers,
|
defHeaders = defaults.headers,
|
||||||
reqHeaders = extend({'X-XSRF-TOKEN': $browser.cookies()['XSRF-TOKEN']},
|
reqHeaders = extend({'X-XSRF-TOKEN': $browser.cookies()['XSRF-TOKEN']},
|
||||||
defHeaders.common, defHeaders[lowercase(config.method)], config.headers),
|
defHeaders.common, defHeaders[lowercase(config.method)], config.headers),
|
||||||
reqData = transformData(config.data, headersGetter(reqHeaders), reqTransformFn),
|
reqData = transformData(config.data, headersGetter(reqHeaders), reqTransformFn),
|
||||||
|
|
@ -488,6 +488,10 @@ function $HttpProvider() {
|
||||||
delete reqHeaders['Content-Type'];
|
delete reqHeaders['Content-Type'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isUndefined(config.withCredentials) && !isUndefined(defaults.withCredentials)) {
|
||||||
|
config.withCredentials = defaults.withCredentials;
|
||||||
|
}
|
||||||
|
|
||||||
// send request
|
// send request
|
||||||
promise = sendReq(config, reqData, reqHeaders);
|
promise = sendReq(config, reqData, reqHeaders);
|
||||||
|
|
||||||
|
|
@ -619,11 +623,11 @@ function $HttpProvider() {
|
||||||
*
|
*
|
||||||
* @description
|
* @description
|
||||||
* Runtime equivalent of the `$httpProvider.defaults` property. Allows configuration of
|
* Runtime equivalent of the `$httpProvider.defaults` property. Allows configuration of
|
||||||
* default headers as well as request and response transformations.
|
* default headers, withCredentials as well as request and response transformations.
|
||||||
*
|
*
|
||||||
* See "Setting HTTP Headers" and "Transforming Requests and Responses" sections above.
|
* See "Setting HTTP Headers" and "Transforming Requests and Responses" sections above.
|
||||||
*/
|
*/
|
||||||
$http.defaults = $config;
|
$http.defaults = defaults;
|
||||||
|
|
||||||
|
|
||||||
return $http;
|
return $http;
|
||||||
|
|
@ -658,7 +662,7 @@ function $HttpProvider() {
|
||||||
* Makes the request
|
* Makes the request
|
||||||
*
|
*
|
||||||
* !!! ACCESSES CLOSURE VARS:
|
* !!! ACCESSES CLOSURE VARS:
|
||||||
* $httpBackend, $config, $log, $rootScope, defaultCache, $http.pendingRequests
|
* $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests
|
||||||
*/
|
*/
|
||||||
function sendReq(config, reqData, reqHeaders) {
|
function sendReq(config, reqData, reqHeaders) {
|
||||||
var deferred = $q.defer(),
|
var deferred = $q.defer(),
|
||||||
|
|
|
||||||
|
|
@ -981,4 +981,27 @@ describe('$http', function() {
|
||||||
|
|
||||||
$httpBackend.verifyNoOutstandingExpectation = noop;
|
$httpBackend.verifyNoOutstandingExpectation = noop;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('should use withCredentials from default', function() {
|
||||||
|
var $httpBackend = jasmine.createSpy('$httpBackend');
|
||||||
|
|
||||||
|
$httpBackend.andCallFake(function(m, u, d, c, h, timeout, withCredentials, responseType) {
|
||||||
|
expect(withCredentials).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
module(function($provide) {
|
||||||
|
$provide.value('$httpBackend', $httpBackend);
|
||||||
|
});
|
||||||
|
|
||||||
|
inject(function($http) {
|
||||||
|
$http.defaults.withCredentials = true;
|
||||||
|
$http({
|
||||||
|
method: 'GET', url: 'some.html', timeout: 12345, responseType: 'json'
|
||||||
|
});
|
||||||
|
expect($httpBackend).toHaveBeenCalledOnce();
|
||||||
|
});
|
||||||
|
|
||||||
|
$httpBackend.verifyNoOutstandingExpectation = noop;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue