@angular-wave/angular.ts 0.9.2 → 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/angular.d.ts +4 -19
- package/@types/animations/animate.d.ts +2 -2
- package/@types/animations/animation.d.ts +1 -1
- package/@types/core/compile/attributes.d.ts +1 -1
- package/@types/core/compile/compile.d.ts +2 -2
- package/@types/core/controller/controller.d.ts +1 -1
- package/@types/core/controller/interface.d.ts +6 -0
- package/@types/core/di/ng-module.d.ts +27 -26
- package/@types/core/filter/filter.d.ts +5 -5
- package/@types/core/interpolate/interface.d.ts +13 -0
- package/@types/core/interpolate/interpolate.d.ts +1 -13
- package/@types/core/scope/scope.d.ts +4 -1
- package/@types/directive/http/http.d.ts +16 -16
- package/@types/directive/http/interface.d.ts +27 -0
- package/@types/directive/include/include.d.ts +4 -4
- package/@types/directive/inject/inject.d.ts +12 -0
- package/@types/directive/model/model.d.ts +1 -1
- package/@types/directive/script/script.d.ts +2 -2
- package/@types/directive/setter/setter.d.ts +4 -4
- package/@types/filters/filter.d.ts +2 -2
- package/@types/filters/filters.d.ts +2 -2
- package/@types/filters/interface.d.ts +8 -0
- package/@types/filters/limit-to.d.ts +2 -2
- package/@types/filters/order-by.d.ts +2 -2
- package/@types/index.d.ts +84 -1
- package/@types/interface.d.ts +105 -82
- package/@types/router/state/interface.d.ts +8 -8
- package/@types/router/state-filters.d.ts +4 -4
- package/@types/router/template-factory.d.ts +6 -6
- package/@types/router/transition/hook-builder.d.ts +5 -2
- package/@types/router/transition/hook-registry.d.ts +11 -2
- package/@types/router/transition/transition-service.d.ts +6 -2
- package/@types/router/transition/transition.d.ts +2 -2
- package/@types/router/view/view.d.ts +1 -8
- package/@types/router/view-scroll.d.ts +4 -2
- package/@types/services/{anchor-scroll.d.ts → anchor-scroll/anchor-scroll.d.ts} +2 -2
- package/@types/services/exception/exception-handler.d.ts +2 -2
- package/@types/services/exception/interface.d.ts +1 -1
- package/@types/services/http/http.d.ts +40 -2
- package/@types/services/http/interface.d.ts +11 -0
- package/@types/services/location/location.d.ts +1 -4
- package/@types/services/sce/sce.d.ts +3 -4
- package/@types/services/template-cache/template-cache.d.ts +4 -4
- package/@types/services/template-request/interface.d.ts +22 -0
- package/@types/services/{template-request.d.ts → template-request/template-request.d.ts} +4 -7
- package/@types/shared/common.d.ts +8 -69
- package/@types/shared/hof.d.ts +7 -7
- package/dist/angular-ts.esm.js +509 -570
- package/dist/angular-ts.umd.js +509 -570
- package/dist/angular-ts.umd.min.js +1 -1
- package/{src/filters → docs/content/docs/filter}/filter.md +18 -9
- package/{src/filters → docs/content/docs/filter}/json.md +6 -3
- package/docs/content/docs/filter/limit-to.md +30 -0
- package/docs/content/docs/filter/order-by.md +123 -0
- package/docs/content/docs/provider/sceProvider.md +194 -0
- package/docs/content/docs/provider/templateRequestProvider.md +5 -0
- package/docs/content/docs/service/compile.md +5 -0
- package/docs/content/docs/service/controller.md +5 -0
- package/docs/content/docs/service/http.md +161 -0
- package/docs/content/docs/service/interpolation.md +5 -0
- package/docs/content/docs/service/log.md +1 -1
- package/docs/content/docs/service/parse.md +5 -0
- package/docs/content/docs/service/rootElement.md +5 -0
- package/docs/content/docs/service/rootScope.md +5 -0
- package/docs/content/docs/service/sce.md +194 -0
- package/docs/content/docs/service/templateRequest.md +5 -0
- package/docs/content/docs/values/_index.md +4 -0
- package/docs/content/docs/values/document.md +29 -0
- package/docs/content/docs/values/window.md +29 -0
- package/docs/layouts/shortcodes/version.html +1 -1
- package/docs/static/examples/document/document.html +3 -0
- package/docs/static/examples/i18n/i18n.html +77 -0
- package/docs/static/examples/window/window.html +4 -0
- package/docs/static/typedoc/assets/hierarchy.js +1 -1
- package/docs/static/typedoc/assets/highlight.css +0 -49
- package/docs/static/typedoc/assets/navigation.js +1 -1
- package/docs/static/typedoc/assets/search.js +1 -1
- package/docs/static/typedoc/classes/PubSubProvider.html +3 -2
- package/docs/static/typedoc/classes/TemplateCacheProvider.html +1 -1
- package/docs/static/typedoc/hierarchy.html +1 -1
- package/docs/static/typedoc/index.html +1 -1
- package/docs/static/typedoc/interfaces/HttpProviderDefaults.html +1 -1
- package/docs/static/typedoc/interfaces/RequestConfig.html +1 -1
- package/docs/static/typedoc/interfaces/RequestShortcutConfig.html +1 -1
- package/docs/static/typedoc/interfaces/ServiceProvider.html +3 -3
- package/docs/static/typedoc/types/HttpParamSerializer.html +2 -0
- package/docs/static/typedoc/types/{Expression.html → HttpParams.html} +1 -5
- package/legacy.d.ts +0 -921
- package/package.json +1 -1
- package/src/angular.js +2 -9
- package/src/animations/animate.js +1 -1
- package/src/animations/animation.js +7 -7
- package/src/core/compile/compile.js +3 -2
- package/src/core/controller/controller.js +10 -6
- package/src/core/controller/interface.ts +6 -0
- package/src/core/di/injector.js +1 -1
- package/src/core/di/internal-injector.js +2 -0
- package/src/core/di/ng-module.js +16 -13
- package/src/core/filter/filter.js +3 -3
- package/src/core/interpolate/interface.ts +14 -0
- package/src/core/interpolate/interpolate.js +7 -5
- package/src/core/scope/scope.js +4 -1
- package/src/directive/http/delete.spec.js +5 -8
- package/src/directive/http/http.js +16 -16
- package/src/directive/http/interface.ts +36 -0
- package/src/directive/http/put.spec.js +5 -8
- package/src/directive/include/include.js +2 -2
- package/src/{services/http-backend/http-backend.html → directive/inject/inject.html} +1 -4
- package/src/directive/inject/inject.js +35 -0
- package/src/directive/inject/inject.spec.js +108 -0
- package/src/{services/http-backend/http-backend.test.js → directive/inject/inject.test.js} +1 -1
- package/src/directive/script/script.js +1 -1
- package/src/directive/setter/setter.js +2 -2
- package/src/filters/filter.js +1 -1
- package/src/filters/filters.js +1 -1
- package/src/filters/interface.ts +9 -0
- package/src/filters/limit-to.js +1 -1
- package/src/filters/order-by.js +1 -1
- package/src/index.ts +96 -0
- package/src/injection-tokens.js +4 -1
- package/src/interface.ts +102 -93
- package/src/ng.js +6 -4
- package/src/ng.spec.js +12 -0
- package/src/router/directives/state-directives.js +1 -1
- package/src/router/directives/view-directive.spec.js +19 -35
- package/src/router/state/interface.ts +8 -8
- package/src/router/state/state-builder.js +4 -4
- package/src/router/state/state-registry.js +7 -2
- package/src/router/state/state-service.js +2 -14
- package/src/router/state-filters.js +2 -2
- package/src/router/template-factory.js +3 -3
- package/src/router/template-factory.spec.js +10 -19
- package/src/router/transition/hook-builder.js +5 -1
- package/src/router/transition/hook-registry.js +12 -3
- package/src/router/transition/transition-service.js +4 -9
- package/src/router/transition/transition.js +3 -2
- package/src/router/url/url-service.js +2 -2
- package/src/router/view/view.js +3 -15
- package/src/router/view-scroll.js +2 -2
- package/src/services/{anchor-scroll.js → anchor-scroll/anchor-scroll.js} +4 -4
- package/src/services/exception/exception-handler.js +1 -1
- package/src/services/exception/interface.ts +1 -1
- package/src/services/http/http.js +200 -13
- package/src/services/http/http.spec.js +388 -9
- package/src/services/http/interface.ts +13 -0
- package/src/services/location/location.js +1 -1
- package/src/services/pubsub/pubsub.js +0 -1
- package/src/services/sce/sce.js +18 -13
- package/src/services/template-cache/template-cache.js +2 -2
- package/src/services/template-request/interface.ts +23 -0
- package/src/services/{template-request.js → template-request/template-request.js} +6 -6
- package/src/shared/common.js +7 -80
- package/src/shared/hof.js +23 -17
- package/typedoc.json +1 -1
- package/@types/services/cookie-reader.d.ts +0 -4
- package/@types/services/http-backend/http-backend.d.ts +0 -58
- package/@types/services/template-cache/interface.d.ts +0 -10
- package/docs/static/typedoc/interfaces/ChangesObject.html +0 -6
- package/docs/static/typedoc/interfaces/ComponentOptions.html +0 -16
- package/docs/static/typedoc/interfaces/Controller.html +0 -12
- package/docs/static/typedoc/interfaces/Directive.html +0 -37
- package/docs/static/typedoc/interfaces/DirectivePrePost.html +0 -4
- package/docs/static/typedoc/interfaces/NgModelController.html +0 -30
- package/docs/static/typedoc/interfaces/NgModelOptions.html +0 -16
- package/docs/static/typedoc/interfaces/Provider.html +0 -34
- package/docs/static/typedoc/interfaces/TemplateCache.html +0 -7
- package/docs/static/typedoc/interfaces/TranscludeFunctionObject.html +0 -8
- package/docs/static/typedoc/types/AnnotatedDirectiveFactory.html +0 -1
- package/docs/static/typedoc/types/AnnotatedFactory.html +0 -8
- package/docs/static/typedoc/types/CloneAttachFunction.html +0 -2
- package/docs/static/typedoc/types/ControllerConstructor.html +0 -2
- package/docs/static/typedoc/types/DirectiveCompileFn.html +0 -2
- package/docs/static/typedoc/types/DirectiveController.html +0 -2
- package/docs/static/typedoc/types/DirectiveFactory.html +0 -1
- package/docs/static/typedoc/types/DirectiveFactoryFn.html +0 -1
- package/docs/static/typedoc/types/DirectiveLinkFn.html +0 -2
- package/docs/static/typedoc/types/ExpandoStore.html +0 -2
- package/docs/static/typedoc/types/FilterFactory.html +0 -2
- package/docs/static/typedoc/types/FilterFn.html +0 -2
- package/docs/static/typedoc/types/Injectable.html +0 -4
- package/docs/static/typedoc/types/InjectableClass.html +0 -1
- package/docs/static/typedoc/types/InjectableFactory.html +0 -1
- package/docs/static/typedoc/types/OnChangesObject.html +0 -2
- package/docs/static/typedoc/types/SwapModeType.html +0 -2
- package/docs/static/typedoc/types/TController.html +0 -2
- package/docs/static/typedoc/variables/SwapMode.html +0 -11
- package/src/filters/limit-to.md +0 -19
- package/src/filters/order-by.md +0 -83
- package/src/router/state/README.md +0 -21
- package/src/services/cookie-reader.js +0 -48
- package/src/services/http/http.md +0 -413
- package/src/services/http-backend/http-backend.js +0 -158
- package/src/services/http-backend/http-backend.spec.js +0 -389
- package/src/services/sce/sce.md +0 -300
- package/src/services/template-cache/interface.ts +0 -10
- /package/src/services/{anchor-scroll.html → anchor-scroll/anchor-scroll.html} +0 -0
|
@@ -1,413 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
_ The `$http` service is a core AngularTS service that facilitates communication with the remote
|
|
3
|
-
_ HTTP servers via the browser's [XMLHttpRequest](https://developer.mozilla.org/en/xmlhttprequest)
|
|
4
|
-
_ object or via [JSONP](http://en.wikipedia.org/wiki/JSONP).
|
|
5
|
-
_
|
|
6
|
-
_ For unit testing applications that use `$http` service, see
|
|
7
|
-
_ {@link ngMock.$httpBackend $httpBackend mock}.
|
|
8
|
-
*
|
|
9
|
-
* For a higher level of abstraction, please check out the {@link ngResource.$resource
|
|
10
|
-
_ $resource} service.
|
|
11
|
-
_
|
|
12
|
-
_ The $http API is based on the {@link ng.$q deferred/promise APIs} exposed by
|
|
13
|
-
_ the $q service. While for simple usage patterns this doesn't matter much, for advanced usage
|
|
14
|
-
* it is important to familiarize yourself with these APIs and the guarantees they provide.
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* ## General usage
|
|
18
|
-
* The `$http`service is a function which takes a single argument — a {@link $http#usage configuration object} —
|
|
19
|
-
* that is used to generate an HTTP request and returns a {@link ng.$q promise} that is
|
|
20
|
-
* resolved (request success) or rejected (request failure) with a
|
|
21
|
-
* {@link ng.$http#$http-returns response} object.
|
|
22
|
-
*
|
|
23
|
-
* ```js
|
|
24
|
-
* // Simple GET request example:
|
|
25
|
-
* $http({
|
|
26
|
-
* method: 'GET',
|
|
27
|
-
* url: '/someUrl'
|
|
28
|
-
* }).then(function successCallback(response) {
|
|
29
|
-
* // this callback will be called asynchronously
|
|
30
|
-
* // when the response is available
|
|
31
|
-
* }, function errorCallback(response) {
|
|
32
|
-
* // called asynchronously if an error occurs
|
|
33
|
-
* // or server returns response with an error status.
|
|
34
|
-
* });
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* ## Shortcut methods
|
|
39
|
-
*
|
|
40
|
-
* Shortcut methods are also available. All shortcut methods require passing in the URL, and
|
|
41
|
-
* request data must be passed in for POST/PUT requests. An optional config can be passed as the
|
|
42
|
-
* last argument.
|
|
43
|
-
*
|
|
44
|
-
* ```js
|
|
45
|
-
* $http.get('/someUrl', config).then(successCallback, errorCallback);
|
|
46
|
-
* $http.post('/someUrl', data, config).then(successCallback, errorCallback);
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* Complete list of shortcut methods:
|
|
50
|
-
*
|
|
51
|
-
* - {@link ng.$http#get $http.get}
|
|
52
|
-
* - {@link ng.$http#head $http.head}
|
|
53
|
-
* - {@link ng.$http#post $http.post}
|
|
54
|
-
* - {@link ng.$http#put $http.put}
|
|
55
|
-
* - {@link ng.$http#delete $http.delete}
|
|
56
|
-
* - {@link ng.$http#patch $http.patch}
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* ```
|
|
60
|
-
* $http.get(...);
|
|
61
|
-
* $httpBackend.flush();
|
|
62
|
-
* ```
|
|
63
|
-
*
|
|
64
|
-
* ## Setting HTTP Headers
|
|
65
|
-
*
|
|
66
|
-
* The $http service will automatically add certain HTTP headers to all requests. These defaults
|
|
67
|
-
* can be fully configured by accessing the`$httpProvider.defaults.headers` configuration
|
|
68
|
-
* object, which currently contains this default configuration:
|
|
69
|
-
*
|
|
70
|
-
* - `$httpProvider.defaults.headers.common`(headers that are common for all requests):
|
|
71
|
-
* - <code>Accept: application/json, text/plain, \*/\*</code>
|
|
72
|
-
* -`$httpProvider.defaults.headers.post`: (header defaults for POST requests)
|
|
73
|
-
* - `Content-Type: application/json`
|
|
74
|
-
* - `$httpProvider.defaults.headers.put`(header defaults for PUT requests)
|
|
75
|
-
* -`Content-Type: application/json` *
|
|
76
|
-
* To add or overwrite these defaults, simply add or remove a property from these configuration
|
|
77
|
-
* objects. To add headers for an HTTP method other than POST or PUT, simply add a new object
|
|
78
|
-
* with the lowercased HTTP method name as the key, e.g.
|
|
79
|
-
*`$httpProvider.defaults.headers.get = { 'My-Header' : 'value' }`.
|
|
80
|
-
*
|
|
81
|
-
* The defaults can also be set at runtime via the `$http.defaults`object in the same
|
|
82
|
-
* fashion. For example:
|
|
83
|
-
*
|
|
84
|
-
* ```
|
|
85
|
-
* module.run(function($http) {
|
|
86
|
-
* $http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w';
|
|
87
|
-
* });
|
|
88
|
-
* ```
|
|
89
|
-
*
|
|
90
|
-
* In addition, you can supply a`headers`property in the config object passed when
|
|
91
|
-
* calling`$http(config)`, which overrides the defaults without changing them globally.
|
|
92
|
-
*
|
|
93
|
-
* To explicitly remove a header automatically added via $httpProvider.defaults.headers on a per request basis,
|
|
94
|
-
* Use the `headers`property, setting the desired header to`undefined`. For example:
|
|
95
|
-
*
|
|
96
|
-
* ```js
|
|
97
|
-
* let req = {
|
|
98
|
-
* method: 'POST',
|
|
99
|
-
* url: 'http://example.com',
|
|
100
|
-
* headers: {
|
|
101
|
-
* 'Content-Type': undefined
|
|
102
|
-
* },
|
|
103
|
-
* data: { test: 'test' }
|
|
104
|
-
* }
|
|
105
|
-
*
|
|
106
|
-
* $http(req).then(function(){...}, function(){...});
|
|
107
|
-
* ```
|
|
108
|
-
*
|
|
109
|
-
* ## Transforming Requests and Responses
|
|
110
|
-
*
|
|
111
|
-
* Both requests and responses can be transformed using transformation functions: `transformRequest` * and`transformResponse`. These properties can be a single function that returns
|
|
112
|
-
* the transformed value (`function(data, headersGetter, status)`) or an array of such transformation functions,
|
|
113
|
-
* which allows you to `push`or`unshift` a new transformation function into the transformation chain. \*
|
|
114
|
-
_ <div class="alert alert-warning">
|
|
115
|
-
_ **Note:** AngularTS does not make a copy of the `data` parameter before it is passed into the `transformRequest` pipeline.
|
|
116
|
-
_ That means changes to the properties of `data` are not local to the transform function (since Javascript passes objects by reference).
|
|
117
|
-
_ For example, when calling `$http.get(url, $scope.myObject)`, modifications to the object's properties in a transformRequest
|
|
118
|
-
_ function will be reflected on the scope and in any templates where the object is data-bound.
|
|
119
|
-
_ To prevent this, transform functions should have no side-effects.
|
|
120
|
-
_ If you need to modify properties, it is recommended to make a copy of the data, or create new object to return.
|
|
121
|
-
_ </div> \*
|
|
122
|
-
_ ### Default Transformations
|
|
123
|
-
_
|
|
124
|
-
_ The `$httpProvider` provider and `$http` service expose `defaults.transformRequest` and
|
|
125
|
-
_ `defaults.transformResponse` properties. If a request does not provide its own transformations
|
|
126
|
-
_ then these will be applied.
|
|
127
|
-
_
|
|
128
|
-
_ You can augment or replace the default transformations by modifying these properties by adding to or
|
|
129
|
-
_ replacing the array. \*
|
|
130
|
-
_ AngularTS provides the following default transformations:
|
|
131
|
-
_
|
|
132
|
-
_ Request transformations (`$httpProvider.defaults.transformRequest` and `$http.defaults.transformRequest`) is
|
|
133
|
-
_ an array with one function that does the following: \*
|
|
134
|
-
_ - If the `data` property of the request configuration object contains an object, serialize it
|
|
135
|
-
_ into JSON format. \*
|
|
136
|
-
_ Response transformations (`$httpProvider.defaults.transformResponse` and `$http.defaults.transformResponse`) is
|
|
137
|
-
_ an array with one function that does the following: \*
|
|
138
|
-
_ - If XSRF prefix is detected, strip it (see Security Considerations section below).
|
|
139
|
-
_ - If the `Content-Type` is `application/json` or the response looks like JSON,
|
|
140
|
-
_ deserialize it using a JSON parser.
|
|
141
|
-
_ \*
|
|
142
|
-
_ ### Overriding the Default Transformations Per Request
|
|
143
|
-
_
|
|
144
|
-
_ If you wish to override the request/response transformations only for a single request then provide
|
|
145
|
-
_ `transformRequest` and/or `transformResponse` properties on the configuration object passed
|
|
146
|
-
_ into `$http`.
|
|
147
|
-
_
|
|
148
|
-
_ Note that if you provide these properties on the config object the default transformations will be
|
|
149
|
-
_ overwritten. If you wish to augment the default transformations then you must include them in your
|
|
150
|
-
_ local transformation array.
|
|
151
|
-
_
|
|
152
|
-
_ The following code demonstrates adding a new response transformation to be run after the default response
|
|
153
|
-
_ transformations have been run. \*
|
|
154
|
-
_ ```js
|
|
155
|
-
_ function appendTransform(defaults, transform) { \*
|
|
156
|
-
_ // We can't guarantee that the default transformation is an array
|
|
157
|
-
_ defaults = angular.isArray(defaults) ? defaults : [defaults]; \*
|
|
158
|
-
_ // Append the new transformation to the defaults
|
|
159
|
-
_ return defaults.concat(transform);
|
|
160
|
-
_ }
|
|
161
|
-
_
|
|
162
|
-
_ $http({
|
|
163
|
-
_ url: '...',
|
|
164
|
-
_ method: 'GET',
|
|
165
|
-
_ transformResponse: appendTransform($http.defaults.transformResponse, function(value) {
|
|
166
|
-
* return doTransform(value);
|
|
167
|
-
* })
|
|
168
|
-
* });
|
|
169
|
-
* ```
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
* ## Caching
|
|
173
|
-
*
|
|
174
|
-
* {@link ng.$http `$http`} responses are not cached by default. To enable caching, you must
|
|
175
|
-
_ set the config.cache value or the default cache value to TRUE or to a cache object (created
|
|
176
|
-
_ with {@link ng.$cacheFactory `$cacheFactory`}). If defined, the value of config.cache takes
|
|
177
|
-
* precedence over the default cache value.
|
|
178
|
-
*
|
|
179
|
-
* In order to:
|
|
180
|
-
* * cache all responses - set the default cache value to TRUE or to a cache object
|
|
181
|
-
* * cache a specific response - set config.cache value to TRUE or to a cache object
|
|
182
|
-
*
|
|
183
|
-
* If caching is enabled, but neither the default cache nor config.cache are set to a cache object,
|
|
184
|
-
* then the default `$cacheFactory("$http")`object is used.
|
|
185
|
-
*
|
|
186
|
-
* The default cache value can be set by updating the
|
|
187
|
-
* {@link ng.$http#defaults`$http.defaults.cache`} property or the
|
|
188
|
-
* {@link $httpProvider#defaults `$httpProvider.defaults.cache`} property.
|
|
189
|
-
*
|
|
190
|
-
* When caching is enabled, {@link ng.$http `$http`} stores the response from the server using
|
|
191
|
-
* the relevant cache object. The next time the same request is made, the response is returned
|
|
192
|
-
* from the cache without sending a request to the server.
|
|
193
|
-
*
|
|
194
|
-
* Take note that:
|
|
195
|
-
*
|
|
196
|
-
* * Only GET and JSONP requests are cached.
|
|
197
|
-
* * The cache key is the request URL including search parameters; headers are not considered.
|
|
198
|
-
* * Cached responses are returned asynchronously, in the same way as responses from the server.
|
|
199
|
-
* * If multiple identical requests are made using the same cache, which is not yet populated,
|
|
200
|
-
* one request will be made to the server and remaining requests will return the same response.
|
|
201
|
-
* * A cache-control header on the response does not affect if or how responses are cached.
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
* ## Interceptors
|
|
205
|
-
*
|
|
206
|
-
* Before you start creating interceptors, be sure to understand the
|
|
207
|
-
* {@link ng.$q $q and deferred/promise APIs}.
|
|
208
|
-
*
|
|
209
|
-
* For purposes of global error handling, authentication, or any kind of synchronous or
|
|
210
|
-
* asynchronous pre-processing of request or postprocessing of responses, it is desirable to be
|
|
211
|
-
* able to intercept requests before they are handed to the server and
|
|
212
|
-
* responses before they are handed over to the application code that
|
|
213
|
-
* initiated these requests. The interceptors leverage the {@link ng.$q
|
|
214
|
-
_ promise APIs} to fulfill this need for both synchronous and asynchronous pre-processing.
|
|
215
|
-
_
|
|
216
|
-
_ The interceptors are service factories that are registered with the `$httpProvider` by
|
|
217
|
-
_ adding them to the `$httpProvider.interceptors` array. The factory is called and
|
|
218
|
-
_ injected with dependencies (if specified) and returns the interceptor.
|
|
219
|
-
_
|
|
220
|
-
_ There are two kinds of interceptors (and two kinds of rejection interceptors):
|
|
221
|
-
_ \* _ `request`: interceptors get called with a http {@link $http#usage config} object. The function is free to
|
|
222
|
-
_ modify the `config` object or create a new one. The function needs to return the `config`
|
|
223
|
-
_ object directly, or a promise containing the `config` or a new `config` object.
|
|
224
|
-
_ _ `requestError`: interceptor gets called when a previous interceptor threw an error or
|
|
225
|
-
_ resolved with a rejection. \* _ `response`: interceptors get called with http `response` object. The function is free to
|
|
226
|
-
_ modify the `response` object or create a new one. The function needs to return the `response`
|
|
227
|
-
_ object directly, or as a promise containing the `response` or a new `response` object.
|
|
228
|
-
_ _ `responseError`: interceptor gets called when a previous interceptor threw an error or
|
|
229
|
-
_ resolved with a rejection. \* \*
|
|
230
|
-
_ ```js
|
|
231
|
-
_ // register the interceptor as a service
|
|
232
|
-
_ $provide.factory('myHttpInterceptor', function($q, dependency1, dependency2) {
|
|
233
|
-
_ return {
|
|
234
|
-
_ // optional method
|
|
235
|
-
_ 'request': function(config) {
|
|
236
|
-
_ // do something on success
|
|
237
|
-
_ return config;
|
|
238
|
-
_ },
|
|
239
|
-
_
|
|
240
|
-
_ // optional method
|
|
241
|
-
_ 'requestError': function(rejection) {
|
|
242
|
-
_ // do something on error
|
|
243
|
-
_ if (canRecover(rejection)) {
|
|
244
|
-
_ return responseOrNewPromise
|
|
245
|
-
_ }
|
|
246
|
-
_ return $q.reject(rejection);
|
|
247
|
-
_ }, \* \* \*
|
|
248
|
-
_ // optional method
|
|
249
|
-
_ 'response': function(response) {
|
|
250
|
-
_ // do something on success
|
|
251
|
-
_ return response;
|
|
252
|
-
_ },
|
|
253
|
-
_
|
|
254
|
-
_ // optional method
|
|
255
|
-
_ 'responseError': function(rejection) {
|
|
256
|
-
_ // do something on error
|
|
257
|
-
_ if (canRecover(rejection)) {
|
|
258
|
-
_ return responseOrNewPromise
|
|
259
|
-
_ }
|
|
260
|
-
_ return $q.reject(rejection);
|
|
261
|
-
_ }
|
|
262
|
-
_ };
|
|
263
|
-
_ }); \*
|
|
264
|
-
_ $httpProvider.interceptors.push('myHttpInterceptor');
|
|
265
|
-
_ \*
|
|
266
|
-
_ // alternatively, register the interceptor via an anonymous factory
|
|
267
|
-
_ $httpProvider.interceptors.push(function($q, dependency1, dependency2) {
|
|
268
|
-
_ return {
|
|
269
|
-
_ 'request': function(config) {
|
|
270
|
-
_ // same as above
|
|
271
|
-
_ }, \*
|
|
272
|
-
_ 'response': function(response) {
|
|
273
|
-
_ // same as above
|
|
274
|
-
_ }
|
|
275
|
-
_ };
|
|
276
|
-
_ });
|
|
277
|
-
_ `` *
|
|
278
|
-
* ## Security Considerations
|
|
279
|
-
*
|
|
280
|
-
* When designing web applications, consider security threats from:
|
|
281
|
-
*
|
|
282
|
-
* - [JSON vulnerability](http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx)
|
|
283
|
-
* - [XSRF](http://en.wikipedia.org/wiki/Cross-site_request_forgery)
|
|
284
|
-
*
|
|
285
|
-
* Both server and the client must cooperate in order to eliminate these threats. AngularTS comes
|
|
286
|
-
* pre-configured with strategies that address these issues, but for this to work backend server
|
|
287
|
-
* cooperation is required.
|
|
288
|
-
*
|
|
289
|
-
* ### JSON Vulnerability Protection
|
|
290
|
-
*
|
|
291
|
-
* A [JSON vulnerability](http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx)
|
|
292
|
-
* allows third party website to turn your JSON resource URL into
|
|
293
|
-
* [JSONP](http://en.wikipedia.org/wiki/JSONP) request under some conditions. To
|
|
294
|
-
* counter this your server can prefix all JSON requests with following string `")]}',\n"`.
|
|
295
|
-
* AngularTS will automatically strip the prefix before processing it as JSON.
|
|
296
|
-
*
|
|
297
|
-
* For example if your server needs to return:
|
|
298
|
-
*``js
|
|
299
|
-
_ ['one','two']
|
|
300
|
-
_ ` *
|
|
301
|
-
* which is vulnerable to attack, your server can return:
|
|
302
|
-
*`js
|
|
303
|
-
_ )]}',
|
|
304
|
-
_ ['one','two']
|
|
305
|
-
_ ```
|
|
306
|
-
_
|
|
307
|
-
_ AngularTS will strip the prefix, before processing the JSON.
|
|
308
|
-
_ \*
|
|
309
|
-
_ ### Cross Site Request Forgery (XSRF) Protection
|
|
310
|
-
_
|
|
311
|
-
_ [XSRF](http://en.wikipedia.org/wiki/Cross-site_request_forgery) is an attack technique by
|
|
312
|
-
_ which the attacker can trick an authenticated user into unknowingly executing actions on your
|
|
313
|
-
_ website. AngularTS provides a mechanism to counter XSRF. When performing XHR requests, the
|
|
314
|
-
_ $http service reads a token from a cookie (by default, `XSRF-TOKEN`) and sets it as an HTTP
|
|
315
|
-
_ header (by default `X-XSRF-TOKEN`). Since only JavaScript that runs on your domain could read
|
|
316
|
-
_ the cookie, your server can be assured that the XHR came from JavaScript running on your
|
|
317
|
-
_ domain.
|
|
318
|
-
_
|
|
319
|
-
_ To take advantage of this, your server needs to set a token in a JavaScript readable session
|
|
320
|
-
_ cookie called `XSRF-TOKEN` on the first HTTP GET request. On subsequent XHR requests the
|
|
321
|
-
_ server can verify that the cookie matches the `X-XSRF-TOKEN` HTTP header, and therefore be
|
|
322
|
-
_ sure that only JavaScript running on your domain could have sent the request. The token must
|
|
323
|
-
_ be unique for each user and must be verifiable by the server (to prevent the JavaScript from
|
|
324
|
-
_ making up its own tokens). We recommend that the token is a digest of your site's
|
|
325
|
-
_ authentication cookie with a [salt](https://en.wikipedia.org/wiki/Salt_(cryptography))
|
|
326
|
-
\_ for added security. \* \* The header will — by default — **not** be set for cross-domain requests. This
|
|
327
|
-
_ prevents unauthorized servers (e.g. malicious or compromised 3rd-party APIs) from gaining
|
|
328
|
-
_ access to your users' XSRF tokens and exposing them to Cross Site Request Forgery. If you
|
|
329
|
-
_ want to, you can trust additional origins to also receive the XSRF token, by adding them
|
|
330
|
-
_ to {@link ng.$httpProvider#xsrfTrustedOrigins xsrfTrustedOrigins}. This might be
|
|
331
|
-
* useful, for example, if your application, served from `example.com`, needs to access your API
|
|
332
|
-
* at `api.example.com`.
|
|
333
|
-
* See {@link ng.$httpProvider#xsrfTrustedOrigins $httpProvider.xsrfTrustedOrigins} for
|
|
334
|
-
_ more details.
|
|
335
|
-
_
|
|
336
|
-
_ <div class="alert alert-danger">
|
|
337
|
-
_ **Warning**<br />
|
|
338
|
-
_ Only trusted origins that you have control over and make sure you understand the
|
|
339
|
-
_ implications of doing so.
|
|
340
|
-
_ </div>
|
|
341
|
-
_
|
|
342
|
-
_ The name of the cookie and the header can be specified using the `xsrfCookieName` and
|
|
343
|
-
_ `xsrfHeaderName` properties of either `$httpProvider.defaults` at config-time,
|
|
344
|
-
_ `$http.defaults` at run-time, or the per-request config object.
|
|
345
|
-
_
|
|
346
|
-
_ In order to prevent collisions in environments where multiple AngularTS apps share the
|
|
347
|
-
_ same domain or subdomain, we recommend that each application uses a unique cookie name. \* \*
|
|
348
|
-
_ @param {object} requestConfig Object describing the request to be made and how it should be
|
|
349
|
-
_ processed. The object has following properties: \* \* - **method** – `{string}` – HTTP method (e.g. 'GET', 'POST', etc) \* - **url** – `{string|TrustedObject}` – Absolute or relative URL of the resource that is being requested;
|
|
350
|
-
_ or an object created by a call to `$sce.trustAsResourceUrl(url)`.
|
|
351
|
-
_ - **params** – `{Object.<string|Object>}` – Map of strings or objects which will be serialized
|
|
352
|
-
_ with the `paramSerializer` and appended as GET parameters.
|
|
353
|
-
_ - **data** – `{string|Object}` – Data to be sent as the request message data. \* - **headers** – `{Object}` – Map of strings or functions which return strings representing
|
|
354
|
-
_ HTTP headers to send to the server. If the return value of a function is null, the
|
|
355
|
-
_ header will not be sent. Functions accept a config object as an argument. \* - **eventHandlers** - `{Object}` - Event listeners to be bound to the XMLHttpRequest object.
|
|
356
|
-
_ To bind events to the XMLHttpRequest upload object, use `uploadEventHandlers`.
|
|
357
|
-
_ The handler will be called in the context of a `$apply` block. \* - **uploadEventHandlers** - `{Object}` - Event listeners to be bound to the XMLHttpRequest upload
|
|
358
|
-
_ object. To bind events to the XMLHttpRequest object, use `eventHandlers`.
|
|
359
|
-
_ The handler will be called in the context of a `$apply` block. \* - **xsrfHeaderName** – `{string}` – Name of HTTP header to populate with the XSRF token. \* - **xsrfCookieName** – `{string}` – Name of cookie containing the XSRF token. \* - **transformRequest** –
|
|
360
|
-
_ `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
|
|
361
|
-
_ transform function or an array of such functions. The transform function takes the http
|
|
362
|
-
_ request body and headers and returns its transformed (typically serialized) version.
|
|
363
|
-
_ See {@link ng.$http#overriding-the-default-transformations-per-request
|
|
364
|
-
_ Overriding the Default Transformations}
|
|
365
|
-
_ - **transformResponse** –
|
|
366
|
-
_ `{function(data, headersGetter, status)|Array.<function(data, headersGetter, status)>}` –
|
|
367
|
-
_ transform function or an array of such functions. The transform function takes the http
|
|
368
|
-
_ response body, headers and status and returns its transformed (typically deserialized) version.
|
|
369
|
-
_ See {@link ng.$http#overriding-the-default-transformations-per-request
|
|
370
|
-
_ Overriding the Default Transformations}
|
|
371
|
-
_ - **paramSerializer** - `{string|function(Object<string,string>):string}` - A function used to
|
|
372
|
-
_ prepare the string representation of request parameters (specified as an object).
|
|
373
|
-
_ If specified as string, it is interpreted as function registered with the
|
|
374
|
-
_ {@link $injector $injector}, which means you can create your own serializer
|
|
375
|
-
_ by registering it as a {@link auto.$provide#service service}.
|
|
376
|
-
_ The default serializer is the {@link $httpParamSerializer $httpParamSerializer};
|
|
377
|
-
_ alternatively, you can use the {@link $httpParamSerializerJQLike $httpParamSerializerJQLike} \* - **cache** – `{boolean|Object}` – A boolean value or object created with
|
|
378
|
-
_ {@link ng.$cacheFactory `$cacheFactory`} to enable or disable caching of the HTTP response.
|
|
379
|
-
_ See {@link $http#caching $http Caching} for more information. \* - **timeout** – `{number|Promise}` – timeout in milliseconds, or {@link ng.$q promise}
|
|
380
|
-
* that should abort the request when resolved.
|
|
381
|
-
*
|
|
382
|
-
* A numerical timeout or a promise returned from {@link ng.$timeout $timeout}, will set
|
|
383
|
-
* the `xhrStatus` in the {@link $http#$http-returns response} to "timeout", and any other
|
|
384
|
-
_ resolved promise will set it to "abort", following standard XMLHttpRequest behavior.
|
|
385
|
-
_ \* - **withCredentials** - `{boolean}` - whether to set the `withCredentials` flag on the
|
|
386
|
-
_ XHR object. See [requests with credentials](https://developer.mozilla.org/docs/Web/HTTP/Access_control_CORS#Requests_with_credentials)
|
|
387
|
-
_ for more information. \* - **responseType** - `{string}` - see
|
|
388
|
-
_ [XMLHttpRequest.responseType](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#xmlhttprequest-responsetype).
|
|
389
|
-
_
|
|
390
|
-
_ @returns {PromiseLike} A {@link ng.$q `Promise}` that will be resolved (request success)
|
|
391
|
-
_ or rejected (request failure) with a response object. \*
|
|
392
|
-
_ The response object has these properties:
|
|
393
|
-
_ \* - **data** – `{string|Object}` – The response body transformed with
|
|
394
|
-
_ the transform functions.
|
|
395
|
-
_ - **status** – `{number}` – HTTP status code of the response. \* - **headers** – `{function([headerName])}` – Header getter function. \* - **config** – `{Object}` – The configuration object that was used
|
|
396
|
-
_ to generate the request.
|
|
397
|
-
_ - **statusText** – `{string}` – HTTP status text of the response. \* - **xhrStatus\*_ – `{string}` – Status of the XMLHttpRequest
|
|
398
|
-
_ (`complete`, `error`, `timeout` or `abort`). \* \*
|
|
399
|
-
_ A response status code between 200 and 299 is considered a success status
|
|
400
|
-
_ and will result in the success callback being called. Any response status
|
|
401
|
-
_ code outside of that range is considered an error status and will result
|
|
402
|
-
_ in the error callback being called.
|
|
403
|
-
_ Also, status codes less than -1 are normalized to zero. -1 usually means
|
|
404
|
-
_ the request was aborted, e.g. using a `config.timeout`. More information
|
|
405
|
-
_ about the status might be available in the `xhrStatus` property.
|
|
406
|
-
_
|
|
407
|
-
_ Note that if the response is a redirect, XMLHttpRequest will transparently
|
|
408
|
-
_ follow it, meaning that the outcome (success or error) will be determined
|
|
409
|
-
_ by the final response status code.
|
|
410
|
-
_ \*
|
|
411
|
-
_ @property {Array.<Object>} pendingRequests Array of config objects for currently pending
|
|
412
|
-
_ requests. This is primarily meant to be used for debugging purposes. \*
|
|
413
|
-
\*/
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { trimEmptyHash } from "../../shared/url-utils/url-utils.js";
|
|
2
|
-
import { isDefined, isPromiseLike, isUndefined } from "../../shared/utils.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* HTTP backend used by the `$http` that delegates to
|
|
6
|
-
* XMLHttpRequest object and deals with browser incompatibilities.
|
|
7
|
-
* You should never need to use this service directly.
|
|
8
|
-
*/
|
|
9
|
-
export class HttpBackendProvider {
|
|
10
|
-
constructor() {
|
|
11
|
-
this.$get = () => createHttpBackend();
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @returns
|
|
17
|
-
*/
|
|
18
|
-
export function createHttpBackend() {
|
|
19
|
-
/**
|
|
20
|
-
* Makes an HTTP request using XMLHttpRequest with flexible options.
|
|
21
|
-
*
|
|
22
|
-
* @param {string} method - The HTTP method (e.g., "GET", "POST").
|
|
23
|
-
* @param {string} [url] - The URL to send the request to. Defaults to the current page URL.
|
|
24
|
-
* @param {*} [post] - The body to send with the request, if any.
|
|
25
|
-
* @param {function(number, any, string|null, string, string): void} [callback] - Callback invoked when the request completes.
|
|
26
|
-
* @param {Object<string, string|undefined>} [headers] - Headers to set on the request.
|
|
27
|
-
* @param {number|Promise<any>} [timeout] - Timeout in ms or a cancellable promise.
|
|
28
|
-
* @param {boolean} [withCredentials] - Whether to send credentials with the request.
|
|
29
|
-
* @param {XMLHttpRequestResponseType} [responseType] - The type of data expected in the response.
|
|
30
|
-
* @param {Object<string, EventListener>} [eventHandlers] - Event listeners for the XMLHttpRequest object.
|
|
31
|
-
* @param {Object<string, EventListener>} [uploadEventHandlers] - Event listeners for the XMLHttpRequest.upload object.
|
|
32
|
-
* @returns {void}
|
|
33
|
-
*/
|
|
34
|
-
return function (
|
|
35
|
-
method,
|
|
36
|
-
url,
|
|
37
|
-
post,
|
|
38
|
-
callback,
|
|
39
|
-
headers,
|
|
40
|
-
timeout,
|
|
41
|
-
withCredentials,
|
|
42
|
-
responseType,
|
|
43
|
-
eventHandlers,
|
|
44
|
-
uploadEventHandlers,
|
|
45
|
-
) {
|
|
46
|
-
url = url || trimEmptyHash(window.location.href);
|
|
47
|
-
|
|
48
|
-
const xhr = new XMLHttpRequest();
|
|
49
|
-
let abortedByTimeout = false;
|
|
50
|
-
let timeoutId;
|
|
51
|
-
|
|
52
|
-
xhr.open(method, url, true);
|
|
53
|
-
|
|
54
|
-
if (headers) {
|
|
55
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
56
|
-
if (isDefined(value)) {
|
|
57
|
-
xhr.setRequestHeader(key, value);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
xhr.onload = () => {
|
|
63
|
-
let status = xhr.status || 0;
|
|
64
|
-
const statusText = xhr.statusText || "";
|
|
65
|
-
|
|
66
|
-
if (status === 0) {
|
|
67
|
-
status = xhr.response
|
|
68
|
-
? 200
|
|
69
|
-
: new URL(url).protocol === "file:"
|
|
70
|
-
? 404
|
|
71
|
-
: 0;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
completeRequest(
|
|
75
|
-
status,
|
|
76
|
-
xhr.response,
|
|
77
|
-
xhr.getAllResponseHeaders(),
|
|
78
|
-
statusText,
|
|
79
|
-
"complete",
|
|
80
|
-
);
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
xhr.onerror = () => completeRequest(-1, null, null, "", "error");
|
|
84
|
-
xhr.ontimeout = () => completeRequest(-1, null, null, "", "timeout");
|
|
85
|
-
|
|
86
|
-
xhr.onabort = () => {
|
|
87
|
-
completeRequest(
|
|
88
|
-
-1,
|
|
89
|
-
null,
|
|
90
|
-
null,
|
|
91
|
-
"",
|
|
92
|
-
abortedByTimeout ? "timeout" : "abort",
|
|
93
|
-
);
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
if (eventHandlers) {
|
|
97
|
-
for (const [key, handler] of Object.entries(eventHandlers)) {
|
|
98
|
-
xhr.addEventListener(key, handler);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (uploadEventHandlers) {
|
|
103
|
-
for (const [key, handler] of Object.entries(uploadEventHandlers)) {
|
|
104
|
-
xhr.upload.addEventListener(key, handler);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (withCredentials) {
|
|
109
|
-
xhr.withCredentials = true;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (responseType) {
|
|
113
|
-
try {
|
|
114
|
-
xhr.responseType = responseType;
|
|
115
|
-
} catch (e) {
|
|
116
|
-
if (responseType !== "json") throw e;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
xhr.send(isUndefined(post) ? null : post);
|
|
121
|
-
|
|
122
|
-
if (typeof timeout === "number" && timeout > 0) {
|
|
123
|
-
timeoutId = setTimeout(() => timeoutRequest("timeout"), timeout);
|
|
124
|
-
} else if (isPromiseLike(timeout)) {
|
|
125
|
-
/** @type {Promise} */ (timeout).then(() => {
|
|
126
|
-
timeoutRequest(isDefined(timeout["$$timeoutId"]) ? "timeout" : "abort");
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* @param {"timeout"|"abort"} reason
|
|
132
|
-
*/
|
|
133
|
-
function timeoutRequest(reason) {
|
|
134
|
-
abortedByTimeout = reason === "timeout";
|
|
135
|
-
if (xhr) xhr.abort();
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* @param {number} status - HTTP status code or -1 for network errors.
|
|
140
|
-
* @param {*} response - The parsed or raw response from the server.
|
|
141
|
-
* @param {string|null} headersString - The raw response headers as a string.
|
|
142
|
-
* @param {string} statusText - The status text returned by the server.
|
|
143
|
-
* @param {"complete"|"error"|"timeout"|"abort"} xhrStatus - Final status of the request.
|
|
144
|
-
*/
|
|
145
|
-
function completeRequest(
|
|
146
|
-
status,
|
|
147
|
-
response,
|
|
148
|
-
headersString,
|
|
149
|
-
statusText,
|
|
150
|
-
xhrStatus,
|
|
151
|
-
) {
|
|
152
|
-
if (isDefined(timeoutId)) {
|
|
153
|
-
clearTimeout(timeoutId);
|
|
154
|
-
}
|
|
155
|
-
callback(status, response, headersString, statusText, xhrStatus);
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
}
|