@angular-wave/angular.ts 0.0.66 → 0.0.67

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.
Files changed (64) hide show
  1. package/dist/angular-ts.esm.js +2 -2
  2. package/dist/angular-ts.umd.js +2 -2
  3. package/package.json +1 -1
  4. package/src/animations/animate-js.js +4 -4
  5. package/src/animations/animate-swap.js +3 -0
  6. package/src/core/compile/compile.js +3 -3
  7. package/src/core/controller/controller.js +0 -5
  8. package/src/core/di/injector.js +9 -12
  9. package/src/core/di/internal-injector.js +113 -60
  10. package/src/core/parser/parse.js +1 -12
  11. package/src/core/parser/parse.spec.js +96 -110
  12. package/src/core/timeout/timeout.js +110 -111
  13. package/src/directive/input/input.js +32 -726
  14. package/src/directive/input/input.md +706 -0
  15. package/src/directive/select/select.js +48 -122
  16. package/src/directive/select/select.md +74 -0
  17. package/src/directive/show-hide/show-hide.js +13 -224
  18. package/src/directive/show-hide/show-hide.md +257 -0
  19. package/src/filters/limit-to.spec.js +1 -1
  20. package/src/filters/order-by.spec.js +1 -1
  21. package/src/index.js +6 -2
  22. package/src/loader.js +7 -3
  23. package/src/public.js +1 -7
  24. package/src/router/state/state-builder.js +2 -4
  25. package/src/router/state/state-service.js +1 -1
  26. package/src/router/state-provider.js +1 -1
  27. package/src/router/template-factory.js +10 -10
  28. package/src/router/url/url-service.js +4 -4
  29. package/src/services/anchor-scroll.js +2 -2
  30. package/src/services/browser.js +2 -9
  31. package/src/services/cache-factory.js +0 -67
  32. package/src/services/cache-factory.md +75 -0
  33. package/src/services/cookie-reader.js +36 -55
  34. package/src/services/http/http.js +62 -587
  35. package/src/services/http/http.md +413 -0
  36. package/src/services/http-backend/http-backend.js +19 -44
  37. package/src/services/template-request.js +1 -9
  38. package/src/shared/jqlite/jqlite.js +4 -69
  39. package/src/types.js +2 -4
  40. package/types/animations/animate-swap.d.ts +4 -7
  41. package/types/core/compile/compile.d.ts +6 -6
  42. package/types/core/controller/controller.d.ts +0 -5
  43. package/types/core/di/internal-injector.d.ts +73 -18
  44. package/types/core/exception-handler.d.ts +1 -1
  45. package/types/core/parser/parse.d.ts +1 -1
  46. package/types/core/timeout/timeout.d.ts +16 -26
  47. package/types/directive/input/input.d.ts +19 -124
  48. package/types/directive/select/select.d.ts +7 -74
  49. package/types/directive/show-hide/show-hide.d.ts +11 -224
  50. package/types/loader.d.ts +4 -4
  51. package/types/router/state/state-builder.d.ts +1 -2
  52. package/types/router/state/state-service.d.ts +2 -2
  53. package/types/router/state-provider.d.ts +2 -2
  54. package/types/router/template-factory.d.ts +15 -15
  55. package/types/router/url/url-service.d.ts +4 -4
  56. package/types/services/anchor-scroll.d.ts +1 -1
  57. package/types/services/browser.d.ts +0 -10
  58. package/types/services/cache-factory.d.ts +0 -67
  59. package/types/services/cookie-reader.d.ts +2 -10
  60. package/types/services/http/http.d.ts +53 -61
  61. package/types/services/http-backend/http-backend.d.ts +8 -31
  62. package/types/services/template-request.d.ts +1 -9
  63. package/types/shared/jqlite/jqlite.d.ts +9 -9
  64. package/types/types.d.ts +1 -9
@@ -23,6 +23,7 @@ import {
23
23
  uppercase,
24
24
  isPromiseLike,
25
25
  } from "../../shared/utils";
26
+ import { getCookies } from "../cookie-reader";
26
27
 
27
28
  const APPLICATION_JSON = "application/json";
