1
|
import { Headers } from './headers';
|
2
|
import { ResponseOptionsArgs } from './interfaces';
|
3
|
/**
|
4
|
* Creates a response options object to be optionally provided when instantiating a
|
5
|
* {@link Response}.
|
6
|
*
|
7
|
* This class is based on the `ResponseInit` description in the [Fetch
|
8
|
* Spec](https://fetch.spec.whatwg.org/#responseinit).
|
9
|
*
|
10
|
* All values are null by default. Typical defaults can be found in the
|
11
|
* {@link BaseResponseOptions} class, which sub-classes `ResponseOptions`.
|
12
|
*
|
13
|
* This class may be used in tests to build {@link Response Responses} for
|
14
|
* mock responses (see {@link MockBackend}).
|
15
|
*
|
16
|
* ### Example ([live demo](http://plnkr.co/edit/P9Jkk8e8cz6NVzbcxEsD?p=preview))
|
17
|
*
|
18
|
* ```typescript
|
19
|
* import {ResponseOptions, Response} from '@angular/http';
|
20
|
*
|
21
|
* var options = new ResponseOptions({
|
22
|
* body: '{"name":"Jeff"}'
|
23
|
* });
|
24
|
* var res = new Response(options);
|
25
|
*
|
26
|
* console.log('res.json():', res.json()); // Object {name: "Jeff"}
|
27
|
* ```
|
28
|
*
|
29
|
* @experimental
|
30
|
*/
|
31
|
export declare class ResponseOptions {
|
32
|
/**
|
33
|
* String, Object, ArrayBuffer or Blob representing the body of the {@link Response}.
|
34
|
*/
|
35
|
body: string | Object | ArrayBuffer | Blob | null;
|
36
|
/**
|
37
|
* Http {@link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html status code}
|
38
|
* associated with the response.
|
39
|
*/
|
40
|
status: number | null;
|
41
|
/**
|
42
|
* Response {@link Headers headers}
|
43
|
*/
|
44
|
headers: Headers | null;
|
45
|
url: string | null;
|
46
|
constructor(opts?: ResponseOptionsArgs);
|
47
|
/**
|
48
|
* Creates a copy of the `ResponseOptions` instance, using the optional input as values to
|
49
|
* override
|
50
|
* existing values. This method will not change the values of the instance on which it is being
|
51
|
* called.
|
52
|
*
|
53
|
* This may be useful when sharing a base `ResponseOptions` object inside tests,
|
54
|
* where certain properties may change from test to test.
|
55
|
*
|
56
|
* ### Example ([live demo](http://plnkr.co/edit/1lXquqFfgduTFBWjNoRE?p=preview))
|
57
|
*
|
58
|
* ```typescript
|
59
|
* import {ResponseOptions, Response} from '@angular/http';
|
60
|
*
|
61
|
* var options = new ResponseOptions({
|
62
|
* body: {name: 'Jeff'}
|
63
|
* });
|
64
|
* var res = new Response(options.merge({
|
65
|
* url: 'https://google.com'
|
66
|
* }));
|
67
|
* console.log('options.url:', options.url); // null
|
68
|
* console.log('res.json():', res.json()); // Object {name: "Jeff"}
|
69
|
* console.log('res.url:', res.url); // https://google.com
|
70
|
* ```
|
71
|
*/
|
72
|
merge(options?: ResponseOptionsArgs): ResponseOptions;
|
73
|
}
|
74
|
/**
|
75
|
* Subclass of {@link ResponseOptions}, with default values.
|
76
|
*
|
77
|
* Default values:
|
78
|
* * status: 200
|
79
|
* * headers: empty {@link Headers} object
|
80
|
*
|
81
|
* This class could be extended and bound to the {@link ResponseOptions} class
|
82
|
* when configuring an {@link Injector}, in order to override the default options
|
83
|
* used by {@link Http} to create {@link Response Responses}.
|
84
|
*
|
85
|
* ### Example ([live demo](http://plnkr.co/edit/qv8DLT?p=preview))
|
86
|
*
|
87
|
* ```typescript
|
88
|
* import {provide} from '@angular/core';
|
89
|
* import {bootstrap} from '@angular/platform-browser/browser';
|
90
|
* import {HTTP_PROVIDERS, Headers, Http, BaseResponseOptions, ResponseOptions} from
|
91
|
* '@angular/http';
|
92
|
* import {App} from './myapp';
|
93
|
*
|
94
|
* class MyOptions extends BaseResponseOptions {
|
95
|
* headers:Headers = new Headers({network: 'github'});
|
96
|
* }
|
97
|
*
|
98
|
* bootstrap(App, [HTTP_PROVIDERS, {provide: ResponseOptions, useClass: MyOptions}]);
|
99
|
* ```
|
100
|
*
|
101
|
* The options could also be extended when manually creating a {@link Response}
|
102
|
* object.
|
103
|
*
|
104
|
* ### Example ([live demo](http://plnkr.co/edit/VngosOWiaExEtbstDoix?p=preview))
|
105
|
*
|
106
|
* ```
|
107
|
* import {BaseResponseOptions, Response} from '@angular/http';
|
108
|
*
|
109
|
* var options = new BaseResponseOptions();
|
110
|
* var res = new Response(options.merge({
|
111
|
* body: 'Angular',
|
112
|
* headers: new Headers({framework: 'angular'})
|
113
|
* }));
|
114
|
* console.log('res.headers.get("framework"):', res.headers.get('framework')); // angular
|
115
|
* console.log('res.text():', res.text()); // Angular;
|
116
|
* ```
|
117
|
*
|
118
|
* @experimental
|
119
|
*/
|
120
|
export declare class BaseResponseOptions extends ResponseOptions {
|
121
|
constructor();
|
122
|
}
|