@nativescript/core 9.0.18-next.3 → 9.0.18-next.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/http/http-interfaces.d.ts +9 -10
- package/http/http-interfaces.js.map +1 -1
- package/http/http-request/http-request-common.d.ts +1 -0
- package/http/http-request/http-request-common.js +8 -0
- package/http/http-request/http-request-common.js.map +1 -1
- package/http/http-request/index.android.d.ts +1 -2
- package/http/http-request/index.android.js +54 -260
- package/http/http-request/index.android.js.map +1 -1
- package/http/http-request/index.d.ts +1 -1
- package/http/http-request/index.ios.d.ts +1 -2
- package/http/http-request/index.ios.js +35 -214
- package/http/http-request/index.ios.js.map +1 -1
- package/http/http-request-internal/http-request-internal-common.d.ts +2 -0
- package/http/http-request-internal/http-request-internal-common.js +12 -0
- package/http/http-request-internal/http-request-internal-common.js.map +1 -0
- package/http/http-request-internal/index.android.d.ts +4 -0
- package/http/http-request-internal/index.android.js +204 -0
- package/http/http-request-internal/index.android.js.map +1 -0
- package/http/http-request-internal/index.d.ts +28 -0
- package/http/http-request-internal/index.ios.d.ts +4 -0
- package/http/http-request-internal/index.ios.js +181 -0
- package/http/http-request-internal/index.ios.js.map +1 -0
- package/http/index.d.ts +1 -1
- package/http/index.js.map +1 -1
- package/image-source/index.android.js +2 -2
- package/image-source/index.android.js.map +1 -1
- package/image-source/index.ios.js +2 -2
- package/image-source/index.ios.js.map +1 -1
- package/package.json +1 -1
- package/http/http-shared.d.ts +0 -3
- package/http/http-shared.js +0 -2
- package/http/http-shared.js.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ImageSource } from '../image-source';
|
|
2
2
|
import type { File } from '../file-system';
|
|
3
|
+
import type { BaseHttpContent } from './http-request-internal';
|
|
3
4
|
/**
|
|
4
5
|
* Provides options for the http requests.
|
|
5
6
|
*/
|
|
@@ -32,7 +33,7 @@ export interface HttpRequestOptions {
|
|
|
32
33
|
/**
|
|
33
34
|
* Encapsulates HTTP-response information from an HTTP-request.
|
|
34
35
|
*/
|
|
35
|
-
export interface HttpResponse {
|
|
36
|
+
export interface HttpResponse<T = HttpContent> {
|
|
36
37
|
/**
|
|
37
38
|
* Gets the response status code.
|
|
38
39
|
*/
|
|
@@ -44,7 +45,7 @@ export interface HttpResponse {
|
|
|
44
45
|
/**
|
|
45
46
|
* Gets the response content.
|
|
46
47
|
*/
|
|
47
|
-
content?:
|
|
48
|
+
content?: T;
|
|
48
49
|
}
|
|
49
50
|
export type Headers = {
|
|
50
51
|
[key: string]: string | string[];
|
|
@@ -53,14 +54,7 @@ export declare enum HttpResponseEncoding {
|
|
|
53
54
|
UTF8 = 0,
|
|
54
55
|
GBK = 1
|
|
55
56
|
}
|
|
56
|
-
|
|
57
|
-
* Encapsulates the content of an HttpResponse.
|
|
58
|
-
*/
|
|
59
|
-
export interface HttpContent {
|
|
60
|
-
/**
|
|
61
|
-
* Gets the response body as raw data.
|
|
62
|
-
*/
|
|
63
|
-
raw: any;
|
|
57
|
+
export interface HttpContentHandler {
|
|
64
58
|
/**
|
|
65
59
|
* Gets the response body as ArrayBuffer
|
|
66
60
|
*/
|
|
@@ -82,3 +76,8 @@ export interface HttpContent {
|
|
|
82
76
|
*/
|
|
83
77
|
toFile: (destinationFilePath?: string) => File;
|
|
84
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Encapsulates the content of an HttpResponse.
|
|
81
|
+
*/
|
|
82
|
+
export interface HttpContent extends HttpContentHandler, BaseHttpContent {
|
|
83
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-interfaces.js","sourceRoot":"","sources":["../../../../packages/core/http/http-interfaces.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http-interfaces.js","sourceRoot":"","sources":["../../../../packages/core/http/http-interfaces.ts"],"names":[],"mappings":"AA6DA,MAAM,CAAN,IAAY,oBAGX;AAHD,WAAY,oBAAoB;IAC/B,+DAAI,CAAA;IACJ,6DAAG,CAAA;AACJ,CAAC,EAHW,oBAAoB,KAApB,oBAAoB,QAG/B"}
|
|
@@ -12,4 +12,12 @@ export function getFilenameFromUrl(url) {
|
|
|
12
12
|
const result = path.join(knownFolders.documents().path, actualFileName);
|
|
13
13
|
return result;
|
|
14
14
|
}
|
|
15
|
+
export function parseJSON(source) {
|
|
16
|
+
const src = source.trim();
|
|
17
|
+
const lastIndex = src.lastIndexOf(')');
|
|
18
|
+
if (lastIndex === src.length - 1) {
|
|
19
|
+
return JSON.parse(src.substring(src.indexOf('(') + 1, lastIndex));
|
|
20
|
+
}
|
|
21
|
+
return JSON.parse(src);
|
|
22
|
+
}
|
|
15
23
|
//# sourceMappingURL=http-request-common.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-request-common.js","sourceRoot":"","sources":["../../../../../packages/core/http/http-request/http-request-common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEvD,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC7C,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC1C,MAAM,eAAe,GAAG,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAE7C,IAAI,cAAsB,CAAC;IAC3B,IAAI,eAAe,KAAK,CAAC,CAAC,EAAE,CAAC;QAC5B,cAAc,GAAG,GAAG,CAAC,SAAS,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;IAC3D,CAAC;SAAM,CAAC;QACP,cAAc,GAAG,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;IAExE,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
1
|
+
{"version":3,"file":"http-request-common.js","sourceRoot":"","sources":["../../../../../packages/core/http/http-request/http-request-common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEvD,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC7C,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC1C,MAAM,eAAe,GAAG,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAE7C,IAAI,cAAsB,CAAC;IAC3B,IAAI,eAAe,KAAK,CAAC,CAAC,EAAE,CAAC;QAC5B,cAAc,GAAG,GAAG,CAAC,SAAS,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;IAC3D,CAAC;SAAM,CAAC;QACP,cAAc,GAAG,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;IAExE,OAAO,MAAM,CAAC;AACf,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,MAAc;IACvC,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;IAC1B,MAAM,SAAS,GAAG,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAEvC,IAAI,SAAS,KAAK,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;IACnE,CAAC;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { HttpResponse, HttpRequestOptions } from '../../http';
|
|
2
2
|
export declare function request(options: HttpRequestOptions): Promise<HttpResponse>;
|
|
3
|
-
export declare function addHeader(headers: Headers, key: string, value: string): void;
|
|
@@ -1,274 +1,68 @@
|
|
|
1
1
|
import { ImageSource } from '../../image-source';
|
|
2
|
-
import { Screen } from '../../platform/screen';
|
|
3
2
|
import { File } from '../../file-system';
|
|
4
3
|
import { HttpResponseEncoding } from '../http-interfaces';
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const pendingRequests = {};
|
|
16
|
-
let debugRequests;
|
|
17
|
-
if (__DEV__) {
|
|
18
|
-
debugRequests = new Map();
|
|
19
|
-
}
|
|
20
|
-
let completeCallback;
|
|
21
|
-
function ensureCompleteCallback() {
|
|
22
|
-
if (completeCallback) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
completeCallback = new org.nativescript.widgets.Async.CompleteCallback({
|
|
26
|
-
onComplete: function (result, context) {
|
|
27
|
-
// as a context we will receive the id of the request
|
|
28
|
-
onRequestComplete(context, result);
|
|
29
|
-
},
|
|
30
|
-
onError: function (error, context) {
|
|
31
|
-
onRequestError(error, context);
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
function onRequestComplete(requestId, result) {
|
|
36
|
-
const callbacks = pendingRequests[requestId];
|
|
37
|
-
delete pendingRequests[requestId];
|
|
38
|
-
if (result.error) {
|
|
39
|
-
callbacks.rejectCallback(new Error(result.error.toString()));
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
// read the headers
|
|
43
|
-
const headers = {};
|
|
44
|
-
if (result.headers) {
|
|
45
|
-
const jHeaders = result.headers;
|
|
46
|
-
const length = jHeaders.size();
|
|
47
|
-
let pair;
|
|
48
|
-
for (let i = 0; i < length; i++) {
|
|
49
|
-
pair = jHeaders.get(i);
|
|
50
|
-
addHeader(headers, pair.key, pair.value);
|
|
4
|
+
import { requestInternal } from '../http-request-internal';
|
|
5
|
+
import { getFilenameFromUrl, parseJSON } from './http-request-common';
|
|
6
|
+
const contentHandler = {
|
|
7
|
+
toArrayBuffer() {
|
|
8
|
+
return Uint8Array.from(this.raw.toByteArray()).buffer;
|
|
9
|
+
},
|
|
10
|
+
toString(encoding) {
|
|
11
|
+
let str;
|
|
12
|
+
if (encoding) {
|
|
13
|
+
str = decodeResponse(this.raw, encoding);
|
|
51
14
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const debugRequestInfo = debugRequests.get(requestId);
|
|
55
|
-
if (debugRequestInfo) {
|
|
56
|
-
const debugRequest = debugRequestInfo.debugRequest;
|
|
57
|
-
let mime = (headers['Content-Type'] ?? 'text/plain');
|
|
58
|
-
if (typeof mime === 'string') {
|
|
59
|
-
mime = mime.split(';')[0] ?? 'text/plain';
|
|
60
|
-
}
|
|
61
|
-
debugRequest.mimeType = mime;
|
|
62
|
-
debugRequest.data = result.raw;
|
|
63
|
-
const debugResponse = {
|
|
64
|
-
url: result.url,
|
|
65
|
-
status: result.statusCode,
|
|
66
|
-
statusText: result.statusText,
|
|
67
|
-
headers: headers,
|
|
68
|
-
mimeType: mime,
|
|
69
|
-
fromDiskCache: false,
|
|
70
|
-
timing: {
|
|
71
|
-
requestTime: debugRequestInfo.timestamp,
|
|
72
|
-
proxyStart: -1,
|
|
73
|
-
proxyEnd: -1,
|
|
74
|
-
dnsStart: -1,
|
|
75
|
-
dnsEnd: -1,
|
|
76
|
-
connectStart: -1,
|
|
77
|
-
connectEnd: -1,
|
|
78
|
-
sslStart: -1,
|
|
79
|
-
sslEnd: -1,
|
|
80
|
-
serviceWorkerFetchStart: -1,
|
|
81
|
-
serviceWorkerFetchReady: -1,
|
|
82
|
-
serviceWorkerFetchEnd: -1,
|
|
83
|
-
sendStart: -1,
|
|
84
|
-
sendEnd: -1,
|
|
85
|
-
receiveHeadersEnd: -1,
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
debugRequest.responseReceived(debugResponse);
|
|
89
|
-
debugRequest.loadingFinished();
|
|
90
|
-
debugRequests.delete(requestId);
|
|
15
|
+
else {
|
|
16
|
+
str = this.toNativeString(encoding);
|
|
91
17
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
content: {
|
|
95
|
-
raw: result.raw,
|
|
96
|
-
toArrayBuffer: () => Uint8Array.from(result.raw.toByteArray()).buffer,
|
|
97
|
-
toString: (encoding) => {
|
|
98
|
-
let str;
|
|
99
|
-
if (encoding) {
|
|
100
|
-
str = decodeResponse(result.raw, encoding);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
str = result.responseAsString;
|
|
104
|
-
}
|
|
105
|
-
if (typeof str === 'string') {
|
|
106
|
-
return str;
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
throw new Error('Response content may not be converted to string');
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
toJSON: (encoding) => {
|
|
113
|
-
let str;
|
|
114
|
-
if (encoding) {
|
|
115
|
-
str = decodeResponse(result.raw, encoding);
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
str = result.responseAsString;
|
|
119
|
-
}
|
|
120
|
-
return parseJSON(str);
|
|
121
|
-
},
|
|
122
|
-
toImage: () => {
|
|
123
|
-
return new Promise((resolveImage, rejectImage) => {
|
|
124
|
-
if (result.responseAsImage != null) {
|
|
125
|
-
resolveImage(new ImageSource(result.responseAsImage));
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
rejectImage(new Error('Response content may not be converted to an Image'));
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
},
|
|
132
|
-
toFile: (destinationFilePath) => {
|
|
133
|
-
if (!destinationFilePath) {
|
|
134
|
-
destinationFilePath = getFilenameFromUrl(callbacks.url);
|
|
135
|
-
}
|
|
136
|
-
let stream;
|
|
137
|
-
try {
|
|
138
|
-
// ensure destination path exists by creating any missing parent directories
|
|
139
|
-
const file = File.fromPath(destinationFilePath);
|
|
140
|
-
const javaFile = new java.io.File(destinationFilePath);
|
|
141
|
-
stream = new java.io.FileOutputStream(javaFile);
|
|
142
|
-
stream.write(result.raw.toByteArray());
|
|
143
|
-
return file;
|
|
144
|
-
}
|
|
145
|
-
catch (exception) {
|
|
146
|
-
throw new Error(`Cannot save file with path: ${destinationFilePath}.`);
|
|
147
|
-
}
|
|
148
|
-
finally {
|
|
149
|
-
if (stream) {
|
|
150
|
-
stream.close();
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
statusCode: result.statusCode,
|
|
156
|
-
headers: headers,
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
function onRequestError(error, requestId) {
|
|
160
|
-
const callbacks = pendingRequests[requestId];
|
|
161
|
-
delete pendingRequests[requestId];
|
|
162
|
-
if (callbacks) {
|
|
163
|
-
callbacks.rejectCallback(new Error(error));
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
function buildJavaOptions(options) {
|
|
167
|
-
if (typeof options.url !== 'string') {
|
|
168
|
-
throw new Error('Http request must provide a valid url.');
|
|
169
|
-
}
|
|
170
|
-
const javaOptions = new org.nativescript.widgets.Async.Http.RequestOptions();
|
|
171
|
-
javaOptions.url = options.url;
|
|
172
|
-
if (typeof options.method === 'string') {
|
|
173
|
-
javaOptions.method = options.method;
|
|
174
|
-
}
|
|
175
|
-
if (typeof options.content === 'string' || options.content instanceof FormData) {
|
|
176
|
-
const nativeString = new java.lang.String(options.content.toString());
|
|
177
|
-
const nativeBytes = nativeString.getBytes('UTF-8');
|
|
178
|
-
const nativeBuffer = java.nio.ByteBuffer.wrap(nativeBytes);
|
|
179
|
-
javaOptions.content = nativeBuffer;
|
|
180
|
-
}
|
|
181
|
-
else if (options.content instanceof ArrayBuffer) {
|
|
182
|
-
const typedArray = new Uint8Array(options.content);
|
|
183
|
-
const nativeBuffer = java.nio.ByteBuffer.wrap(Array.from(typedArray));
|
|
184
|
-
javaOptions.content = nativeBuffer;
|
|
185
|
-
}
|
|
186
|
-
if (typeof options.timeout === 'number') {
|
|
187
|
-
javaOptions.timeout = options.timeout;
|
|
188
|
-
}
|
|
189
|
-
if (typeof options.dontFollowRedirects === 'boolean') {
|
|
190
|
-
javaOptions.dontFollowRedirects = options.dontFollowRedirects;
|
|
191
|
-
}
|
|
192
|
-
if (options.headers) {
|
|
193
|
-
const arrayList = new java.util.ArrayList();
|
|
194
|
-
const pair = org.nativescript.widgets.Async.Http.KeyValuePair;
|
|
195
|
-
for (const key in options.headers) {
|
|
196
|
-
arrayList.add(new pair(key, options.headers[key] + ''));
|
|
18
|
+
if (typeof str === 'string') {
|
|
19
|
+
return str;
|
|
197
20
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
21
|
+
else {
|
|
22
|
+
throw new Error('Response content may not be converted to string');
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
toJSON(encoding) {
|
|
26
|
+
let str;
|
|
27
|
+
if (encoding) {
|
|
28
|
+
str = decodeResponse(this.raw, encoding);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
str = this.toNativeString(encoding);
|
|
32
|
+
}
|
|
33
|
+
return parseJSON(str);
|
|
34
|
+
},
|
|
35
|
+
toImage() {
|
|
36
|
+
return this.toNativeImage().then((value) => new ImageSource(value));
|
|
37
|
+
},
|
|
38
|
+
toFile(destinationFilePath) {
|
|
39
|
+
if (!destinationFilePath) {
|
|
40
|
+
destinationFilePath = getFilenameFromUrl(this.requestURL);
|
|
41
|
+
}
|
|
42
|
+
let stream;
|
|
211
43
|
try {
|
|
212
|
-
//
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
if (__DEV__) {
|
|
219
|
-
const network = domainDebugger.getNetwork();
|
|
220
|
-
const debugRequest = network && network.create();
|
|
221
|
-
if (options.url && debugRequest) {
|
|
222
|
-
const timestamp = Date.now() / 1000;
|
|
223
|
-
debugRequests.set(requestIdCounter, {
|
|
224
|
-
debugRequest,
|
|
225
|
-
timestamp,
|
|
226
|
-
});
|
|
227
|
-
const request = {
|
|
228
|
-
url: options.url,
|
|
229
|
-
method: 'GET',
|
|
230
|
-
headers: options.headers,
|
|
231
|
-
timestamp,
|
|
232
|
-
};
|
|
233
|
-
debugRequest.requestWillBeSent(request);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
// remember the callbacks so that we can use them when the CompleteCallback is called
|
|
237
|
-
const callbacks = {
|
|
238
|
-
url: options.url,
|
|
239
|
-
resolveCallback: resolve,
|
|
240
|
-
rejectCallback: reject,
|
|
241
|
-
};
|
|
242
|
-
pendingRequests[requestIdCounter] = callbacks;
|
|
243
|
-
ensureCompleteCallback();
|
|
244
|
-
//make the actual async call
|
|
245
|
-
org.nativescript.widgets.Async.Http.MakeRequest(javaOptions, completeCallback, new java.lang.Integer(requestIdCounter));
|
|
246
|
-
// increment the id counter
|
|
247
|
-
requestIdCounter++;
|
|
44
|
+
// ensure destination path exists by creating any missing parent directories
|
|
45
|
+
const file = File.fromPath(destinationFilePath);
|
|
46
|
+
const javaFile = new java.io.File(destinationFilePath);
|
|
47
|
+
stream = new java.io.FileOutputStream(javaFile);
|
|
48
|
+
stream.write(this.raw.toByteArray());
|
|
49
|
+
return file;
|
|
248
50
|
}
|
|
249
|
-
catch (
|
|
250
|
-
|
|
51
|
+
catch (exception) {
|
|
52
|
+
throw new Error(`Cannot save file with path: ${destinationFilePath}.`);
|
|
251
53
|
}
|
|
252
|
-
|
|
54
|
+
finally {
|
|
55
|
+
if (stream) {
|
|
56
|
+
stream.close();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
export function request(options) {
|
|
62
|
+
return requestInternal(options, contentHandler);
|
|
253
63
|
}
|
|
254
64
|
function decodeResponse(raw, encoding) {
|
|
255
|
-
|
|
256
|
-
if (encoding === HttpResponseEncoding.GBK) {
|
|
257
|
-
charsetName = 'GBK';
|
|
258
|
-
}
|
|
65
|
+
const charsetName = encoding === HttpResponseEncoding.GBK ? 'GBK' : 'UTF-8';
|
|
259
66
|
return raw.toString(charsetName);
|
|
260
67
|
}
|
|
261
|
-
export function addHeader(headers, key, value) {
|
|
262
|
-
if (!headers[key]) {
|
|
263
|
-
headers[key] = value;
|
|
264
|
-
}
|
|
265
|
-
else if (Array.isArray(headers[key])) {
|
|
266
|
-
headers[key].push(value);
|
|
267
|
-
}
|
|
268
|
-
else {
|
|
269
|
-
const values = [headers[key]];
|
|
270
|
-
values.push(value);
|
|
271
|
-
headers[key] = values;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
68
|
//# sourceMappingURL=index.android.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.android.js","sourceRoot":"","sources":["../../../../../packages/core/http/http-request/index.android.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.android.js","sourceRoot":"","sources":["../../../../../packages/core/http/http-request/index.android.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HttpRequestOptions, HttpResponse, Headers } from '../http-interfaces';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Makes a generic http request using the provided options and returns a HttpResponse Object.
|
|
4
5
|
* @param options An object that specifies various request options.
|
|
5
6
|
*/
|
|
6
7
|
export const request: (options: HttpRequestOptions) => Promise<HttpResponse>;
|
|
7
|
-
export function addHeader(headers: Headers, key: string, value: string): void;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import type { HttpRequestOptions, HttpResponse
|
|
1
|
+
import type { HttpRequestOptions, HttpResponse } from '../http-interfaces';
|
|
2
2
|
export declare function request(options: HttpRequestOptions): Promise<HttpResponse>;
|
|
3
|
-
export declare function addHeader(headers: Headers, key: string, value: string): void;
|