28
29
  const CONTENT_TYPE_APPLICATION_JSON = {
@@ -43,23 +44,18 @@ function serializeValue(v) {
43
44
  return v;
44
45
  }
45
46
 
47
+ /**
48
+ * Default params serializer that converts objects to strings
49
+ * according to the following rules:
50
+ *
51
+ * * `{'foo': 'bar'}` results in `foo=bar`
52
+ * * `{'foo': Date.now()}` results in `foo=2015-04-01T09%3A50%3A49.262Z` (`toISOString()` and encoded representation of a Date object)
53
+ * * `{'foo': ['bar', 'baz']}` results in `foo=bar&foo=baz` (repeated key for each array element)
54
+ * * `{'foo': {'bar':'baz'}}` results in `foo=%7B%22bar%22%3A%22baz%22%7D` (stringified and encoded representation of an object)
55
+ *
56
+ * Note that serializer will sort the request parameters alphabetically.
57
+ */
46
58
  export function $HttpParamSerializerProvider() {
47
- /**
48
- * @ngdoc service
49
- * @name $httpParamSerializer
50
- * @description
51
- *
52
- * Default {@link $http `$http`} params serializer that converts objects to strings
53
- * according to the following rules:
54
- *
55
- * * `{'foo': 'bar'}` results in `foo=bar`
56
- * * `{'foo': Date.now()}` results in `foo=2015-04-01T09%3A50%3A49.262Z` (`toISOString()` and encoded representation of a Date object)
57
- * * `{'foo': ['bar', 'baz']}` results in `foo=bar&foo=baz` (repeated key for each array element)
58
- * * `{'foo': {'bar':'baz'}}` results in `foo=%7B%22bar%22%3A%22baz%22%7D` (stringified and encoded representation of an object)
59
- *
60
- * Note that serializer will sort the request parameters alphabetically.
61
- */
62
-
63
59
  this.$get = function () {
64
60
  return function ngParamSerializer(params) {
65
61
  if (!params) return "";
@@ -67,7 +63,7 @@ export function $HttpParamSerializerProvider() {
67
63
  forEachSorted(params, (value, key) => {
68
64
  if (value === null || isUndefined(value) || isFunction(value)) return;
69
65
  if (Array.isArray(value)) {
70
- forEach(value, (v) => {
66
+ value.forEach((v) => {
71
67
  parts.push(
72
68
  `${encodeUriQuery(key)}=${encodeUriQuery(serializeValue(v))}`,
73
69
  );
@@ -84,51 +80,47 @@ export function $HttpParamSerializerProvider() {
84
80
  };
85
81
  }
86
82
 
83
+ /**
84
+ *
85
+ * Alternative {@link $http `$http`} params serializer that follows
86
+ * jQuery's [`param()`](http://api.jquery.com/jquery.param/) method logic.
87
+ * The serializer will also sort the params alphabetically.
88
+ *
89
+ * To use it for serializing `$http` request parameters, set it as the `paramSerializer` property:
90
+ *
91
+ * ```js
92
+ * $http({
93
+ * url: myUrl,
94
+ * method: 'GET',
95
+ * params: myParams,
96
+ * paramSerializer: '$httpParamSerializerJQLike'
97
+ * });
98
+ * ```
99
+ *
100
+ * It is also possible to set it as the default `paramSerializer` in the
101
+ * {@link $httpProvider#defaults `$httpProvider`}.
102
+ *
103
+ * Additionally, you can inject the serializer and use it explicitly, for example to serialize
104
+ * form data for submission:
105
+ *
106
+ * ```js
107
+ * .controller(function($http, $httpParamSerializerJQLike) {
108
+ * //...
109
+ *
110
+ * $http({
111
+ * url: myUrl,
112
+ * method: 'POST',
113
+ * data: $httpParamSerializerJQLike(myData),
114
+ * headers: {
115
+ * 'Content-Type': 'application/x-www-form-urlencoded'
116
+ * }
117
+ * });
118
+ *
119
+ * });
120
+ * ```
121
+ *
122
+ */
87
123
  export function $HttpParamSerializerJQLikeProvider() {
88
- /**
89
- * @ngdoc service
90
- * @name $httpParamSerializerJQLike
91
- *
92
- * @description
93
- *
94
- * Alternative {@link $http `$http`} params serializer that follows
95
- * jQuery's [`param()`](http://api.jquery.com/jquery.param/) method logic.
96
- * The serializer will also sort the params alphabetically.
97
- *
98
- * To use it for serializing `$http` request parameters, set it as the `paramSerializer` property:
99
- *
100
- * ```js
101
- * $http({
102
- * url: myUrl,
103
- * method: 'GET',
104
- * params: myParams,
105
- * paramSerializer: '$httpParamSerializerJQLike'
106
- * });
107
- * ```
108
- *
109
- * It is also possible to set it as the default `paramSerializer` in the
110
- * {@link $httpProvider#defaults `$httpProvider`}.
111
- *
112
- * Additionally, you can inject the serializer and use it explicitly, for example to serialize
113
- * form data for submission:
114
- *
115
- * ```js
116
- * .controller(function($http, $httpParamSerializerJQLike) {
117
- * //...
118
- *
119
- * $http({
120
- * url: myUrl,
121
- * method: 'POST',
122
- * data: $httpParamSerializerJQLike(myData),
123
- * headers: {
124
- * 'Content-Type': 'application/x-www-form-urlencoded'
125
- * }
126
- * });
127
- *
128
- * });
129
- * ```
130
- *
131
- */
132
124
  this.$get = function () {
133
125
  return function jQueryLikeParamSerializer(params) {
134
126
  if (!params) return "";
@@ -219,8 +211,7 @@ function parseHeaders(headers) {
219
211
  }
220
212
 
221
213
  if (isString(headers)) {
222
- forEach(
223
- headers.split("\n"),
214
+ headers.split("\n").forEach(
224
215
  /** @param {string} line */
225
216
  (line) => {
226
217
  i = line.indexOf(":");
@@ -308,10 +299,6 @@ function isSuccess(status) {
308
299
  */
309
300
  export function $HttpProvider() {
310
301
  /**
311
- * @ngdoc property
312
- * @name $httpProvider#defaults
313
- * @description
314
- *
315
302
  * Object containing default values for all {@link ng.$http $http} requests.
316
303
  *
317
304
  * - **`defaults.cache`** - {boolean|Object} - A boolean value or object created with
@@ -414,10 +401,6 @@ export function $HttpProvider() {
414
401
  };
415
402
 
416
403
  /**
417
- * @ngdoc property
418
- * @name $httpProvider#interceptors
419
- * @description
420
- *
421
404
  * Array containing service factories for all synchronous or asynchronous {@link ng.$http $http}
422
405
  * pre-processing of request or postprocessing of responses.
423
406
  *
@@ -429,10 +412,6 @@ export function $HttpProvider() {
429
412
  const interceptorFactories = (this.interceptors = []);
430
413
 
431
414
  /**
432
- * @ngdoc property
433
- * @name $httpProvider#xsrfTrustedOrigins
434
- * @description
435
- *
436
415
  * Array containing URLs whose origins are trusted to receive the XSRF token. See the
437
416
  * {@link ng.$http#security-considerations Security Considerations} sections for more details on
438
417
  * XSRF.
@@ -471,13 +450,6 @@ export function $HttpProvider() {
471
450
  const xsrfTrustedOrigins = (this.xsrfTrustedOrigins = []);
472
451
 
473
452
  /**
474
- * @ngdoc property
475
- * @name $httpProvider#xsrfWhitelistedOrigins
476
- * @description
477
- *
478
- * @deprecated
479
- * sinceVersion="1.8.1"
480
- *
481
453
  * This property is deprecated. Use {@link $httpProvider#xsrfTrustedOrigins xsrfTrustedOrigins}
482
454
  * instead.
483
455
  */
@@ -493,7 +465,6 @@ export function $HttpProvider() {
493
465
  this.$get = [
494
466
  "$browser",
495
467
  "$httpBackend",
496
- "$$cookieReader",
497
468
  "$cacheFactory",
498
469
  "$rootScope",
499
470
  "$q",
@@ -503,7 +474,6 @@ export function $HttpProvider() {
503
474
  *
504
475
  * @param {*} $browser
505
476
  * @param {*} $httpBackend
506
- * @param {*} $$cookieReader
507
477
  * @param {*} $cacheFactory
508
478
  * @param {*} $rootScope
509
479
  * @param {*} $q
@@ -514,7 +484,6 @@ export function $HttpProvider() {
514
484
  function (
515
485
  $browser,
516
486
  $httpBackend,
517
- $$cookieReader,
518
487
  $cacheFactory,
519
488
  $rootScope,
520
489
  $q,
@@ -537,7 +506,7 @@ export function $HttpProvider() {
537
506
  */
538
507
  const reversedInterceptors = [];
539
508
 
540
- forEach(interceptorFactories, (interceptorFactory) => {
509
+ interceptorFactories.forEach((interceptorFactory) => {
541
510
  reversedInterceptors.unshift(
542
511
  isString(interceptorFactory)
543
512
  ? $injector.get(interceptorFactory)
@@ -551,478 +520,8 @@ export function $HttpProvider() {
551
520
  const urlIsAllowedOrigin = urlIsAllowedOriginFactory(xsrfTrustedOrigins);
552
521
 
553
522
  /**
554
- * @ngdoc service
555
- * @kind function
556
- * @name $http
557
- * @requires ng.$httpBackend
558
- * @requires $cacheFactory
559
- * @requires $rootScope
560
- * @requires $q
561
- * @requires $injector
562
- *
563
- * @description
564
- * The `$http` service is a core AngularJS service that facilitates communication with the remote
565
- * HTTP servers via the browser's [XMLHttpRequest](https://developer.mozilla.org/en/xmlhttprequest)
566
- * object or via [JSONP](http://en.wikipedia.org/wiki/JSONP).
567
- *
568
- * For unit testing applications that use `$http` service, see
569
- * {@link ngMock.$httpBackend $httpBackend mock}.
570
- *
571
- * For a higher level of abstraction, please check out the {@link ngResource.$resource
572
- * $resource} service.
573
- *
574
- * The $http API is based on the {@link ng.$q deferred/promise APIs} exposed by
575
- * the $q service. While for simple usage patterns this doesn't matter much, for advanced usage
576
- * it is important to familiarize yourself with these APIs and the guarantees they provide.
577
- *
578
- *
579
- * ## General usage
580
- * The `$http` service is a function which takes a single argument — a {@link $http#usage configuration object} —
581
- * that is used to generate an HTTP request and returns a {@link ng.$q promise} that is
582
- * resolved (request success) or rejected (request failure) with a
583
- * {@link ng.$http#$http-returns response} object.
584
- *
585
- * ```js
586
- * // Simple GET request example:
587
- * $http({
588
- * method: 'GET',
589
- * url: '/someUrl'
590
- * }).then(function successCallback(response) {
591
- * // this callback will be called asynchronously
592
- * // when the response is available
593
- * }, function errorCallback(response) {
594
- * // called asynchronously if an error occurs
595
- * // or server returns response with an error status.
596
- * });
597
- * ```
598
- *
599
- *
600
- * ## Shortcut methods
601
- *
602
- * Shortcut methods are also available. All shortcut methods require passing in the URL, and
603
- * request data must be passed in for POST/PUT requests. An optional config can be passed as the
604
- * last argument.
605
- *
606
- * ```js
607
- * $http.get('/someUrl', config).then(successCallback, errorCallback);
608
- * $http.post('/someUrl', data, config).then(successCallback, errorCallback);
609
- * ```
610
- *
611
- * Complete list of shortcut methods:
612
- *
613
- * - {@link ng.$http#get $http.get}
614
- * - {@link ng.$http#head $http.head}
615
- * - {@link ng.$http#post $http.post}
616
- * - {@link ng.$http#put $http.put}
617
- * - {@link ng.$http#delete $http.delete}
618
- * - {@link ng.$http#patch $http.patch}
619
- *
620
- *
621
- * ```
622
- * $http.get(...);
623
- * $httpBackend.flush();
624
- * ```
625
- *
626
- * ## Setting HTTP Headers
627
- *
628
- * The $http service will automatically add certain HTTP headers to all requests. These defaults
629
- * can be fully configured by accessing the `$httpProvider.defaults.headers` configuration
630
- * object, which currently contains this default configuration:
631
- *
632
- * - `$httpProvider.defaults.headers.common` (headers that are common for all requests):
633
- * - <code>Accept: application/json, text/plain, \*&#65279;/&#65279;\*</code>
634
- * - `$httpProvider.defaults.headers.post`: (header defaults for POST requests)
635
- * - `Content-Type: application/json`
636
- * - `$httpProvider.defaults.headers.put` (header defaults for PUT requests)
637
- * - `Content-Type: application/json`
638
- *
639
- * To add or overwrite these defaults, simply add or remove a property from these configuration
640
- * objects. To add headers for an HTTP method other than POST or PUT, simply add a new object
641
- * with the lowercased HTTP method name as the key, e.g.
642
- * `$httpProvider.defaults.headers.get = { 'My-Header' : 'value' }`.
643
- *
644
- * The defaults can also be set at runtime via the `$http.defaults` object in the same
645
- * fashion. For example:
646
- *
647
- * ```
648
- * module.run(function($http) {
649
- * $http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w';
650
- * });
651
- * ```
652
- *
653
- * In addition, you can supply a `headers` property in the config object passed when
654
- * calling `$http(config)`, which overrides the defaults without changing them globally.
655
- *
656
- * To explicitly remove a header automatically added via $httpProvider.defaults.headers on a per request basis,
657
- * Use the `headers` property, setting the desired header to `undefined`. For example:
658
- *
659
- * ```js
660
- * let req = {
661
- * method: 'POST',
662
- * url: 'http://example.com',
663
- * headers: {
664
- * 'Content-Type': undefined
665
- * },
666
- * data: { test: 'test' }
667
- * }
668
- *
669
- * $http(req).then(function(){...}, function(){...});
670
- * ```
671
- *
672
- * ## Transforming Requests and Responses
673
- *
674
- * Both requests and responses can be transformed using transformation functions: `transformRequest`
675
- * and `transformResponse`. These properties can be a single function that returns
676
- * the transformed value (`function(data, headersGetter, status)`) or an array of such transformation functions,
677
- * which allows you to `push` or `unshift` a new transformation function into the transformation chain.
678
- *
679
- * <div class="alert alert-warning">
680
- * **Note:** AngularJS does not make a copy of the `data` parameter before it is passed into the `transformRequest` pipeline.
681
- * That means changes to the properties of `data` are not local to the transform function (since Javascript passes objects by reference).
682
- * For example, when calling `$http.get(url, $scope.myObject)`, modifications to the object's properties in a transformRequest
683
- * function will be reflected on the scope and in any templates where the object is data-bound.
684
- * To prevent this, transform functions should have no side-effects.
685
- * If you need to modify properties, it is recommended to make a copy of the data, or create new object to return.
686
- * </div>
687
- *
688
- * ### Default Transformations
689
- *
690
- * The `$httpProvider` provider and `$http` service expose `defaults.transformRequest` and
691
- * `defaults.transformResponse` properties. If a request does not provide its own transformations
692
- * then these will be applied.
693
- *
694
- * You can augment or replace the default transformations by modifying these properties by adding to or
695
- * replacing the array.
696
- *
697
- * AngularJS provides the following default transformations:
698
- *
699
- * Request transformations (`$httpProvider.defaults.transformRequest` and `$http.defaults.transformRequest`) is
700
- * an array with one function that does the following:
701
- *
702
- * - If the `data` property of the request configuration object contains an object, serialize it
703
- * into JSON format.
704
- *
705
- * Response transformations (`$httpProvider.defaults.transformResponse` and `$http.defaults.transformResponse`) is
706
- * an array with one function that does the following:
707
- *
708
- * - If XSRF prefix is detected, strip it (see Security Considerations section below).
709
- * - If the `Content-Type` is `application/json` or the response looks like JSON,
710
- * deserialize it using a JSON parser.
711
- *
712
- *
713
- * ### Overriding the Default Transformations Per Request
714
- *
715
- * If you wish to override the request/response transformations only for a single request then provide
716
- * `transformRequest` and/or `transformResponse` properties on the configuration object passed
717
- * into `$http`.
718
- *
719
- * Note that if you provide these properties on the config object the default transformations will be
720
- * overwritten. If you wish to augment the default transformations then you must include them in your
721
- * local transformation array.
722
- *
723
- * The following code demonstrates adding a new response transformation to be run after the default response
724
- * transformations have been run.
725
- *
726
- * ```js
727
- * function appendTransform(defaults, transform) {
728
- *
729
- * // We can't guarantee that the default transformation is an array
730
- * defaults = angular.isArray(defaults) ? defaults : [defaults];
731
- *
732
- * // Append the new transformation to the defaults
733
- * return defaults.concat(transform);
734
- * }
735
- *
736
- * $http({
737
- * url: '...',
738
- * method: 'GET',
739
- * transformResponse: appendTransform($http.defaults.transformResponse, function(value) {
740
- * return doTransform(value);
741
- * })
742
- * });
743
- * ```
744
- *
745
- *
746
- * ## Caching
747
- *
748
- * {@link ng.$http `$http`} responses are not cached by default. To enable caching, you must
749
- * set the config.cache value or the default cache value to TRUE or to a cache object (created
750
- * with {@link ng.$cacheFactory `$cacheFactory`}). If defined, the value of config.cache takes
751
- * precedence over the default cache value.
752
- *
753
- * In order to:
754
- * * cache all responses - set the default cache value to TRUE or to a cache object
755
- * * cache a specific response - set config.cache value to TRUE or to a cache object
756
- *
757
- * If caching is enabled, but neither the default cache nor config.cache are set to a cache object,
758
- * then the default `$cacheFactory("$http")` object is used.
759
- *
760
- * The default cache value can be set by updating the
761
- * {@link ng.$http#defaults `$http.defaults.cache`} property or the
762
- * {@link $httpProvider#defaults `$httpProvider.defaults.cache`} property.
763
- *
764
- * When caching is enabled, {@link ng.$http `$http`} stores the response from the server using
765
- * the relevant cache object. The next time the same request is made, the response is returned
766
- * from the cache without sending a request to the server.
767
- *
768
- * Take note that:
769
- *
770
- * * Only GET and JSONP requests are cached.
771
- * * The cache key is the request URL including search parameters; headers are not considered.
772
- * * Cached responses are returned asynchronously, in the same way as responses from the server.
773
- * * If multiple identical requests are made using the same cache, which is not yet populated,
774
- * one request will be made to the server and remaining requests will return the same response.
775
- * * A cache-control header on the response does not affect if or how responses are cached.
776
- *
777
- *
778
- * ## Interceptors
779
- *
780
- * Before you start creating interceptors, be sure to understand the
781
- * {@link ng.$q $q and deferred/promise APIs}.
782
- *
783
- * For purposes of global error handling, authentication, or any kind of synchronous or
784
- * asynchronous pre-processing of request or postprocessing of responses, it is desirable to be
785
- * able to intercept requests before they are handed to the server and
786
- * responses before they are handed over to the application code that
787
- * initiated these requests. The interceptors leverage the {@link ng.$q
788
- * promise APIs} to fulfill this need for both synchronous and asynchronous pre-processing.
789
- *
790
- * The interceptors are service factories that are registered with the `$httpProvider` by
791
- * adding them to the `$httpProvider.interceptors` array. The factory is called and
792
- * injected with dependencies (if specified) and returns the interceptor.
793
- *
794
- * There are two kinds of interceptors (and two kinds of rejection interceptors):
795
- *
796
- * * `request`: interceptors get called with a http {@link $http#usage config} object. The function is free to
797
- * modify the `config` object or create a new one. The function needs to return the `config`
798
- * object directly, or a promise containing the `config` or a new `config` object.
799
- * * `requestError`: interceptor gets called when a previous interceptor threw an error or
800
- * resolved with a rejection.
801
- * * `response`: interceptors get called with http `response` object. The function is free to
802
- * modify the `response` object or create a new one. The function needs to return the `response`
803
- * object directly, or as a promise containing the `response` or a new `response` object.
804
- * * `responseError`: interceptor gets called when a previous interceptor threw an error or
805
- * resolved with a rejection.
806
- *
807
- *
808
- * ```js
809
- * // register the interceptor as a service
810
- * $provide.factory('myHttpInterceptor', function($q, dependency1, dependency2) {
811
- * return {
812
- * // optional method
813
- * 'request': function(config) {
814
- * // do something on success
815
- * return config;
816
- * },
817
- *
818
- * // optional method
819
- * 'requestError': function(rejection) {
820
- * // do something on error
821
- * if (canRecover(rejection)) {
822
- * return responseOrNewPromise
823
- * }
824
- * return $q.reject(rejection);
825
- * },
826
- *
827
- *
828
- *
829
- * // optional method
830
- * 'response': function(response) {
831
- * // do something on success
832
- * return response;
833
- * },
834
- *
835
- * // optional method
836
- * 'responseError': function(rejection) {
837
- * // do something on error
838
- * if (canRecover(rejection)) {
839
- * return responseOrNewPromise
840
- * }
841
- * return $q.reject(rejection);
842
- * }
843
- * };
844
- * });
845
- *
846
- * $httpProvider.interceptors.push('myHttpInterceptor');
847
- *
848
- *
849
- * // alternatively, register the interceptor via an anonymous factory
850
- * $httpProvider.interceptors.push(function($q, dependency1, dependency2) {
851
- * return {
852
- * 'request': function(config) {
853
- * // same as above
854
- * },
855
- *
856
- * 'response': function(response) {
857
- * // same as above
858
- * }
859
- * };
860
- * });
861
- * ```
862
- *
863
- * ## Security Considerations
864
- *
865
- * When designing web applications, consider security threats from:
866
- *
867
- * - [JSON vulnerability](http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx)
868
- * - [XSRF](http://en.wikipedia.org/wiki/Cross-site_request_forgery)
869
- *
870
- * Both server and the client must cooperate in order to eliminate these threats. AngularJS comes
871
- * pre-configured with strategies that address these issues, but for this to work backend server
872
- * cooperation is required.
873
- *
874
- * ### JSON Vulnerability Protection
875
- *
876
- * A [JSON vulnerability](http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx)
877
- * allows third party website to turn your JSON resource URL into
878
- * [JSONP](http://en.wikipedia.org/wiki/JSONP) request under some conditions. To
879
- * counter this your server can prefix all JSON requests with following string `")]}',\n"`.
880
- * AngularJS will automatically strip the prefix before processing it as JSON.
881
- *
882
- * For example if your server needs to return:
883
- * ```js
884
- * ['one','two']
885
- * ```
886
- *
887
- * which is vulnerable to attack, your server can return:
888
- * ```js
889
- * )]}',
890
- * ['one','two']
891
- * ```
892
- *
893
- * AngularJS will strip the prefix, before processing the JSON.
894
- *
895
- *
896
- * ### Cross Site Request Forgery (XSRF) Protection
897
- *
898
- * [XSRF](http://en.wikipedia.org/wiki/Cross-site_request_forgery) is an attack technique by
899
- * which the attacker can trick an authenticated user into unknowingly executing actions on your
900
- * website. AngularJS provides a mechanism to counter XSRF. When performing XHR requests, the
901
- * $http service reads a token from a cookie (by default, `XSRF-TOKEN`) and sets it as an HTTP
902
- * header (by default `X-XSRF-TOKEN`). Since only JavaScript that runs on your domain could read
903
- * the cookie, your server can be assured that the XHR came from JavaScript running on your
904
- * domain.
905
- *
906
- * To take advantage of this, your server needs to set a token in a JavaScript readable session
907
- * cookie called `XSRF-TOKEN` on the first HTTP GET request. On subsequent XHR requests the
908
- * server can verify that the cookie matches the `X-XSRF-TOKEN` HTTP header, and therefore be
909
- * sure that only JavaScript running on your domain could have sent the request. The token must
910
- * be unique for each user and must be verifiable by the server (to prevent the JavaScript from
911
- * making up its own tokens). We recommend that the token is a digest of your site's
912
- * authentication cookie with a [salt](https://en.wikipedia.org/wiki/Salt_(cryptography&#41;)
913
- * for added security.
914
- *
915
- * The header will &mdash; by default &mdash; **not** be set for cross-domain requests. This
916
- * prevents unauthorized servers (e.g. malicious or compromised 3rd-party APIs) from gaining
917
- * access to your users' XSRF tokens and exposing them to Cross Site Request Forgery. If you
918
- * want to, you can trust additional origins to also receive the XSRF token, by adding them
919
- * to {@link ng.$httpProvider#xsrfTrustedOrigins xsrfTrustedOrigins}. This might be
920
- * useful, for example, if your application, served from `example.com`, needs to access your API
921
- * at `api.example.com`.
922
- * See {@link ng.$httpProvider#xsrfTrustedOrigins $httpProvider.xsrfTrustedOrigins} for
923
- * more details.
924
- *
925
- * <div class="alert alert-danger">
926
- * **Warning**<br />
927
- * Only trusted origins that you have control over and make sure you understand the
928
- * implications of doing so.
929
- * </div>
930
- *
931
- * The name of the cookie and the header can be specified using the `xsrfCookieName` and
932
- * `xsrfHeaderName` properties of either `$httpProvider.defaults` at config-time,
933
- * `$http.defaults` at run-time, or the per-request config object.
934
- *
935
- * In order to prevent collisions in environments where multiple AngularJS apps share the
936
- * same domain or subdomain, we recommend that each application uses a unique cookie name.
937
- *
938
- *
939
- * @param {object} config Object describing the request to be made and how it should be
940
- * processed. The object has following properties:
941
- *
942
- * - **method** – `{string}` – HTTP method (e.g. 'GET', 'POST', etc)
943
- * - **url** – `{string|TrustedObject}` – Absolute or relative URL of the resource that is being requested;
944
- * or an object created by a call to `$sce.trustAsResourceUrl(url)`.
945
- * - **params** – `{Object.<string|Object>}` – Map of strings or objects which will be serialized
946
- * with the `paramSerializer` and appended as GET parameters.
947
- * - **data** – `{string|Object}` – Data to be sent as the request message data.
948
- * - **headers** – `{Object}` – Map of strings or functions which return strings representing
949
- * HTTP headers to send to the server. If the return value of a function is null, the
950
- * header will not be sent. Functions accept a config object as an argument.
951
- * - **eventHandlers** - `{Object}` - Event listeners to be bound to the XMLHttpRequest object.
952
- * To bind events to the XMLHttpRequest upload object, use `uploadEventHandlers`.
953
- * The handler will be called in the context of a `$apply` block.
954
- * - **uploadEventHandlers** - `{Object}` - Event listeners to be bound to the XMLHttpRequest upload
955
- * object. To bind events to the XMLHttpRequest object, use `eventHandlers`.
956
- * The handler will be called in the context of a `$apply` block.
957
- * - **xsrfHeaderName** – `{string}` – Name of HTTP header to populate with the XSRF token.
958
- * - **xsrfCookieName** – `{string}` – Name of cookie containing the XSRF token.
959
- * - **transformRequest** –
960
- * `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
961
- * transform function or an array of such functions. The transform function takes the http
962
- * request body and headers and returns its transformed (typically serialized) version.
963
- * See {@link ng.$http#overriding-the-default-transformations-per-request
964
- * Overriding the Default Transformations}
965
- * - **transformResponse** –
966
- * `{function(data, headersGetter, status)|Array.<function(data, headersGetter, status)>}` –
967
- * transform function or an array of such functions. The transform function takes the http
968
- * response body, headers and status and returns its transformed (typically deserialized) version.
969
- * See {@link ng.$http#overriding-the-default-transformations-per-request
970
- * Overriding the Default Transformations}
971
- * - **paramSerializer** - `{string|function(Object<string,string>):string}` - A function used to
972
- * prepare the string representation of request parameters (specified as an object).
973
- * If specified as string, it is interpreted as function registered with the
974
- * {@link $injector $injector}, which means you can create your own serializer
975
- * by registering it as a {@link auto.$provide#service service}.
976
- * The default serializer is the {@link $httpParamSerializer $httpParamSerializer};
977
- * alternatively, you can use the {@link $httpParamSerializerJQLike $httpParamSerializerJQLike}
978
- * - **cache** – `{boolean|Object}` – A boolean value or object created with
979
- * {@link ng.$cacheFactory `$cacheFactory`} to enable or disable caching of the HTTP response.
980
- * See {@link $http#caching $http Caching} for more information.
981
- * - **timeout** – `{number|Promise}` – timeout in milliseconds, or {@link ng.$q promise}
982
- * that should abort the request when resolved.
983
- *
984
- * A numerical timeout or a promise returned from {@link ng.$timeout $timeout}, will set
985
- * the `xhrStatus` in the {@link $http#$http-returns response} to "timeout", and any other
986
- * resolved promise will set it to "abort", following standard XMLHttpRequest behavior.
987
- *
988
- * - **withCredentials** - `{boolean}` - whether to set the `withCredentials` flag on the
989
- * XHR object. See [requests with credentials](https://developer.mozilla.org/docs/Web/HTTP/Access_control_CORS#Requests_with_credentials)
990
- * for more information.
991
- * - **responseType** - `{string}` - see
992
- * [XMLHttpRequest.responseType](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#xmlhttprequest-responsetype).
993
- *
994
- * @returns {HttpPromise} A {@link ng.$q `Promise}` that will be resolved (request success)
995
- * or rejected (request failure) with a response object.
996
- *
997
- * The response object has these properties:
998
- *
999
- * - **data** – `{string|Object}` – The response body transformed with
1000
- * the transform functions.
1001
- * - **status** – `{number}` – HTTP status code of the response.
1002
- * - **headers** – `{function([headerName])}` – Header getter function.
1003
- * - **config** – `{Object}` – The configuration object that was used
1004
- * to generate the request.
1005
- * - **statusText** – `{string}` – HTTP status text of the response.
1006
- * - **xhrStatus** – `{string}` – Status of the XMLHttpRequest
1007
- * (`complete`, `error`, `timeout` or `abort`).
1008
- *
1009
- *
1010
- * A response status code between 200 and 299 is considered a success status
1011
- * and will result in the success callback being called. Any response status
1012
- * code outside of that range is considered an error status and will result
1013
- * in the error callback being called.
1014
- * Also, status codes less than -1 are normalized to zero. -1 usually means
1015
- * the request was aborted, e.g. using a `config.timeout`. More information
1016
- * about the status might be available in the `xhrStatus` property.
1017
- *
1018
- * Note that if the response is a redirect, XMLHttpRequest will transparently
1019
- * follow it, meaning that the outcome (success or error) will be determined
1020
- * by the final response status code.
1021
- *
1022
- *
1023
- * @property {Array.<Object>} pendingRequests Array of config objects for currently pending
1024
- * requests. This is primarily meant to be used for debugging purposes.
1025
- *
523
+ * @property {Array.<Object>} requestConfig Array of config objects for currently pending
524
+ * requests. This is primarily meant to be used for debugging purposes.
1026
525
  */
1027
526
  function $http(requestConfig) {
1028
527
  if (!isObject(requestConfig)) {
@@ -1189,13 +688,9 @@ export function $HttpProvider() {
1189
688
  $http.pendingRequests = [];
1190
689
 
1191
690
  /**
1192
- * @ngdoc method
1193
- * @name $http#get
1194
- *
1195
- * @description
1196
691
  * Shortcut method to perform `GET` request.
1197
692
  *
1198
- * @param {string|TrustedObject} url Absolute or relative URL of the resource that is being requested;
693
+ * @param {string} url Absolute or relative URL of the resource that is being requested;
1199
694
  * or an object created by a call to `$sce.trustAsResourceUrl(url)`.
1200
695
  * @param {Object=} config Optional configuration object. See {@link ng.$http#$http-arguments `$http()` arguments}.
1201
696
  * @returns {HttpPromise} A Promise that will be resolved or rejected with a response object.
@@ -1203,13 +698,9 @@ export function $HttpProvider() {
1203
698
  */
1204
699
 
1205
700
  /**
1206
- * @ngdoc method
1207
- * @name $http#delete
1208
- *
1209
- * @description
1210
701
  * Shortcut method to perform `DELETE` request.
1211
702
  *
1212
- * @param {string|TrustedObject} url Absolute or relative URL of the resource that is being requested;
703
+ * @param {string} url Absolute or relative URL of the resource that is being requested;
1213
704
  * or an object created by a call to `$sce.trustAsResourceUrl(url)`.
1214
705
  * @param {Object=} config Optional configuration object. See {@link ng.$http#$http-arguments `$http()` arguments}.
1215
706
  * @returns {HttpPromise} A Promise that will be resolved or rejected with a response object.
@@ -1217,13 +708,9 @@ export function $HttpProvider() {
1217
708
  */
1218
709
 
1219
710
  /**
1220
- * @ngdoc method
1221
- * @name $http#head
1222
- *
1223
- * @description
1224
711
  * Shortcut method to perform `HEAD` request.
1225
712
  *
1226
- * @param {string|TrustedObject} url Absolute or relative URL of the resource that is being requested;
713
+ * @param {string} url Absolute or relative URL of the resource that is being requested;
1227
714
  * or an object created by a call to `$sce.trustAsResourceUrl(url)`.
1228
715
  * @param {Object=} config Optional configuration object. See {@link ng.$http#$http-arguments `$http()` arguments}.
1229
716
  * @returns {HttpPromise} A Promise that will be resolved or rejected with a response object.
@@ -1231,10 +718,6 @@ export function $HttpProvider() {
1231
718
  */
1232
719
 
1233
720
  /**
1234
- * @ngdoc method
1235
- * @name $http#jsonp
1236
- *
1237
- * @description
1238
721
  * Shortcut method to perform `JSONP` request.
1239
722
  *
1240
723
  * Note that, since JSONP requests are sensitive because the response is given full access to the browser,
@@ -1258,7 +741,7 @@ export function $HttpProvider() {
1258
741
  * If you would like to customise where and how the callbacks are stored then try overriding
1259
742
  * or decorating the {@link $jsonpCallbacks} service.
1260
743
  *
1261
- * @param {string|TrustedObject} url Absolute or relative URL of the resource that is being requested;
744
+ * @param {string} url Absolute or relative URL of the resource that is being requested;
1262
745
  * or an object created by a call to `$sce.trustAsResourceUrl(url)`.
1263
746
  * @param {Object=} config Optional configuration object. See {@link ng.$http#$http-arguments `$http()` arguments}.
1264
747
  * @returns {HttpPromise} A Promise that will be resolved or rejected with a response object.
@@ -1267,10 +750,6 @@ export function $HttpProvider() {
1267
750
  createShortMethods("get", "delete", "head");
1268
751
 
1269
752
  /**
1270
- * @ngdoc method
1271
- * @name $http#post
1272
- *
1273
- * @description
1274
753
  * Shortcut method to perform `POST` request.
1275
754
  *
1276
755
  * @param {string} url Relative or absolute URL specifying the destination of the request
@@ -1281,10 +760,6 @@ export function $HttpProvider() {
1281
760
  */
1282
761
 
1283
762
  /**
1284
- * @ngdoc method
1285
- * @name $http#put
1286
- *
1287
- * @description
1288
763
  * Shortcut method to perform `PUT` request.
1289
764
  *
1290
765
  * @param {string} url Relative or absolute URL specifying the destination of the request
@@ -1419,7 +894,7 @@ export function $HttpProvider() {
1419
894
  // send the request to the backend
1420
895
  if (isUndefined(cachedResp)) {
1421
896
  const xsrfValue = urlIsAllowedOrigin(config.url)
1422
- ? $$cookieReader()[config.xsrfCookieName || defaults.xsrfCookieName]
897
+ ? getCookies()[config.xsrfCookieName || defaults.xsrfCookieName]
1423
898
  : undefined;
1424
899
  if (xsrfValue) {
1425
900
  reqHeaders[config.xsrfHeaderName || defaults.xsrfHeaderName] =