@d1g1tal/transportr 0.1.2 → 0.1.3
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/dist/transportr.js +1437 -56
- package/dist/transportr.min.js +2 -2
- package/dist/transportr.min.js.map +4 -4
- package/index.d.ts +1 -0
- package/package.json +10 -9
- package/src/http-error.d.ts +60 -0
- package/src/http-error.d.ts.map +1 -0
- package/src/http-error.js +63 -0
- package/src/http-media-type.d.ts +7 -0
- package/src/http-media-type.d.ts.map +1 -0
- package/src/http-media-type.js +6 -0
- package/src/http-request-headers.d.ts +1 -0
- package/src/http-request-headers.d.ts.map +1 -0
- package/src/http-request-headers.js +6 -0
- package/src/http-request-methods.d.ts +1 -0
- package/src/http-request-methods.d.ts.map +1 -0
- package/src/http-request-methods.js +6 -0
- package/src/http-response-headers.d.ts +1 -0
- package/src/http-response-headers.d.ts.map +1 -0
- package/src/http-response-headers.js +6 -0
- package/src/response-status.d.ts +28 -0
- package/src/response-status.d.ts.map +1 -0
- package/src/response-status.js +40 -0
- package/src/transportr.d.ts +230 -127
- package/src/transportr.d.ts.map +1 -0
- package/src/transportr.js +191 -120
package/dist/transportr.js
CHANGED
|
@@ -60,25 +60,35 @@ var Transportr = (() => {
|
|
|
60
60
|
|
|
61
61
|
// node_modules/@d1g1tal/chrysalis/src/esm/object-merge.js
|
|
62
62
|
var _objectMerge = (...objects) => {
|
|
63
|
-
return objects.reduce((
|
|
64
|
-
Object.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
return objects.reduce((previousValue, currentValue) => {
|
|
64
|
+
for (const [key, value] of Object.entries(currentValue)) {
|
|
65
|
+
switch (true) {
|
|
66
|
+
case (Array.isArray(value) && Array.isArray(previousValue[key])): {
|
|
67
|
+
previousValue[key] = [.../* @__PURE__ */ new Set([...value, ...previousValue[key]])];
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
case (object_is_type_default(value, Object) && object_is_type_default(previousValue[key], Object)): {
|
|
71
|
+
previousValue[key] = _objectMerge(previousValue[key], value);
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
default:
|
|
75
|
+
previousValue[key] = value;
|
|
73
76
|
}
|
|
74
|
-
}
|
|
75
|
-
return
|
|
77
|
+
}
|
|
78
|
+
return previousValue;
|
|
76
79
|
}, {});
|
|
77
80
|
};
|
|
78
81
|
var object_merge_default = _objectMerge;
|
|
79
82
|
|
|
80
83
|
// node_modules/@d1g1tal/collections/src/set-multi-map.js
|
|
81
84
|
var SetMultiMap = class extends Map {
|
|
85
|
+
/**
|
|
86
|
+
* Adds a new element with a specified key and value to the SetMultiMap. If an element with the same key already exists, the value will be added to the underlying {@link Set}.
|
|
87
|
+
*
|
|
88
|
+
* @param {K} key The key to set.
|
|
89
|
+
* @param {V} value The value to add to the SetMultiMap
|
|
90
|
+
* @returns {SetMultiMap} The SetMultiMap with the updated key and value.
|
|
91
|
+
*/
|
|
82
92
|
set(key, value) {
|
|
83
93
|
super.set(key, (super.get(key) ?? /* @__PURE__ */ new Set()).add(value));
|
|
84
94
|
return this;
|
|
@@ -124,18 +134,48 @@ var Transportr = (() => {
|
|
|
124
134
|
|
|
125
135
|
// node_modules/@d1g1tal/media-type/src/media-type-parameters.js
|
|
126
136
|
var MediaTypeParameters = class {
|
|
137
|
+
/**
|
|
138
|
+
* Create a new MediaTypeParameters instance.
|
|
139
|
+
*
|
|
140
|
+
* @param {Map.<string, string>} map The map of parameters for a media type.
|
|
141
|
+
*/
|
|
127
142
|
constructor(map) {
|
|
128
143
|
this._map = map;
|
|
129
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Gets the number of media type parameters.
|
|
147
|
+
*
|
|
148
|
+
* @returns {number} The number of media type parameters
|
|
149
|
+
*/
|
|
130
150
|
get size() {
|
|
131
151
|
return this._map.size;
|
|
132
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Gets the media type parameter value for the supplied name.
|
|
155
|
+
*
|
|
156
|
+
* @param {string} name The name of the media type parameter to retrieve.
|
|
157
|
+
* @returns {string} The media type parameter value.
|
|
158
|
+
*/
|
|
133
159
|
get(name) {
|
|
134
160
|
return this._map.get(asciiLowercase(String(name)));
|
|
135
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* Indicates whether the media type parameter with the specified name exists or not.
|
|
164
|
+
*
|
|
165
|
+
* @param {string} name The name of the media type parameter to check.
|
|
166
|
+
* @returns {boolean} true if the media type parameter exists, false otherwise.
|
|
167
|
+
*/
|
|
136
168
|
has(name) {
|
|
137
169
|
return this._map.has(asciiLowercase(String(name)));
|
|
138
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Adds a new media type parameter using the specified name and value to the MediaTypeParameters.
|
|
173
|
+
* If an parameter with the same name already exists, the parameter will be updated.
|
|
174
|
+
*
|
|
175
|
+
* @param {string} name The name of the media type parameter to set.
|
|
176
|
+
* @param {string} value The media type parameter value.
|
|
177
|
+
* @returns {MediaTypeParameters} This instance.
|
|
178
|
+
*/
|
|
139
179
|
set(name, value) {
|
|
140
180
|
name = asciiLowercase(String(name));
|
|
141
181
|
value = String(value);
|
|
@@ -148,25 +188,60 @@ var Transportr = (() => {
|
|
|
148
188
|
this._map.set(name, value);
|
|
149
189
|
return this;
|
|
150
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Clears all the media type parameters.
|
|
193
|
+
*/
|
|
151
194
|
clear() {
|
|
152
195
|
this._map.clear();
|
|
153
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* Removes the media type parameter using the specified name.
|
|
199
|
+
*
|
|
200
|
+
* @param {string} name The name of the media type parameter to delete.
|
|
201
|
+
* @returns {boolean} true if the parameter existed and has been removed, or false if the parameter does not exist.
|
|
202
|
+
*/
|
|
154
203
|
delete(name) {
|
|
155
204
|
name = asciiLowercase(String(name));
|
|
156
205
|
return this._map.delete(name);
|
|
157
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* Executes a provided function once per each name/value pair in the MediaTypeParameters, in insertion order.
|
|
209
|
+
*
|
|
210
|
+
* @param {function(string, string): void} callback The function called on each iteration.
|
|
211
|
+
* @param {*} [thisArg] Optional object when binding 'this' to the callback.
|
|
212
|
+
*/
|
|
158
213
|
forEach(callback, thisArg) {
|
|
159
214
|
this._map.forEach(callback, thisArg);
|
|
160
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Returns an iterable of parameter names.
|
|
218
|
+
*
|
|
219
|
+
* @returns {IterableIterator<string>} The {@link IterableIterator} of media type parameter names.
|
|
220
|
+
*/
|
|
161
221
|
keys() {
|
|
162
222
|
return this._map.keys();
|
|
163
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* Returns an iterable of parameter values.
|
|
226
|
+
*
|
|
227
|
+
* @returns {IterableIterator<string>} The {@link IterableIterator} of media type parameter values.
|
|
228
|
+
*/
|
|
164
229
|
values() {
|
|
165
230
|
return this._map.values();
|
|
166
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* Returns an iterable of name, value pairs for every parameter entry in the media type parameters.
|
|
234
|
+
*
|
|
235
|
+
* @returns {IterableIterator<Array<Array<string>>>} The media type parameter entries.
|
|
236
|
+
*/
|
|
167
237
|
entries() {
|
|
168
238
|
return this._map.entries();
|
|
169
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* A method that returns the default iterator for the {@link MediaTypeParameters}. Called by the semantics of the for-of statement.
|
|
242
|
+
*
|
|
243
|
+
* @returns {Iterator<string, string, undefined>} The {@link Symbol.iterator} for the media type parameters.
|
|
244
|
+
*/
|
|
170
245
|
[Symbol.iterator]() {
|
|
171
246
|
return this._map[Symbol.iterator]();
|
|
172
247
|
}
|
|
@@ -266,6 +341,11 @@ var Transportr = (() => {
|
|
|
266
341
|
|
|
267
342
|
// node_modules/@d1g1tal/media-type/src/media-type.js
|
|
268
343
|
var MediaType = class {
|
|
344
|
+
/**
|
|
345
|
+
* Create a new MediaType instance from a string representation.
|
|
346
|
+
*
|
|
347
|
+
* @param {string} string The media type to parse
|
|
348
|
+
*/
|
|
269
349
|
constructor(string) {
|
|
270
350
|
string = String(string);
|
|
271
351
|
const result = parser_default(string);
|
|
@@ -276,6 +356,12 @@ var Transportr = (() => {
|
|
|
276
356
|
this._subtype = result.subtype;
|
|
277
357
|
this._parameters = new MediaTypeParameters(result.parameters);
|
|
278
358
|
}
|
|
359
|
+
/**
|
|
360
|
+
* Static factor method for parsing a media type.
|
|
361
|
+
*
|
|
362
|
+
* @param {string} string The media type to parse
|
|
363
|
+
* @returns {MediaType} The parsed {@link MediaType} object
|
|
364
|
+
*/
|
|
279
365
|
static parse(string) {
|
|
280
366
|
try {
|
|
281
367
|
return new this(string);
|
|
@@ -283,12 +369,25 @@ var Transportr = (() => {
|
|
|
283
369
|
return null;
|
|
284
370
|
}
|
|
285
371
|
}
|
|
372
|
+
/**
|
|
373
|
+
* Gets the media type essence (type/subtype).
|
|
374
|
+
*
|
|
375
|
+
* @returns {string} The media type without any parameters
|
|
376
|
+
*/
|
|
286
377
|
get essence() {
|
|
287
378
|
return `${this.type}/${this.subtype}`;
|
|
288
379
|
}
|
|
380
|
+
/**
|
|
381
|
+
* Gets the type.
|
|
382
|
+
*
|
|
383
|
+
* @returns {string} The type.
|
|
384
|
+
*/
|
|
289
385
|
get type() {
|
|
290
386
|
return this._type;
|
|
291
387
|
}
|
|
388
|
+
/**
|
|
389
|
+
* Sets the type.
|
|
390
|
+
*/
|
|
292
391
|
set type(value) {
|
|
293
392
|
value = asciiLowercase(String(value));
|
|
294
393
|
if (value.length === 0) {
|
|
@@ -299,9 +398,17 @@ var Transportr = (() => {
|
|
|
299
398
|
}
|
|
300
399
|
this._type = value;
|
|
301
400
|
}
|
|
401
|
+
/**
|
|
402
|
+
* Gets the subtype.
|
|
403
|
+
*
|
|
404
|
+
* @returns {string} The subtype.
|
|
405
|
+
*/
|
|
302
406
|
get subtype() {
|
|
303
407
|
return this._subtype;
|
|
304
408
|
}
|
|
409
|
+
/**
|
|
410
|
+
* Sets the subtype.
|
|
411
|
+
*/
|
|
305
412
|
set subtype(value) {
|
|
306
413
|
value = asciiLowercase(String(value));
|
|
307
414
|
if (value.length === 0) {
|
|
@@ -312,12 +419,29 @@ var Transportr = (() => {
|
|
|
312
419
|
}
|
|
313
420
|
this._subtype = value;
|
|
314
421
|
}
|
|
422
|
+
/**
|
|
423
|
+
* Gets the parameters.
|
|
424
|
+
*
|
|
425
|
+
* @returns {MediaTypeParameters} The media type parameters.
|
|
426
|
+
*/
|
|
315
427
|
get parameters() {
|
|
316
428
|
return this._parameters;
|
|
317
429
|
}
|
|
430
|
+
/**
|
|
431
|
+
* Gets the serialized version of the media type.
|
|
432
|
+
*
|
|
433
|
+
* @returns {string} The serialized media type.
|
|
434
|
+
*/
|
|
318
435
|
toString() {
|
|
319
436
|
return serializer_default(this);
|
|
320
437
|
}
|
|
438
|
+
/**
|
|
439
|
+
* Determines if this instance is a JavaScript media type.
|
|
440
|
+
*
|
|
441
|
+
* @param {Object} [options] Optional options.
|
|
442
|
+
* @param {boolean} [options.prohibitParameters=false] The option to prohibit parameters when checking if the media type is JavaScript.
|
|
443
|
+
* @returns {boolean} true if this instance represents a JavaScript media type, false otherwise.
|
|
444
|
+
*/
|
|
321
445
|
isJavaScript({ prohibitParameters = false } = {}) {
|
|
322
446
|
switch (this._type) {
|
|
323
447
|
case "text": {
|
|
@@ -354,216 +478,1199 @@ var Transportr = (() => {
|
|
|
354
478
|
return false;
|
|
355
479
|
}
|
|
356
480
|
}
|
|
481
|
+
/**
|
|
482
|
+
* Determines if this instance is an XML media type.
|
|
483
|
+
*
|
|
484
|
+
* @returns {boolean} true if this instance represents an XML media type, false otherwise.
|
|
485
|
+
*/
|
|
357
486
|
isXML() {
|
|
358
487
|
return this._subtype === "xml" && (this._type === "text" || this._type === "application") || this._subtype.endsWith("+xml");
|
|
359
488
|
}
|
|
489
|
+
/**
|
|
490
|
+
* Determines if this instance is an HTML media type.
|
|
491
|
+
*
|
|
492
|
+
* @returns {boolean} true if this instance represents an HTML media type, false otherwise.
|
|
493
|
+
*/
|
|
360
494
|
isHTML() {
|
|
361
495
|
return this._subtype === "html" && this._type === "text";
|
|
362
496
|
}
|
|
497
|
+
/**
|
|
498
|
+
* Gets the name of the class.
|
|
499
|
+
*
|
|
500
|
+
* @returns {string} The class name
|
|
501
|
+
*/
|
|
363
502
|
get [Symbol.toStringTag]() {
|
|
364
503
|
return "MediaType";
|
|
365
504
|
}
|
|
366
505
|
};
|
|
367
506
|
|
|
507
|
+
// src/http-error.js
|
|
508
|
+
var HttpError = class extends Error {
|
|
509
|
+
/** @type {ResponseBody} */
|
|
510
|
+
#entity;
|
|
511
|
+
/** @type {ResponseStatus} */
|
|
512
|
+
#responseStatus;
|
|
513
|
+
/**
|
|
514
|
+
* @param {string} [message] The error message.
|
|
515
|
+
* @param {HttpErrorOptions} [options] The error options.
|
|
516
|
+
* @param {Error} [options.cause] The cause of the error.
|
|
517
|
+
* @param {ResponseStatus} [options.status] The response status.
|
|
518
|
+
* @param {ResponseBody} [options.entity] The error entity from the server, if any.
|
|
519
|
+
*/
|
|
520
|
+
constructor(message, { cause, status, entity }) {
|
|
521
|
+
super(message, { cause });
|
|
522
|
+
this.#entity = entity;
|
|
523
|
+
this.#responseStatus = status;
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* It returns the value of the private variable #entity.
|
|
527
|
+
*
|
|
528
|
+
* @returns {ResponseBody} The entity property of the class.
|
|
529
|
+
*/
|
|
530
|
+
get entity() {
|
|
531
|
+
return this.#entity;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* It returns the status code of the {@link Response}.
|
|
535
|
+
*
|
|
536
|
+
* @returns {number} The status code of the {@link Response}.
|
|
537
|
+
*/
|
|
538
|
+
get statusCode() {
|
|
539
|
+
return this.#responseStatus?.code;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* It returns the status text of the {@link Response}.
|
|
543
|
+
*
|
|
544
|
+
* @returns {string} The status code and status text of the {@link Response}.
|
|
545
|
+
*/
|
|
546
|
+
get statusText() {
|
|
547
|
+
return this.#responseStatus?.text;
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
var http_error_default = HttpError;
|
|
551
|
+
|
|
368
552
|
// src/http-media-type.js
|
|
369
553
|
var HttpMediaType = {
|
|
554
|
+
/** Advanced Audio Coding (AAC) */
|
|
370
555
|
AAC: "audio/aac",
|
|
556
|
+
/** AbiWord */
|
|
371
557
|
ABW: "application/x-abiword",
|
|
558
|
+
/** Archive document (multiple files embedded) */
|
|
372
559
|
ARC: "application/x-freearc",
|
|
560
|
+
/** AVIF image */
|
|
373
561
|
AVIF: "image/avif",
|
|
562
|
+
/** Audio Video Interleave (AVI) */
|
|
374
563
|
AVI: "video/x-msvideo",
|
|
564
|
+
/** Amazon Kindle eBook format */
|
|
375
565
|
AZW: "application/vnd.amazon.ebook",
|
|
566
|
+
/** Binary Data */
|
|
376
567
|
BIN: "application/octet-stream",
|
|
568
|
+
/** Windows OS/2 Bitmap Graphics */
|
|
377
569
|
BMP: "image/bmp",
|
|
570
|
+
/** Bzip Archive */
|
|
378
571
|
BZIP: "application/x-bzip",
|
|
572
|
+
/** Bzip2 Archive */
|
|
379
573
|
BZIP2: "application/x-bzip2",
|
|
574
|
+
/** CD audio */
|
|
380
575
|
CDA: "application/x-cdf",
|
|
576
|
+
/** C Shell Script */
|
|
381
577
|
CSH: "application/x-csh",
|
|
578
|
+
/** Cascading Style Sheets (CSS) */
|
|
382
579
|
CSS: "text/css",
|
|
580
|
+
/** Comma-Separated Values */
|
|
383
581
|
CSV: "text/csv",
|
|
582
|
+
/** Microsoft Office Word Document */
|
|
384
583
|
DOC: "application/msword",
|
|
584
|
+
/** Microsoft Office Word Document (OpenXML) */
|
|
385
585
|
DOCX: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
586
|
+
/** Microsoft Embedded OpenType */
|
|
386
587
|
EOT: "application/vnd.ms-fontobject",
|
|
588
|
+
/** Electronic Publication (EPUB) */
|
|
387
589
|
EPUB: "application/epub+zip",
|
|
590
|
+
/** GZip Compressed Archive */
|
|
388
591
|
GZIP: "application/gzip",
|
|
592
|
+
/** Graphics Interchange Format */
|
|
389
593
|
GIF: "image/gif",
|
|
594
|
+
/** HyperText Markup Language (HTML) */
|
|
390
595
|
HTML: "text/html",
|
|
596
|
+
/** Icon Format */
|
|
391
597
|
ICO: "image/vnd.microsoft.icon",
|
|
598
|
+
/** iCalendar Format */
|
|
392
599
|
ICS: "text/calendar",
|
|
600
|
+
/** Java Archive (JAR) */
|
|
393
601
|
JAR: "application/java-archive",
|
|
602
|
+
/** JPEG Image */
|
|
394
603
|
JPEG: "image/jpeg",
|
|
604
|
+
/** JavaScript */
|
|
395
605
|
JAVA_SCRIPT: "text/javascript",
|
|
606
|
+
/** JavaScript Object Notation Format (JSON) */
|
|
396
607
|
JSON: "application/json",
|
|
608
|
+
/** JavaScript Object Notation LD Format */
|
|
397
609
|
JSON_LD: "application/ld+json",
|
|
610
|
+
/** Musical Instrument Digital Interface (MIDI) */
|
|
398
611
|
MID: "audio/midi",
|
|
612
|
+
/** Musical Instrument Digital Interface (MIDI) */
|
|
399
613
|
X_MID: "audio/x-midi",
|
|
614
|
+
/** MP3 Audio */
|
|
400
615
|
MP3: "audio/mpeg",
|
|
616
|
+
/** MPEG-4 Audio */
|
|
401
617
|
MP4A: "audio/mp4",
|
|
618
|
+
/** MPEG-4 Video */
|
|
402
619
|
MP4: "video/mp4",
|
|
620
|
+
/** MPEG Video */
|
|
403
621
|
MPEG: "video/mpeg",
|
|
622
|
+
/** Apple Installer Package */
|
|
404
623
|
MPKG: "application/vnd.apple.installer+xml",
|
|
624
|
+
/** OpenDocument Presentation Document */
|
|
405
625
|
ODP: "application/vnd.oasis.opendocument.presentation",
|
|
626
|
+
/** OpenDocument Spreadsheet Document */
|
|
406
627
|
ODS: "application/vnd.oasis.opendocument.spreadsheet",
|
|
628
|
+
/** OpenDocument Text Document */
|
|
407
629
|
ODT: "application/vnd.oasis.opendocument.text",
|
|
630
|
+
/** Ogg Audio */
|
|
408
631
|
OGA: "audio/ogg",
|
|
632
|
+
/** Ogg Video */
|
|
409
633
|
OGV: "video/ogg",
|
|
634
|
+
/** Ogg */
|
|
410
635
|
OGX: "application/ogg",
|
|
636
|
+
/** Opus audio */
|
|
411
637
|
OPUS: "audio/opus",
|
|
638
|
+
/** OpenType Font File */
|
|
412
639
|
OTF: "font/otf",
|
|
640
|
+
/** Portable Network Graphics (PNG) */
|
|
413
641
|
PNG: "image/png",
|
|
642
|
+
/** Adobe Portable Document Format */
|
|
414
643
|
PDF: "application/pdf",
|
|
644
|
+
/** Hypertext Preprocessor (Personal Home Page) */
|
|
415
645
|
PHP: "application/x-httpd-php",
|
|
646
|
+
/** Microsoft PowerPoint */
|
|
416
647
|
PPT: "application/vnd.ms-powerpoint",
|
|
648
|
+
/** Microsoft Office Presentation (OpenXML) */
|
|
417
649
|
PPTX: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
650
|
+
/** RAR Archive */
|
|
418
651
|
RAR: "application/vnd.rar",
|
|
652
|
+
/** Rich Text Format */
|
|
419
653
|
RTF: "application/rtf",
|
|
654
|
+
/** Bourne Shell Script */
|
|
420
655
|
SH: "application/x-sh",
|
|
656
|
+
/** Scalable Vector Graphics (SVG) */
|
|
421
657
|
SVG: "image/svg+xml",
|
|
658
|
+
/** Tape Archive (TAR) */
|
|
422
659
|
TAR: "application/x-tar",
|
|
660
|
+
/** Tagged Image File Format (TIFF) */
|
|
423
661
|
TIFF: "image/tiff",
|
|
662
|
+
/** MPEG transport stream */
|
|
424
663
|
TRANSPORT_STREAM: "video/mp2t",
|
|
664
|
+
/** TrueType Font */
|
|
425
665
|
TTF: "font/ttf",
|
|
666
|
+
/** Text, (generally ASCII or ISO 8859-n) */
|
|
426
667
|
TEXT: "text/plain",
|
|
668
|
+
/** Microsoft Visio */
|
|
427
669
|
VSD: "application/vnd.visio",
|
|
670
|
+
/** Waveform Audio Format (WAV) */
|
|
428
671
|
WAV: "audio/wav",
|
|
672
|
+
/** Open Web Media Project - Audio */
|
|
429
673
|
WEBA: "audio/webm",
|
|
674
|
+
/** Open Web Media Project - Video */
|
|
430
675
|
WEBM: "video/webm",
|
|
676
|
+
/** WebP Image */
|
|
431
677
|
WEBP: "image/webp",
|
|
678
|
+
/** Web Open Font Format */
|
|
432
679
|
WOFF: "font/woff",
|
|
680
|
+
/** Web Open Font Format */
|
|
433
681
|
WOFF2: "font/woff2",
|
|
682
|
+
/** XHTML - The Extensible HyperText Markup Language */
|
|
434
683
|
XHTML: "application/xhtml+xml",
|
|
684
|
+
/** Microsoft Excel Document */
|
|
435
685
|
XLS: "application/vnd.ms-excel",
|
|
686
|
+
/** Microsoft Office Spreadsheet Document (OpenXML) */
|
|
436
687
|
XLSX: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
688
|
+
/** Extensible Markup Language (XML) */
|
|
437
689
|
XML: "application/xml",
|
|
690
|
+
/** XML User Interface Language (XUL) */
|
|
438
691
|
XUL: "application/vnd.mozilla.xul+xml",
|
|
692
|
+
/** Zip Archive */
|
|
439
693
|
ZIP: "application/zip",
|
|
694
|
+
/** 3GPP audio/video container */
|
|
440
695
|
"3GP": "video/3gpp",
|
|
696
|
+
/** 3GPP2 audio/video container */
|
|
441
697
|
"3G2": "video/3gpp2",
|
|
698
|
+
/** 7-Zip Archive */
|
|
442
699
|
"7Z": "application/x-7z-compressed"
|
|
443
700
|
};
|
|
444
701
|
var http_media_type_default = HttpMediaType;
|
|
445
702
|
|
|
446
703
|
// src/http-request-headers.js
|
|
447
704
|
var HttpRequestHeader = {
|
|
705
|
+
/**
|
|
706
|
+
* Content-Types that are acceptable for the response. See Content negotiation. Permanent.
|
|
707
|
+
*
|
|
708
|
+
* @example
|
|
709
|
+
* <code>Accept: text/plain</code>
|
|
710
|
+
*/
|
|
448
711
|
ACCEPT: "accept",
|
|
712
|
+
/**
|
|
713
|
+
* Character sets that are acceptable. Permanent.
|
|
714
|
+
*
|
|
715
|
+
* @example
|
|
716
|
+
* <code>Accept-Charset: utf-8</code>
|
|
717
|
+
*/
|
|
449
718
|
ACCEPT_CHARSET: "accept-charset",
|
|
719
|
+
/**
|
|
720
|
+
* List of acceptable encodings. See HTTP compression. Permanent.
|
|
721
|
+
*
|
|
722
|
+
* @example
|
|
723
|
+
* <code>Accept-Encoding: gzip, deflate</code>
|
|
724
|
+
*/
|
|
450
725
|
ACCEPT_ENCODING: "accept-encoding",
|
|
726
|
+
/**
|
|
727
|
+
* List of acceptable human languages for response. See Content negotiation. Permanent.
|
|
728
|
+
*
|
|
729
|
+
* @example
|
|
730
|
+
* <code>Accept-Language: en-US</code>
|
|
731
|
+
*/
|
|
451
732
|
ACCEPT_LANGUAGE: "accept-language",
|
|
733
|
+
/**
|
|
734
|
+
* Authentication credentials for HTTP authentication. Permanent.
|
|
735
|
+
*
|
|
736
|
+
* @example
|
|
737
|
+
* <code>Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==</code>
|
|
738
|
+
*/
|
|
452
739
|
AUTHORIZATION: "authorization",
|
|
740
|
+
/**
|
|
741
|
+
* Used to specify directives that must be obeyed by all caching mechanisms along the request-response chain.
|
|
742
|
+
* Permanent.
|
|
743
|
+
*
|
|
744
|
+
* @example
|
|
745
|
+
* <code>Cache-Control: no-cache</code>
|
|
746
|
+
*/
|
|
453
747
|
CACHE_CONTROL: "cache-control",
|
|
748
|
+
/**
|
|
749
|
+
* Control options for the current connection and list of hop-by-hop request fields. Permanent.
|
|
750
|
+
*
|
|
751
|
+
* @example
|
|
752
|
+
* <code>Connection: keep-alive</code>
|
|
753
|
+
* <code>Connection: Upgrade</code>
|
|
754
|
+
*/
|
|
454
755
|
CONNECTION: "connection",
|
|
756
|
+
/**
|
|
757
|
+
* An HTTP cookie previously sent by the server with Set-Cookie (below). Permanent: standard.
|
|
758
|
+
*
|
|
759
|
+
* @example
|
|
760
|
+
* <code>Cookie: $Version=1, Skin=new,</code>
|
|
761
|
+
*/
|
|
455
762
|
COOKIE: "cookie",
|
|
763
|
+
/**
|
|
764
|
+
* The length of the request body in octets (8-bit bytes). Permanent.
|
|
765
|
+
*
|
|
766
|
+
* @example
|
|
767
|
+
* <code>Content-Length: 348</code>
|
|
768
|
+
*/
|
|
456
769
|
CONTENT_LENGTH: "content-length",
|
|
770
|
+
/**
|
|
771
|
+
* A Base64-encoded binary MD5 sum of the content of the request body. Obsolete.
|
|
772
|
+
*
|
|
773
|
+
* @example
|
|
774
|
+
* <code>Content-MD5: Q2hlY2sgSW50ZWdyaXR5IQ==</code>
|
|
775
|
+
*/
|
|
457
776
|
CONTENT_MD5: "content-md5",
|
|
777
|
+
/**
|
|
778
|
+
* The MIME type of the body of the request (used with POST and PUT requests). Permanent.
|
|
779
|
+
* <code>Content-Type: application/x-www-form-urlencoded</code>
|
|
780
|
+
*/
|
|
458
781
|
CONTENT_TYPE: "content-type",
|
|
782
|
+
/**
|
|
783
|
+
* The date and time that the message was sent (in "HTTP-date" format as defined by RFC 7231 Date/Time Formats).
|
|
784
|
+
* Permanent.
|
|
785
|
+
*
|
|
786
|
+
* @example
|
|
787
|
+
* <code>Date: Tue, 15 Nov 1994 08:12:31 GMT</code>
|
|
788
|
+
*/
|
|
459
789
|
DATE: "date",
|
|
790
|
+
/**
|
|
791
|
+
* Indicates that particular server behaviors are required by the client. Permanent.
|
|
792
|
+
*
|
|
793
|
+
* @example
|
|
794
|
+
* <code>Expect: 100-continue</code>
|
|
795
|
+
*/
|
|
460
796
|
EXPECT: "expect",
|
|
797
|
+
/**
|
|
798
|
+
* The email address of the user making the request. Permanent.
|
|
799
|
+
*
|
|
800
|
+
* @example
|
|
801
|
+
* <code>From: user@example.com</code>
|
|
802
|
+
*/
|
|
461
803
|
FROM: "from",
|
|
804
|
+
/**
|
|
805
|
+
* The domain name of the server (for virtual hosting), and the TCP port number on which the server is listening. The
|
|
806
|
+
* port number may be omitted if the port is the standard port for the service requested. Permanent. Mandatory since
|
|
807
|
+
* HTTP/1.1.
|
|
808
|
+
*
|
|
809
|
+
* @example
|
|
810
|
+
* <code>Host: en.wikipedia.org:80</code>
|
|
811
|
+
* <code>Host: en.wikipedia.org</code>
|
|
812
|
+
*/
|
|
462
813
|
HOST: "host",
|
|
814
|
+
/**
|
|
815
|
+
* Only perform the action if the client supplied entity matches the same entity on the server. This is mainly for
|
|
816
|
+
* methods like PUT to only update a resource if it has not been modified since the user last updated it. Permanent.
|
|
817
|
+
*
|
|
818
|
+
* @example
|
|
819
|
+
* <code>If-Match: "737060cd8c284d8af7ad3082f209582d"</code>
|
|
820
|
+
*/
|
|
463
821
|
IF_MATCH: "if-match",
|
|
822
|
+
/**
|
|
823
|
+
* Allows a 304 Not Modified to be returned if content is unchanged. Permanent.
|
|
824
|
+
*
|
|
825
|
+
* @example
|
|
826
|
+
* <code>If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT</code>
|
|
827
|
+
*/
|
|
464
828
|
IF_MODIFIED_SINCE: "if-modified-since",
|
|
829
|
+
/**
|
|
830
|
+
* Allows a 304 Not Modified to be returned if content is unchanged, see HTTP ETag. Permanent.
|
|
831
|
+
*
|
|
832
|
+
* @example
|
|
833
|
+
* <code>If-None-Match: "737060cd8c284d8af7ad3082f209582d"</code>
|
|
834
|
+
*/
|
|
465
835
|
IF_NONE_MATCH: "if-none-match",
|
|
836
|
+
/**
|
|
837
|
+
* If the entity is unchanged, send me the part(s) that I am missing, otherwise, send me the entire new entity.
|
|
838
|
+
* Permanent.
|
|
839
|
+
*
|
|
840
|
+
* @example
|
|
841
|
+
* <code>If-Range: "737060cd8c284d8af7ad3082f209582d"</code>
|
|
842
|
+
*/
|
|
466
843
|
IF_RANGE: "if-range",
|
|
844
|
+
/**
|
|
845
|
+
* Only send the response if the entity has not been modified since a specific time. Permanent.
|
|
846
|
+
*
|
|
847
|
+
* @example
|
|
848
|
+
* <code>If-Unmodified-Since: Sat, 29 Oct 1994 19:43:31 GMT</code>
|
|
849
|
+
*/
|
|
467
850
|
IF_UNMODIFIED_SINCE: "if-unmodified-since",
|
|
851
|
+
/**
|
|
852
|
+
* Limit the number of times the message can be forwarded through proxies or gateways. Permanent.
|
|
853
|
+
*
|
|
854
|
+
* @example
|
|
855
|
+
* <code>Max-Forwards: 10</code>
|
|
856
|
+
*/
|
|
468
857
|
MAX_FORWARDS: "max-forwards",
|
|
858
|
+
/**
|
|
859
|
+
* Initiates a request for cross-origin resource sharing (asks server for an 'Access-Control-Allow-Origin' response
|
|
860
|
+
* field). Permanent: standard.
|
|
861
|
+
*
|
|
862
|
+
* @example
|
|
863
|
+
* <code>Origin: http://www.example-social-network.com</code>
|
|
864
|
+
*/
|
|
469
865
|
ORIGIN: "origin",
|
|
866
|
+
/**
|
|
867
|
+
* Implementation-specific fields that may have various effects anywhere along the request-response chain. Permanent.
|
|
868
|
+
*
|
|
869
|
+
* @example
|
|
870
|
+
* <code>Pragma: no-cache</code>
|
|
871
|
+
*/
|
|
470
872
|
PRAGMA: "pragma",
|
|
873
|
+
/**
|
|
874
|
+
* Authorization credentials for connecting to a proxy. Permanent.
|
|
875
|
+
*
|
|
876
|
+
* @example
|
|
877
|
+
* <code>Proxy-Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==</code>
|
|
878
|
+
*/
|
|
471
879
|
PROXY_AUTHORIZATION: "proxy-authorization",
|
|
880
|
+
/**
|
|
881
|
+
* Request only part of an entity. Bytes are numbered from 0. See Byte serving. Permanent.
|
|
882
|
+
*
|
|
883
|
+
* @example
|
|
884
|
+
* <code>Range: bytes=500-999</code>
|
|
885
|
+
*/
|
|
472
886
|
RANGE: "range",
|
|
887
|
+
/**
|
|
888
|
+
* This is the address of the previous web page from which a link to the currently requested page was followed. (The
|
|
889
|
+
* word "referrer" has been misspelled in the RFC as well as in most implementations to the point that it has become
|
|
890
|
+
* standard usage and is considered correct terminology). Permanent.
|
|
891
|
+
*
|
|
892
|
+
* @example
|
|
893
|
+
* <code>Referer: http://en.wikipedia.org/wiki/Main_Page</code>
|
|
894
|
+
*/
|
|
473
895
|
REFERER: "referer",
|
|
896
|
+
/**
|
|
897
|
+
* The transfer encodings the user agent is willing to accept: the same values as for the response header field
|
|
898
|
+
* Transfer-Encoding can be used, plus the "trailers" value (related to the "chunked" transfer method) to notify the
|
|
899
|
+
* server it expects to receive additional fields in the trailer after the last, zero-sized, chunk. Permanent.
|
|
900
|
+
*
|
|
901
|
+
* @example
|
|
902
|
+
* <code>TE: trailers, deflate</code>
|
|
903
|
+
*/
|
|
474
904
|
TE: "te",
|
|
905
|
+
/**
|
|
906
|
+
* The user agent string of the user agent. Permanent.
|
|
907
|
+
*
|
|
908
|
+
* @example
|
|
909
|
+
* <code>User-Agent: Mozilla/5.0 (X11, Linux x86_64, rv:12.0) Gecko/20100101 Firefox/21.0</code>
|
|
910
|
+
*/
|
|
475
911
|
USER_AGENT: "user-agent",
|
|
912
|
+
/**
|
|
913
|
+
* Ask the server to upgrade to another protocol. Permanent.
|
|
914
|
+
*
|
|
915
|
+
* @example
|
|
916
|
+
* <code>Upgrade: HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11</code>
|
|
917
|
+
*/
|
|
476
918
|
UPGRADE: "upgrade",
|
|
919
|
+
/**
|
|
920
|
+
* Informs the server of proxies through which the request was sent. Permanent.
|
|
921
|
+
*
|
|
922
|
+
* @example
|
|
923
|
+
* <code>Via: 1.0 fred, 1.1 example.com (Apache/1.1)</code>
|
|
924
|
+
*/
|
|
477
925
|
VIA: "via",
|
|
926
|
+
/**
|
|
927
|
+
* A general warning about possible problems with the entity body. Permanent.
|
|
928
|
+
*
|
|
929
|
+
* @example
|
|
930
|
+
* <code>Warning: 199 Miscellaneous warning</code>
|
|
931
|
+
*/
|
|
478
932
|
WARNING: "warning",
|
|
933
|
+
/**
|
|
934
|
+
* mainly used to identify Ajax requests. Most JavaScript frameworks send this field with value of XMLHttpRequest.
|
|
935
|
+
*
|
|
936
|
+
* @example
|
|
937
|
+
* <code>X-Requested-With: XMLHttpRequest</code>
|
|
938
|
+
*/
|
|
479
939
|
X_REQUESTED_WITH: "x-requested-with",
|
|
940
|
+
/**
|
|
941
|
+
* Requests a web application to disable their tracking of a user. This is Mozilla's version of the X-Do-Not-Track
|
|
942
|
+
* header field (since Firefox 4.0 Beta 11). Safari and IE9 also have support for this field. On March 7, 2011, a
|
|
943
|
+
* draft proposal was submitted to IETF. The W3C Tracking Protection Working Group is producing a specification.
|
|
944
|
+
*
|
|
945
|
+
* @example
|
|
946
|
+
* <code>DNT: 1 (Do Not Track Enabled)</code>
|
|
947
|
+
* <code>DNT: 0 (Do Not Track Disabled)</code>
|
|
948
|
+
*/
|
|
480
949
|
DNT: "dnt",
|
|
950
|
+
/**
|
|
951
|
+
* A de facto standard for identifying the originating IP address of a client connecting to a web server through an
|
|
952
|
+
* HTTP proxy or load balancer.
|
|
953
|
+
*
|
|
954
|
+
* @example
|
|
955
|
+
* <code>X-Forwarded-For: client1, proxy1, proxy2</code>
|
|
956
|
+
* <code>X-Forwarded-For: 129.78.138.66, 129.78.64.103</code>
|
|
957
|
+
*/
|
|
481
958
|
X_FORWARDED_FOR: "x-forwarded-for",
|
|
959
|
+
/**
|
|
960
|
+
* A de facto standard for identifying the original host requested by the client in the Host HTTP request header, since
|
|
961
|
+
* the host name and/or port of the reverse proxy (load balancer) may differ from the origin server handling the
|
|
962
|
+
* request.
|
|
963
|
+
*
|
|
964
|
+
* @example
|
|
965
|
+
* <code>X-Forwarded-Host: en.wikipedia.org:80</code>
|
|
966
|
+
* <code>X-Forwarded-Host: en.wikipedia.org</code>
|
|
967
|
+
*/
|
|
482
968
|
X_FORWARDED_HOST: "x-forwarded-host",
|
|
969
|
+
/**
|
|
970
|
+
* A de facto standard for identifying the originating protocol of an HTTP request, since a reverse proxy (load
|
|
971
|
+
* balancer) may communicate with a web server using HTTP even if the request to the reverse proxy is HTTPS. An
|
|
972
|
+
* alternative form of the header (X-ProxyUser-Ip) is used by Google clients talking to Google servers.
|
|
973
|
+
*
|
|
974
|
+
* @example
|
|
975
|
+
* <code>X-Forwarded-Proto: https</code>
|
|
976
|
+
*/
|
|
483
977
|
X_FORWARDED_PROTO: "x-forwarded-proto",
|
|
978
|
+
/**
|
|
979
|
+
* Non-standard header field used by Microsoft applications and load-balancers.
|
|
980
|
+
*
|
|
981
|
+
* @example
|
|
982
|
+
* <code>Front-End-Https: on</code>
|
|
983
|
+
*/
|
|
484
984
|
FRONT_END_HTTPS: "front-end-https",
|
|
985
|
+
/**
|
|
986
|
+
* Requests a web application override the method specified in the request (typically POST) with the method given in
|
|
987
|
+
* the header field (typically PUT or DELETE). Can be used when a user agent or firewall prevents PUT or DELETE methods
|
|
988
|
+
* from being sent directly (note that this either a bug in the software component, which ought to be fixed, or an
|
|
989
|
+
* intentional configuration, in which case bypassing it may be the wrong thing to do).
|
|
990
|
+
*
|
|
991
|
+
* @example
|
|
992
|
+
* <code>X-HTTP-Method-Override: DELETE</code>
|
|
993
|
+
*/
|
|
485
994
|
X_HTTP_METHOD_OVERRIDE: "x-http-method-override",
|
|
995
|
+
/**
|
|
996
|
+
* Allows easier parsing of the MakeModel/Firmware that is usually found in the User-Agent String of AT&T Devices.
|
|
997
|
+
*
|
|
998
|
+
* @example
|
|
999
|
+
* <code>X-Att-Deviceid: GT-P7320/P7320XXLPG</code>
|
|
1000
|
+
*/
|
|
486
1001
|
X_ATT_DEVICE_ID: "x-att-deviceid",
|
|
1002
|
+
/**
|
|
1003
|
+
* Links to an XML file on the Internet with a full description and details about the device currently connecting. In the example to the right is an XML file for an AT&T Samsung Galaxy S2.
|
|
1004
|
+
* x-wap-profile: http://wap.samsungmobile.com/uaprof/SGH-I777.xml
|
|
1005
|
+
*/
|
|
487
1006
|
X_WAP_PROFILE: "x-wap-profile"
|
|
488
1007
|
};
|
|
489
1008
|
var http_request_headers_default = HttpRequestHeader;
|
|
490
1009
|
|
|
491
1010
|
// src/http-request-methods.js
|
|
492
1011
|
var HttpRequestMethod = {
|
|
1012
|
+
/**
|
|
1013
|
+
* The OPTIONS method represents a request for information about the communication options available on the
|
|
1014
|
+
* request/response chain identified by the Request-URI. This method allows the client to determine the options and/or
|
|
1015
|
+
* requirements associated with a resource, or the capabilities of a server, without implying a resource action or
|
|
1016
|
+
* initiating a resource retrieval.
|
|
1017
|
+
*
|
|
1018
|
+
* Responses to this method are not cacheable.
|
|
1019
|
+
*
|
|
1020
|
+
* If the OPTIONS request includes an entity-body (as indicated by the presence of Content-Length or
|
|
1021
|
+
* Transfer-Encoding), then the media type MUST be indicated by a Content-Type field. Although this specification does
|
|
1022
|
+
* not define any use for such a body, future extensions to HTTP might use the OPTIONS body to make more detailed
|
|
1023
|
+
* queries on the server. A server that does not support such an extension MAY discard the request body.
|
|
1024
|
+
*
|
|
1025
|
+
* If the Request-URI is an asterisk ("*"), the OPTIONS request is intended to apply to the server in general rather
|
|
1026
|
+
* than to a specific resource. Since a server's communication options typically depend on the resource, the "*"
|
|
1027
|
+
* request is only useful as a "ping" or "no-op" type of method, it does nothing beyond allowing the client to test the
|
|
1028
|
+
* capabilities of the server. For example, this can be used to test a proxy for HTTP/1.1 compliance (or lack thereof).
|
|
1029
|
+
*
|
|
1030
|
+
* If the Request-URI is not an asterisk, the OPTIONS request applies only to the options that are available when
|
|
1031
|
+
* communicating with that resource.
|
|
1032
|
+
*
|
|
1033
|
+
* A 200 response SHOULD include any header fields that indicate optional features implemented by the server and
|
|
1034
|
+
* applicable to that resource (e.g., Allow), possibly including extensions not defined by this specification. The
|
|
1035
|
+
* response body, if any, SHOULD also include information about the communication options. The format for such a body
|
|
1036
|
+
* is not defined by this specification, but might be defined by future extensions to HTTP. Content negotiation MAY be
|
|
1037
|
+
* used to select the appropriate response format. If no response body is included, the response MUST include a
|
|
1038
|
+
* Content-Length field with a field-value of "0".
|
|
1039
|
+
*
|
|
1040
|
+
* The Max-Forwards request-header field MAY be used to target a specific proxy in the request chain. When a proxy
|
|
1041
|
+
* receives an OPTIONS request on an absoluteURI for which request forwarding is permitted, the proxy MUST check for a
|
|
1042
|
+
* Max-Forwards field. If the Max-Forwards field-value is zero ("0"), the proxy MUST NOT forward the message, instead,
|
|
1043
|
+
* the proxy SHOULD respond with its own communication options. If the Max-Forwards field-value is an integer greater
|
|
1044
|
+
* than zero, the proxy MUST decrement the field-value when it forwards the request. If no Max-Forwards field is
|
|
1045
|
+
* present in the request, then the forwarded request MUST NOT include a Max-Forwards field.
|
|
1046
|
+
*/
|
|
493
1047
|
OPTIONS: "OPTIONS",
|
|
1048
|
+
/**
|
|
1049
|
+
* The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI. If
|
|
1050
|
+
* the Request-URI refers to a data-producing process, it is the produced data which shall be returned as the entity in
|
|
1051
|
+
* the response and not the source text of the process, unless that text happens to be the output of the process.
|
|
1052
|
+
*
|
|
1053
|
+
* The semantics of the GET method change to a "conditional GET" if the request message includes an If-Modified-Since;
|
|
1054
|
+
* If-Unmodified-Since, If-Match, If-None-Match, or If-Range header field. A conditional GET method requests that the
|
|
1055
|
+
* entity be transferred only under the circumstances described by the conditional header field(s). The conditional GET
|
|
1056
|
+
* method is intended to reduce unnecessary network usage by allowing cached entities to be refreshed without requiring
|
|
1057
|
+
* multiple requests or transferring data already held by the client.
|
|
1058
|
+
*
|
|
1059
|
+
* The semantics of the GET method change to a "partial GET" if the request message includes a Range header field. A
|
|
1060
|
+
* partial GET requests that only part of the entity be transferred, as described in section 14.35. The partial GET
|
|
1061
|
+
* method is intended to reduce unnecessary network usage by allowing partially-retrieved entities to be completed
|
|
1062
|
+
* without transferring data already held by the client.
|
|
1063
|
+
*
|
|
1064
|
+
* The response to a GET request is cacheable if and only if it meets the requirements for HTTP caching described in
|
|
1065
|
+
* section 13.
|
|
1066
|
+
*
|
|
1067
|
+
* See section 15.1.3 for security considerations when used for forms.
|
|
1068
|
+
*/
|
|
494
1069
|
GET: "GET",
|
|
1070
|
+
/**
|
|
1071
|
+
* The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response. The
|
|
1072
|
+
* meta information contained in the HTTP headers in response to a HEAD request SHOULD be identical to the information
|
|
1073
|
+
* sent in response to a GET request. This method can be used for obtaining meta information about the entity implied by
|
|
1074
|
+
* the request without transferring the entity-body itself. This method is often used for testing hypertext links for
|
|
1075
|
+
* validity, accessibility, and recent modification.
|
|
1076
|
+
*
|
|
1077
|
+
* The response to a HEAD request MAY be cacheable in the sense that the information contained in the response MAY be
|
|
1078
|
+
* used to update a previously cached entity from that resource. If the new field values indicate that the cached
|
|
1079
|
+
* entity differs from the current entity (as would be indicated by a change in Content-Length, Content-MD5, ETag or
|
|
1080
|
+
* Last-Modified), then the cache MUST treat the cache entry as stale.
|
|
1081
|
+
*/
|
|
495
1082
|
HEAD: "HEAD",
|
|
1083
|
+
/**
|
|
1084
|
+
* The POST method is used to request that the origin server accept the entity enclosed in the request as a new
|
|
1085
|
+
* subordinate of the resource identified by the Request-URI in the Request-Line. POST is designed to allow a uniform
|
|
1086
|
+
* method to cover the following functions:
|
|
1087
|
+
* <ul>
|
|
1088
|
+
* <li>Annotation of existing resources,</li>
|
|
1089
|
+
* <li>Posting a message to a bulletin board, newsgroup, mailing list, or similar group of articles,</li>
|
|
1090
|
+
* <li>Providing a block of data, such as the result of submitting a form, to a data-handling process,</li>
|
|
1091
|
+
* <li>Extending a database through an append operation.</li>
|
|
1092
|
+
* </ul>
|
|
1093
|
+
*
|
|
1094
|
+
* The actual function performed by the POST method is determined by the server and is usually dependent on the
|
|
1095
|
+
* Request-URI. The posted entity is subordinate to that URI in the same way that a file is subordinate to a directory
|
|
1096
|
+
* containing it, a news article is subordinate to a newsgroup to which it is posted, or a record is subordinate to a
|
|
1097
|
+
* database.
|
|
1098
|
+
*
|
|
1099
|
+
* The action performed by the POST method might not result in a resource that can be identified by a URI. In this
|
|
1100
|
+
* case, either 200 (OK) or 204 (No Content) is the appropriate response status, depending on whether or not the
|
|
1101
|
+
* response includes an entity that describes the result.
|
|
1102
|
+
*
|
|
1103
|
+
* If a resource has been created on the origin server, the response SHOULD be 201 (Created) and contain an entity
|
|
1104
|
+
* which describes the status of the request and refers to the new resource, and a Location header (see section 14.30).
|
|
1105
|
+
*
|
|
1106
|
+
* Responses to this method are not cacheable, unless the response includes appropriate Cache-Control or Expires header
|
|
1107
|
+
* fields. However, the 303 (See Other) response can be used to direct the user agent to retrieve a cacheable resource.
|
|
1108
|
+
*
|
|
1109
|
+
* POST requests MUST obey the message transmission requirements set out in section 8.2.
|
|
1110
|
+
*
|
|
1111
|
+
* See section 15.1.3 for security considerations.
|
|
1112
|
+
*/
|
|
496
1113
|
POST: "POST",
|
|
1114
|
+
/**
|
|
1115
|
+
* The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers
|
|
1116
|
+
* to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing
|
|
1117
|
+
* on the origin server. If the Request-URI does not point to an existing resource, and that URI is capable of being
|
|
1118
|
+
* defined as a new resource by the requesting user agent, the origin server can create the resource with that URI. If
|
|
1119
|
+
* a new resource is created, the origin server MUST inform the user agent via the 201 (Created) response. If an
|
|
1120
|
+
* existing resource is modified, either the 200 (OK) or 204 (No Content) response codes SHOULD be sent to indicate
|
|
1121
|
+
* successful completion of the request. If the resource could not be created or modified with the Request-URI, an
|
|
1122
|
+
* appropriate error response SHOULD be given that reflects the nature of the problem. The recipient of the entity MUST
|
|
1123
|
+
* \NOT ignore any Content-* (e.g. Content-Range) headers that it does not understand or implement and MUST return a
|
|
1124
|
+
* 501 (Not Implemented) response in such cases.
|
|
1125
|
+
*
|
|
1126
|
+
* If the request passes through a cache and the Request-URI identifies one or more currently cached entities, those
|
|
1127
|
+
* entries SHOULD be treated as stale. Responses to this method are not cacheable.
|
|
1128
|
+
*
|
|
1129
|
+
* The fundamental difference between the POST and PUT requests is reflected in the different meaning of the
|
|
1130
|
+
* Request-URI. The URI in a POST request identifies the resource that will handle the enclosed entity. That resource
|
|
1131
|
+
* might be a data-accepting process, a gateway to some other protocol, or a separate entity that accepts annotations.
|
|
1132
|
+
* In contrast, the URI in a PUT request identifies the entity enclosed with the request -- the user agent knows what
|
|
1133
|
+
* URI is intended and the server MUST NOT attempt to apply the request to some other resource. If the server desires
|
|
1134
|
+
* that the request be applied to a different URI, it MUST send a 301 (Moved Permanently) response, the user agent MAY
|
|
1135
|
+
* then make its own decision regarding whether or not to redirect the request.
|
|
1136
|
+
*
|
|
1137
|
+
* A single resource MAY be identified by many different URIs. For example, an article might have a URI for identifying
|
|
1138
|
+
* "the current version" which is separate from the URI identifying each particular version. In this case, a PUT
|
|
1139
|
+
* request on a general URI might result in several other URIs being defined by the origin server.
|
|
1140
|
+
*
|
|
1141
|
+
* HTTP/1.1 does not define how a PUT method affects the state of an origin server.
|
|
1142
|
+
*
|
|
1143
|
+
* PUT requests MUST obey the message transmission requirements set out in section 8.2.
|
|
1144
|
+
*
|
|
1145
|
+
* Unless otherwise specified for a particular entity-header, the entity-headers in the PUT request SHOULD be applied
|
|
1146
|
+
* to the resource created or modified by the PUT.
|
|
1147
|
+
*/
|
|
497
1148
|
PUT: "PUT",
|
|
1149
|
+
/**
|
|
1150
|
+
* The DELETE method requests that the origin server delete the resource identified by the Request-URI. This method MAY
|
|
1151
|
+
* be overridden by human intervention (or other means) on the origin server. The client cannot be guaranteed that the
|
|
1152
|
+
* operation has been carried out, even if the status code returned from the origin server indicates that the action
|
|
1153
|
+
* has been completed successfully. However, the server SHOULD NOT indicate success unless, at the time the response
|
|
1154
|
+
* is given, it intends to delete the resource or move it to an inaccessible location.
|
|
1155
|
+
*
|
|
1156
|
+
* A successful response SHOULD be 200 (OK) if the response includes an entity describing the status, 202 (Accepted) if
|
|
1157
|
+
* the action has not yet been enacted, or 204 (No Content) if the action has been enacted but the response does not
|
|
1158
|
+
* include an entity.
|
|
1159
|
+
*
|
|
1160
|
+
* If the request passes through a cache and the Request-URI identifies one or more currently cached entities, those
|
|
1161
|
+
* entries SHOULD be treated as stale. Responses to this method are not cacheable.
|
|
1162
|
+
*/
|
|
498
1163
|
DELETE: "DELETE",
|
|
1164
|
+
/**
|
|
1165
|
+
* The TRACE method is used to invoke a remote, application-layer loop- back of the request message. The final
|
|
1166
|
+
* recipient of the request SHOULD reflect the message received back to the client as the entity-body of a 200 (OK)
|
|
1167
|
+
* response. The final recipient is either the origin server or the first proxy or gateway to receive a Max-Forwards
|
|
1168
|
+
* value of zero (0) in the request (see section 14.31). A TRACE request MUST NOT include an entity.
|
|
1169
|
+
*
|
|
1170
|
+
* TRACE allows the client to see what is being received at the other end of the request chain and use that data for
|
|
1171
|
+
* testing or diagnostic information. The value of the Via header field (section 14.45) is of particular interest,
|
|
1172
|
+
* since it acts as a trace of the request chain. Use of the Max-Forwards header field allows the client to limit the
|
|
1173
|
+
* length of the request chain, which is useful for testing a chain of proxies forwarding messages in an infinite loop.
|
|
1174
|
+
*
|
|
1175
|
+
* If the request is valid, the response SHOULD contain the entire request message in the entity-body, with a
|
|
1176
|
+
* Content-Type of "message/http". Responses to this method MUST NOT be cached.
|
|
1177
|
+
*/
|
|
499
1178
|
TRACE: "TRACE",
|
|
1179
|
+
/**
|
|
1180
|
+
* This specification reserves the method name CONNECT for use with a proxy that can dynamically switch to being a
|
|
1181
|
+
* tunnel (e.g. SSL tunneling [44]).
|
|
1182
|
+
*/
|
|
500
1183
|
CONNECT: "CONNECT",
|
|
1184
|
+
/**
|
|
1185
|
+
* The PATCH method requests that a set of changes described in the
|
|
1186
|
+
* request entity be applied to the resource identified by the Request-
|
|
1187
|
+
* URI. The set of changes is represented in a format called a "patch
|
|
1188
|
+
* document" identified by a media type. If the Request-URI does not
|
|
1189
|
+
* point to an existing resource, the server MAY create a new resource,
|
|
1190
|
+
* depending on the patch document type (whether it can logically modify
|
|
1191
|
+
* a null resource) and permissions, etc.
|
|
1192
|
+
*
|
|
1193
|
+
* The difference between the PUT and PATCH requests is reflected in the
|
|
1194
|
+
* way the server processes the enclosed entity to modify the resource
|
|
1195
|
+
* identified by the Request-URI. In a PUT request, the enclosed entity
|
|
1196
|
+
* is considered to be a modified version of the resource stored on the
|
|
1197
|
+
* origin server, and the client is requesting that the stored version
|
|
1198
|
+
* be replaced. With PATCH, however, the enclosed entity contains a set
|
|
1199
|
+
* of instructions describing how a resource currently residing on the
|
|
1200
|
+
* origin server should be modified to produce a new version. The PATCH
|
|
1201
|
+
* method affects the resource identified by the Request-URI, and it
|
|
1202
|
+
* also MAY have side effects on other resources; i.e., new resources
|
|
1203
|
+
* may be created, or existing ones modified, by the application of a
|
|
1204
|
+
* PATCH.
|
|
1205
|
+
*
|
|
1206
|
+
* PATCH is neither safe nor idempotent as defined by [RFC2616], Section
|
|
1207
|
+
* 9.1.
|
|
1208
|
+
*
|
|
1209
|
+
* A PATCH request can be issued in such a way as to be idempotent,
|
|
1210
|
+
* which also helps prevent bad outcomes from collisions between two
|
|
1211
|
+
* PATCH requests on the same resource in a similar time frame.
|
|
1212
|
+
* Collisions from multiple PATCH requests may be more dangerous than
|
|
1213
|
+
* PUT collisions because some patch formats need to operate from a
|
|
1214
|
+
* known base-point or else they will corrupt the resource. Clients
|
|
1215
|
+
* using this kind of patch application SHOULD use a conditional request
|
|
1216
|
+
* such that the request will fail if the resource has been updated
|
|
1217
|
+
* since the client last accessed the resource. For example, the client
|
|
1218
|
+
* can use a strong ETag [RFC2616] in an If-Match header on the PATCH
|
|
1219
|
+
* request.
|
|
1220
|
+
*
|
|
1221
|
+
* There are also cases where patch formats do not need to operate from
|
|
1222
|
+
* a known base-point (e.g., appending text lines to log files, or non-
|
|
1223
|
+
* colliding rows to database tables), in which case the same care in
|
|
1224
|
+
* client requests is not needed.
|
|
1225
|
+
*
|
|
1226
|
+
* The server MUST apply the entire set of changes atomically and never
|
|
1227
|
+
* provide (e.g., in response to a GET during this operation) a
|
|
1228
|
+
* partially modified representation. If the entire patch document
|
|
1229
|
+
* cannot be successfully applied, then the server MUST NOT apply any of
|
|
1230
|
+
* the changes. The determination of what constitutes a successful
|
|
1231
|
+
* PATCH can vary depending on the patch document and the type of
|
|
1232
|
+
* resource(s) being modified. For example, the common 'diff' utility
|
|
1233
|
+
* can generate a patch document that applies to multiple files in a
|
|
1234
|
+
* directory hierarchy. The atomicity requirement holds for all
|
|
1235
|
+
* directly affected files. See "Error Handling", Section 2.2, for
|
|
1236
|
+
* details on status codes and possible error conditions.
|
|
1237
|
+
*
|
|
1238
|
+
* If the request passes through a cache and the Request-URI identifies
|
|
1239
|
+
* one or more currently cached entities, those entries SHOULD be
|
|
1240
|
+
* treated as stale. A response to this method is only cacheable if it
|
|
1241
|
+
* contains explicit freshness information (such as an Expires header or
|
|
1242
|
+
* "Cache-Control: max-age" directive) as well as the Content-Location
|
|
1243
|
+
* header matching the Request-URI, indicating that the PATCH response
|
|
1244
|
+
* body is a resource representation. A cached PATCH response can only
|
|
1245
|
+
* be used to respond to subsequent GET and HEAD requests; it MUST NOT
|
|
1246
|
+
* be used to respond to other methods (in particular, PATCH).
|
|
1247
|
+
*
|
|
1248
|
+
* Note that entity-headers contained in the request apply only to the
|
|
1249
|
+
* contained patch document and MUST NOT be applied to the resource
|
|
1250
|
+
* being modified. Thus, a Content-Language header could be present on
|
|
1251
|
+
* the request, but it would only mean (for whatever that's worth) that
|
|
1252
|
+
* the patch document had a language. Servers SHOULD NOT store such
|
|
1253
|
+
* headers except as trace information, and SHOULD NOT use such header
|
|
1254
|
+
* values the same way they might be used on PUT requests. Therefore,
|
|
1255
|
+
* this document does not specify a way to modify a document's Content-
|
|
1256
|
+
* Type or Content-Language value through headers, though a mechanism
|
|
1257
|
+
* could well be designed to achieve this goal through a patch document.
|
|
1258
|
+
*
|
|
1259
|
+
* There is no guarantee that a resource can be modified with PATCH.
|
|
1260
|
+
* Further, it is expected that different patch document formats will be
|
|
1261
|
+
* appropriate for different types of resources and that no single
|
|
1262
|
+
* format will be appropriate for all types of resources. Therefore,
|
|
1263
|
+
* there is no single default patch document format that implementations
|
|
1264
|
+
* are required to support. Servers MUST ensure that a received patch
|
|
1265
|
+
* document is appropriate for the type of resource identified by the
|
|
1266
|
+
* Request-URI.
|
|
1267
|
+
*
|
|
1268
|
+
* Clients need to choose when to use PATCH rather than PUT. For
|
|
1269
|
+
* example, if the patch document size is larger than the size of the
|
|
1270
|
+
* new resource data that would be used in a PUT, then it might make
|
|
1271
|
+
* sense to use PUT instead of PATCH. A comparison to POST is even more
|
|
1272
|
+
* difficult, because POST is used in widely varying ways and can
|
|
1273
|
+
* encompass PUT and PATCH-like operations if the server chooses. If
|
|
1274
|
+
* the operation does not modify the resource identified by the Request-
|
|
1275
|
+
* URI in a predictable way, POST should be considered instead of PATCH
|
|
1276
|
+
* or PUT.
|
|
1277
|
+
*/
|
|
501
1278
|
PATCH: "PATCH"
|
|
502
1279
|
};
|
|
503
1280
|
var http_request_methods_default = HttpRequestMethod;
|
|
504
1281
|
|
|
505
1282
|
// src/http-response-headers.js
|
|
506
1283
|
var HttpResponseHeader = {
|
|
1284
|
+
/**
|
|
1285
|
+
* Implemented as a misunderstanding of the HTTP specifications. Common because of mistakes in implementations of early HTTP versions. Has exactly the same functionality as standard Connection field.
|
|
1286
|
+
*
|
|
1287
|
+
* @example
|
|
1288
|
+
* proxy-connection: keep-alive
|
|
1289
|
+
*/
|
|
507
1290
|
PROXY_CONNECTION: "proxy-connection",
|
|
1291
|
+
/**
|
|
1292
|
+
* Server-side deep packet insertion of a unique ID identifying customers of Verizon Wireless, also known as "perma-cookie" or "supercookie"
|
|
1293
|
+
*
|
|
1294
|
+
* @example
|
|
1295
|
+
* x-uidh: ...
|
|
1296
|
+
*/
|
|
508
1297
|
X_UIDH: "x-uidh",
|
|
1298
|
+
/**
|
|
1299
|
+
* Used to prevent cross-site request forgery. Alternative header names are: X-CSRFToken and X-XSRF-TOKEN
|
|
1300
|
+
*
|
|
1301
|
+
* @example
|
|
1302
|
+
* x-csrf-token: i8XNjC4b8KVok4uw5RftR38Wgp2BFwql
|
|
1303
|
+
*/
|
|
509
1304
|
X_CSRF_TOKEN: "x-csrf-token",
|
|
1305
|
+
/**
|
|
1306
|
+
* Specifying which web sites can participate in cross-origin resource sharing
|
|
1307
|
+
*
|
|
1308
|
+
* @example
|
|
1309
|
+
* access-control-allow-origin: *
|
|
1310
|
+
* Provisional
|
|
1311
|
+
*/
|
|
510
1312
|
ACCESS_CONTROL_ALLOW_ORIGIN: "access-control-allow-origin",
|
|
1313
|
+
/**
|
|
1314
|
+
* Specifies which patch document formats this server supports
|
|
1315
|
+
*
|
|
1316
|
+
* @example
|
|
1317
|
+
* accept-patch: text/example,charset=utf-8
|
|
1318
|
+
* Permanent
|
|
1319
|
+
*/
|
|
511
1320
|
ACCEPT_PATCH: "accept-patch",
|
|
1321
|
+
/**
|
|
1322
|
+
* What partial content range types this server supports via byte serving
|
|
1323
|
+
*
|
|
1324
|
+
* @example
|
|
1325
|
+
* accept-ranges: bytes
|
|
1326
|
+
* Permanent
|
|
1327
|
+
*/
|
|
512
1328
|
ACCEPT_RANGES: "accept-ranges",
|
|
1329
|
+
/**
|
|
1330
|
+
* The age the object has been in a proxy cache in seconds
|
|
1331
|
+
*
|
|
1332
|
+
* @example
|
|
1333
|
+
* age: 12
|
|
1334
|
+
* Permanent
|
|
1335
|
+
*/
|
|
513
1336
|
AGE: "age",
|
|
1337
|
+
/**
|
|
1338
|
+
* Valid actions for a specified resource. To be used for a 405 Method not allowed
|
|
1339
|
+
*
|
|
1340
|
+
* @example
|
|
1341
|
+
* allow: GET, HEAD
|
|
1342
|
+
* Permanent
|
|
1343
|
+
*/
|
|
514
1344
|
ALLOW: "allow",
|
|
1345
|
+
/**
|
|
1346
|
+
* Tells all caching mechanisms from server to client whether they may cache this object. It is measured in seconds
|
|
1347
|
+
*
|
|
1348
|
+
* @example
|
|
1349
|
+
* cache-control: max-age=3600
|
|
1350
|
+
* Permanent
|
|
1351
|
+
*/
|
|
515
1352
|
CACHE_CONTROL: "cache-control",
|
|
1353
|
+
/**
|
|
1354
|
+
* Control options for the current connection and list of hop-by-hop response fields
|
|
1355
|
+
*
|
|
1356
|
+
* @example
|
|
1357
|
+
* connection: close
|
|
1358
|
+
* Permanent
|
|
1359
|
+
*/
|
|
516
1360
|
CONNECTION: "connection",
|
|
1361
|
+
/**
|
|
1362
|
+
* An opportunity to raise a "File Download" dialogue box for a known MIME type with binary format or suggest a filename for dynamic content. Quotes are necessary with special characters.
|
|
1363
|
+
*
|
|
1364
|
+
* @example
|
|
1365
|
+
* content-disposition: attachment, filename="fname.ext"
|
|
1366
|
+
* Permanent
|
|
1367
|
+
*/
|
|
517
1368
|
CONTENT_DISPOSITION: "content-disposition",
|
|
1369
|
+
/**
|
|
1370
|
+
* The type of encoding used on the data. See HTTP compression.
|
|
1371
|
+
*
|
|
1372
|
+
* @example
|
|
1373
|
+
* content-encoding: gzip
|
|
1374
|
+
* Permanent
|
|
1375
|
+
*/
|
|
518
1376
|
CONTENT_ENCODING: "content-encoding",
|
|
1377
|
+
/**
|
|
1378
|
+
* The natural language or languages of the intended audience for the enclosed content
|
|
1379
|
+
*
|
|
1380
|
+
* @example
|
|
1381
|
+
* content-language: da
|
|
1382
|
+
* Permanent
|
|
1383
|
+
*/
|
|
519
1384
|
CONTENT_LANGUAGE: "content-language",
|
|
1385
|
+
/**
|
|
1386
|
+
* The length of the response body in octets (8-bit bytes)
|
|
1387
|
+
*
|
|
1388
|
+
* @example
|
|
1389
|
+
* content-length: 348
|
|
1390
|
+
* Permanent
|
|
1391
|
+
*/
|
|
520
1392
|
CONTENT_LENGTH: "content-length",
|
|
1393
|
+
/**
|
|
1394
|
+
* An alternate location for the returned data
|
|
1395
|
+
*
|
|
1396
|
+
* @example
|
|
1397
|
+
* content-location: /index.htm
|
|
1398
|
+
* Permanent
|
|
1399
|
+
*/
|
|
521
1400
|
CONTENT_LOCATION: "content-location",
|
|
1401
|
+
/**
|
|
1402
|
+
* Where in a full body message this partial message belongs
|
|
1403
|
+
*
|
|
1404
|
+
* @example
|
|
1405
|
+
* content-range: bytes 21010-47021/47022
|
|
1406
|
+
* Permanent
|
|
1407
|
+
*/
|
|
522
1408
|
CONTENT_RANGE: "content-range",
|
|
1409
|
+
/**
|
|
1410
|
+
* The MIME type of this content
|
|
1411
|
+
*
|
|
1412
|
+
* @example
|
|
1413
|
+
* content-type: text/html, charset=utf-8
|
|
1414
|
+
* Permanent
|
|
1415
|
+
*/
|
|
523
1416
|
CONTENT_TYPE: "content-type",
|
|
1417
|
+
/**
|
|
1418
|
+
* The date and time that the message was sent (in "HTTP-date" format as defined by RFC 7231)
|
|
1419
|
+
*
|
|
1420
|
+
* @example
|
|
1421
|
+
* date: Tue, 15 Nov 1994 08:12:31 GMT
|
|
1422
|
+
* Permanent
|
|
1423
|
+
*/
|
|
524
1424
|
DATE: "date",
|
|
1425
|
+
/**
|
|
1426
|
+
* An identifier for a specific version of a resource, often a message digest
|
|
1427
|
+
*
|
|
1428
|
+
* @example
|
|
1429
|
+
* etag: "737060cd8c284d8af7ad3082f209582d"
|
|
1430
|
+
* Permanent
|
|
1431
|
+
*/
|
|
525
1432
|
ETAG: "etag",
|
|
1433
|
+
/**
|
|
1434
|
+
* Gives the date/time after which the response is considered stale (in "HTTP-date" format as defined by RFC 7231)
|
|
1435
|
+
*
|
|
1436
|
+
* @example
|
|
1437
|
+
* expires: Thu, 01 Dec 1994 16:00:00 GMT
|
|
1438
|
+
* Permanent
|
|
1439
|
+
*/
|
|
526
1440
|
EXPIRES: "expires",
|
|
1441
|
+
/**
|
|
1442
|
+
* The last modified date for the requested object (in "HTTP-date" format as defined by RFC 7231)
|
|
1443
|
+
*
|
|
1444
|
+
* @example
|
|
1445
|
+
* last-modified: Tue, 15 Nov 1994 12:45:26 GMT
|
|
1446
|
+
* Permanent
|
|
1447
|
+
*/
|
|
527
1448
|
LAST_MODIFIED: "last-modified",
|
|
1449
|
+
/**
|
|
1450
|
+
* Used to express a typed relationship with another resource, where the relation type is defined by RFC 5988
|
|
1451
|
+
*
|
|
1452
|
+
* @example
|
|
1453
|
+
* link: </feed>, rel="alternate"
|
|
1454
|
+
* Permanent
|
|
1455
|
+
*/
|
|
528
1456
|
LINK: "link",
|
|
1457
|
+
/**
|
|
1458
|
+
* Used in redirection, or when a new resource has been created.
|
|
1459
|
+
*
|
|
1460
|
+
* @example
|
|
1461
|
+
* location: http://www.w3.org/pub/WWW/People.html
|
|
1462
|
+
* Permanent
|
|
1463
|
+
*/
|
|
529
1464
|
LOCATION: "location",
|
|
1465
|
+
/**
|
|
1466
|
+
* This field is supposed to set P3P policy, in the form of P3P:CP="your_compact_policy". However, P3P did not take off, most browsers have never fully
|
|
1467
|
+
* implemented it, a lot of websites set this field with fake policy text, that was enough to fool browsers the existence of P3P policy and grant permissions for third party cookies.
|
|
1468
|
+
*
|
|
1469
|
+
* @example
|
|
1470
|
+
* p3p: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
|
|
1471
|
+
* Permanent
|
|
1472
|
+
*/
|
|
530
1473
|
P3P: "p3p",
|
|
1474
|
+
/**
|
|
1475
|
+
* Implementation-specific fields that may have various effects anywhere along the request-response chain.
|
|
1476
|
+
*
|
|
1477
|
+
* @example
|
|
1478
|
+
* pragma: no-cache
|
|
1479
|
+
* Permanent
|
|
1480
|
+
*/
|
|
531
1481
|
PRAGMA: "pragma",
|
|
1482
|
+
/**
|
|
1483
|
+
* Request authentication to access the proxy.
|
|
1484
|
+
*
|
|
1485
|
+
* @example
|
|
1486
|
+
* proxy-authenticate: Basic
|
|
1487
|
+
* Permanent
|
|
1488
|
+
*/
|
|
532
1489
|
PROXY_AUTHENTICATION: "proxy-authenticate",
|
|
1490
|
+
/**
|
|
1491
|
+
* HTTP Public Key Pinning, announces hash of website's authentic TLS certificate
|
|
1492
|
+
*
|
|
1493
|
+
* @example
|
|
1494
|
+
* public-key-pins: max-age=2592000, pin-sha256="E9CZ9INDbd+2eRQozYqqbQ2yXLVKB9+xcprMF+44U1g=",
|
|
1495
|
+
* Permanent
|
|
1496
|
+
*/
|
|
533
1497
|
PUBLIC_KEY_PINS: "public-key-pins",
|
|
1498
|
+
/**
|
|
1499
|
+
* If an entity is temporarily unavailable, this instructs the client to try again later. Value could be a specified period of time (in seconds) or a HTTP-date.
|
|
1500
|
+
*
|
|
1501
|
+
* @example
|
|
1502
|
+
* retry-after: 120
|
|
1503
|
+
* retry-after: Fri, 07 Nov 2014 23:59:59 GMT
|
|
1504
|
+
* Permanent
|
|
1505
|
+
*/
|
|
534
1506
|
RETRY_AFTER: "retry-after",
|
|
1507
|
+
/**
|
|
1508
|
+
* A name for the server
|
|
1509
|
+
*
|
|
1510
|
+
* @example
|
|
1511
|
+
* server: Apache/2.4.1 (Unix)
|
|
1512
|
+
* Permanent
|
|
1513
|
+
*/
|
|
535
1514
|
SERVER: "server",
|
|
1515
|
+
/**
|
|
1516
|
+
* An HTTP cookie
|
|
1517
|
+
*
|
|
1518
|
+
* @example
|
|
1519
|
+
* set-cookie: UserID=JohnDoe, Max-Age=3600, Version=1
|
|
1520
|
+
* Permanent
|
|
1521
|
+
*/
|
|
536
1522
|
SET_COOKIE: "set-cookie",
|
|
1523
|
+
/**
|
|
1524
|
+
* CGI header field specifying the status of the HTTP response. Normal HTTP responses use a separate "Status-Line" instead, defined by RFC 7230.
|
|
1525
|
+
*
|
|
1526
|
+
* @example
|
|
1527
|
+
* status: 200 OK
|
|
1528
|
+
*/
|
|
537
1529
|
STATUS: "status",
|
|
1530
|
+
/**
|
|
1531
|
+
* A HSTS Policy informing the HTTP client how long to cache the HTTPS only policy and whether this applies to subdomains.
|
|
1532
|
+
*
|
|
1533
|
+
* @example
|
|
1534
|
+
* strict-transport-security: max-age=16070400, includeSubDomains
|
|
1535
|
+
* Permanent
|
|
1536
|
+
*/
|
|
538
1537
|
STRICT_TRANSPORT_SECURITY: "strict-transport-security",
|
|
1538
|
+
/**
|
|
1539
|
+
* The Trailer general field value indicates that the given set of header fields is present in the trailer of a message encoded with chunked transfer coding.
|
|
1540
|
+
*
|
|
1541
|
+
* @example
|
|
1542
|
+
* trailer: Max-Forwards
|
|
1543
|
+
* Permanent
|
|
1544
|
+
*/
|
|
539
1545
|
TRAILER: "trailer",
|
|
1546
|
+
/**
|
|
1547
|
+
* The form of encoding used to safely transfer the entity to the user. Currently defined methods are: chunked, compress, deflate, gzip, identity.
|
|
1548
|
+
*
|
|
1549
|
+
* @example
|
|
1550
|
+
* transfer-encoding: chunked
|
|
1551
|
+
* Permanent
|
|
1552
|
+
*/
|
|
540
1553
|
TRANSFER_ENCODING: "transfer-encoding",
|
|
1554
|
+
/**
|
|
1555
|
+
* Ask the client to upgrade to another protocol.
|
|
1556
|
+
*
|
|
1557
|
+
* @example
|
|
1558
|
+
* upgrade: HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11
|
|
1559
|
+
* Permanent
|
|
1560
|
+
*/
|
|
541
1561
|
UPGRADE: "upgrade",
|
|
1562
|
+
/**
|
|
1563
|
+
* Tells downstream proxies how to match future request headers to decide whether the cached response can be used rather than requesting a fresh one from the origin server.
|
|
1564
|
+
*
|
|
1565
|
+
* @example
|
|
1566
|
+
* vary: *
|
|
1567
|
+
* Permanent
|
|
1568
|
+
*/
|
|
542
1569
|
VARY: "vary",
|
|
1570
|
+
/**
|
|
1571
|
+
* Informs the client of proxies through which the response was sent.
|
|
1572
|
+
*
|
|
1573
|
+
* @example
|
|
1574
|
+
* via: 1.0 fred, 1.1 example.com (Apache/1.1)
|
|
1575
|
+
* Permanent
|
|
1576
|
+
*/
|
|
543
1577
|
VIA: "via",
|
|
1578
|
+
/**
|
|
1579
|
+
* A general warning about possible problems with the entity body.
|
|
1580
|
+
*
|
|
1581
|
+
* @example
|
|
1582
|
+
* warning: 199 Miscellaneous warning
|
|
1583
|
+
* Permanent
|
|
1584
|
+
*/
|
|
544
1585
|
WARNING: "warning",
|
|
1586
|
+
/**
|
|
1587
|
+
* Indicates the authentication scheme that should be used to access the requested entity.
|
|
1588
|
+
*
|
|
1589
|
+
* @example
|
|
1590
|
+
* www-authenticate: Basic
|
|
1591
|
+
* Permanent
|
|
1592
|
+
*/
|
|
545
1593
|
WWW_AUTHENTICATE: "www-authenticate",
|
|
1594
|
+
/**
|
|
1595
|
+
* Cross-site scripting (XSS) filter
|
|
1596
|
+
*
|
|
1597
|
+
* @example
|
|
1598
|
+
* x-xss-protection: 1, mode=block
|
|
1599
|
+
*/
|
|
546
1600
|
X_XSS_PROTECTION: "x-xss-protection",
|
|
1601
|
+
/**
|
|
1602
|
+
* The HTTP Content-Security-Policy response header allows web site administrators to control resources the user agent is allowed
|
|
1603
|
+
* to load for a given page. With a few exceptions, policies mostly involve specifying server origins and script endpoints.
|
|
1604
|
+
* This helps guard against cross-site scripting attacks (Cross-site_scripting).
|
|
1605
|
+
*
|
|
1606
|
+
* @example
|
|
1607
|
+
* content-security-policy: default-src
|
|
1608
|
+
*/
|
|
547
1609
|
CONTENT_SECURITY_POLICY: "content-security-policy",
|
|
1610
|
+
/**
|
|
1611
|
+
* The only defined value, "nosniff", prevents Internet Explorer from MIME-sniffing a response away from the declared content-type. This also applies to Google Chrome, when downloading extensions.
|
|
1612
|
+
*
|
|
1613
|
+
* @example
|
|
1614
|
+
* x-content-type-options: nosniff
|
|
1615
|
+
*/
|
|
548
1616
|
X_CONTENT_TYPE_OPTIONS: "x-content-type-options",
|
|
1617
|
+
/**
|
|
1618
|
+
* specifies the technology (e.g. ASP.NET, PHP, JBoss) supporting the web application (version details are often in X-Runtime, X-Version, or X-AspNet-Version)
|
|
1619
|
+
*
|
|
1620
|
+
* @example
|
|
1621
|
+
* x-powered-by: PHP/5.4.0
|
|
1622
|
+
*/
|
|
549
1623
|
X_POWERED_BY: "x-powered-by"
|
|
550
1624
|
};
|
|
551
1625
|
var http_response_headers_default = HttpResponseHeader;
|
|
552
1626
|
|
|
553
|
-
// src/
|
|
554
|
-
var
|
|
1627
|
+
// src/response-status.js
|
|
1628
|
+
var ResponseStatus = class {
|
|
1629
|
+
/** @type {number} */
|
|
1630
|
+
#code;
|
|
1631
|
+
/** @type {string} */
|
|
1632
|
+
#text;
|
|
1633
|
+
/**
|
|
1634
|
+
*
|
|
1635
|
+
* @param {number} code The status code from the {@link Response}
|
|
1636
|
+
* @param {string} text The status text from the {@link Response}
|
|
1637
|
+
*/
|
|
1638
|
+
constructor(code, text) {
|
|
1639
|
+
this.#code = code;
|
|
1640
|
+
this.#text = text;
|
|
1641
|
+
}
|
|
1642
|
+
/**
|
|
1643
|
+
* Returns the status code from the {@link Response}
|
|
1644
|
+
*
|
|
1645
|
+
* @returns {number} The status code.
|
|
1646
|
+
*/
|
|
1647
|
+
get code() {
|
|
1648
|
+
return this.#code;
|
|
1649
|
+
}
|
|
1650
|
+
/**
|
|
1651
|
+
* Returns the status text from the {@link Response}.
|
|
1652
|
+
*
|
|
1653
|
+
* @returns {string} The status text.
|
|
1654
|
+
*/
|
|
1655
|
+
get text() {
|
|
1656
|
+
return this.#text;
|
|
1657
|
+
}
|
|
555
1658
|
};
|
|
1659
|
+
|
|
1660
|
+
// src/transportr.js
|
|
556
1661
|
var endsWithSlashRegEx = /\/$/;
|
|
557
1662
|
var _handleText = async (response) => await response.text();
|
|
558
1663
|
var _handleScript = async (response) => {
|
|
559
1664
|
const objectURL = URL.createObjectURL(await response.blob());
|
|
560
1665
|
document.head.removeChild(document.head.appendChild(Object.assign(document.createElement("script"), { src: objectURL, type: http_media_type_default.JAVA_SCRIPT, async: true })));
|
|
561
1666
|
URL.revokeObjectURL(objectURL);
|
|
1667
|
+
return Promise.resolve();
|
|
562
1668
|
};
|
|
563
1669
|
var _handleCss = async (response) => {
|
|
564
1670
|
const objectURL = URL.createObjectURL(await response.blob());
|
|
565
1671
|
document.head.appendChild(Object.assign(document.createElement("link"), { href: objectURL, type: http_media_type_default.CSS, rel: "stylesheet" }));
|
|
566
1672
|
URL.revokeObjectURL(objectURL);
|
|
1673
|
+
return Promise.resolve();
|
|
567
1674
|
};
|
|
568
1675
|
var _handleJson = async (response) => await response.json();
|
|
569
1676
|
var _handleBlob = async (response) => await response.blob();
|
|
@@ -573,12 +1680,43 @@ var Transportr = (() => {
|
|
|
573
1680
|
var _handleXml = async (response) => new DOMParser().parseFromString(await response.text(), Transportr.MediaType.XML.essence);
|
|
574
1681
|
var _handleHtml = async (response) => new DOMParser().parseFromString(await response.text(), Transportr.MediaType.HTML.essence);
|
|
575
1682
|
var _handleHtmlFragment = async (response) => document.createRange().createContextualFragment(await response.text());
|
|
576
|
-
var _baseUrl, _options, _contentTypeHandlers,
|
|
1683
|
+
var _baseUrl, _options, _contentTypeHandlers, _defaultRequestOptions, _get, get_fn, _createUrl, createUrl_fn, _request, request_fn, _processResponse, processResponse_fn, _needsSerialization, needsSerialization_fn;
|
|
577
1684
|
var _Transportr = class {
|
|
1685
|
+
/**
|
|
1686
|
+
* Create a new Transportr instance with the provided location or origin and context path.
|
|
1687
|
+
*
|
|
1688
|
+
* @param {URL | string | RequestOptions} [url = location.origin] The URL for {@link fetch} requests.
|
|
1689
|
+
* @param {RequestOptions} [options = Transportr.#defaultRequestOptions] The default {@link RequestOptions} for this instance.
|
|
1690
|
+
*/
|
|
578
1691
|
constructor(url = location.origin, options = __privateGet(_Transportr, _defaultRequestOptions)) {
|
|
1692
|
+
/**
|
|
1693
|
+
* Makes a GET request to the given path, using the given options, and then calls the
|
|
1694
|
+
* given response handler with the response.
|
|
1695
|
+
*
|
|
1696
|
+
* @private
|
|
1697
|
+
* @async
|
|
1698
|
+
* @param {string} path - The path to the endpoint you want to call.
|
|
1699
|
+
* @param {RequestOptions} options - The options for the request.
|
|
1700
|
+
* @param {ResponseHandler<ResponseBody>} responseHandler - A function that will be called with the response object.
|
|
1701
|
+
* @returns {Promise<ResponseBody>} The result of the #request method.
|
|
1702
|
+
*/
|
|
579
1703
|
__privateAdd(this, _get);
|
|
1704
|
+
/**
|
|
1705
|
+
* It takes a path, options, and a response handler, and returns a promise that resolves to the
|
|
1706
|
+
* response entity.
|
|
1707
|
+
*
|
|
1708
|
+
* @private
|
|
1709
|
+
* @async
|
|
1710
|
+
* @param {string} path - The path to the resource you want to access.
|
|
1711
|
+
* @param {RequestOptions} options - The options to use for the request.
|
|
1712
|
+
* @param {ResponseHandler<ResponseBody>} [responseHandler] - A function that will be called with the response body as a parameter. This
|
|
1713
|
+
* is useful if you want to do something with the response body before returning it.
|
|
1714
|
+
* @returns {Promise<ResponseBody>} The response from the API call.
|
|
1715
|
+
*/
|
|
580
1716
|
__privateAdd(this, _request);
|
|
1717
|
+
/** @type {URL} */
|
|
581
1718
|
__privateAdd(this, _baseUrl, void 0);
|
|
1719
|
+
/** @type {RequestOptions} */
|
|
582
1720
|
__privateAdd(this, _options, void 0);
|
|
583
1721
|
const type = object_type_default(url);
|
|
584
1722
|
if (type == Object) {
|
|
@@ -590,60 +1728,224 @@ var Transportr = (() => {
|
|
|
590
1728
|
__privateSet(this, _baseUrl, url);
|
|
591
1729
|
__privateSet(this, _options, options);
|
|
592
1730
|
}
|
|
1731
|
+
/**
|
|
1732
|
+
* It returns the base {@link URL} for the API.
|
|
1733
|
+
*
|
|
1734
|
+
* @returns {URL} The baseUrl property.
|
|
1735
|
+
*/
|
|
593
1736
|
get baseUrl() {
|
|
594
1737
|
return __privateGet(this, _baseUrl);
|
|
595
1738
|
}
|
|
1739
|
+
/**
|
|
1740
|
+
* This function returns a promise that resolves to the result of a request to the specified path with
|
|
1741
|
+
* the specified options, where the method is GET.
|
|
1742
|
+
*
|
|
1743
|
+
* @async
|
|
1744
|
+
* @param {string} path - The path to the resource you want to get.
|
|
1745
|
+
* @param {RequestOptions} [options={}] - The options for the request.
|
|
1746
|
+
* @returns {Promise<ResponseBody>} A promise that resolves to the response of the request.
|
|
1747
|
+
*/
|
|
596
1748
|
async get(path, options = {}) {
|
|
597
1749
|
return __privateMethod(this, _request, request_fn).call(this, path, object_merge_default(options, { method: http_request_methods_default.GET }));
|
|
598
1750
|
}
|
|
1751
|
+
/**
|
|
1752
|
+
* This function makes a POST request to the given path with the given body and options.
|
|
1753
|
+
*
|
|
1754
|
+
* @async
|
|
1755
|
+
* @param {string} path - The path to the endpoint you want to call.
|
|
1756
|
+
* @param {Object} body - The body of the request.
|
|
1757
|
+
* @param {RequestOptions} [options={}] - The options for the request.
|
|
1758
|
+
* @returns {Promise<ResponseBody>} A promise that resolves to the response body.
|
|
1759
|
+
*/
|
|
599
1760
|
async post(path, body, options = {}) {
|
|
600
1761
|
return __privateMethod(this, _request, request_fn).call(this, path, object_merge_default(options, { body, method: http_request_methods_default.POST }));
|
|
601
1762
|
}
|
|
1763
|
+
/**
|
|
1764
|
+
* This function returns a promise that resolves to the result of a request to the specified path with
|
|
1765
|
+
* the specified options, where the method is PUT.
|
|
1766
|
+
*
|
|
1767
|
+
* @async
|
|
1768
|
+
* @param {string} path - The path to the endpoint you want to call.
|
|
1769
|
+
* @param {RequestOptions} [options={}] - The options for the request.
|
|
1770
|
+
* @returns {Promise<ResponseBody>} The return value of the #request method.
|
|
1771
|
+
*/
|
|
602
1772
|
async put(path, options = {}) {
|
|
603
1773
|
return __privateMethod(this, _request, request_fn).call(this, path, object_merge_default(options, { method: http_request_methods_default.PUT }));
|
|
604
1774
|
}
|
|
1775
|
+
/**
|
|
1776
|
+
* It takes a path and options, and returns a request with the method set to PATCH.
|
|
1777
|
+
*
|
|
1778
|
+
* @async
|
|
1779
|
+
* @param {string} path - The path to the endpoint you want to hit.
|
|
1780
|
+
* @param {RequestOptions} [options={}] - The options for the request.
|
|
1781
|
+
* @returns {Promise<ResponseBody>} A promise that resolves to the response of the request.
|
|
1782
|
+
*/
|
|
605
1783
|
async patch(path, options = {}) {
|
|
606
1784
|
return __privateMethod(this, _request, request_fn).call(this, path, object_merge_default(options, { method: http_request_methods_default.PATCH }));
|
|
607
1785
|
}
|
|
1786
|
+
/**
|
|
1787
|
+
* It takes a path and options, and returns a request with the method set to DELETE.
|
|
1788
|
+
*
|
|
1789
|
+
* @async
|
|
1790
|
+
* @param {string} path - The path to the resource you want to access.
|
|
1791
|
+
* @param {RequestOptions} [options={}] - The options for the request.
|
|
1792
|
+
* @returns {Promise<ResponseBody>} The result of the request.
|
|
1793
|
+
*/
|
|
608
1794
|
async delete(path, options = {}) {
|
|
609
1795
|
return __privateMethod(this, _request, request_fn).call(this, path, object_merge_default(options, { method: http_request_methods_default.DELETE }));
|
|
610
1796
|
}
|
|
1797
|
+
/**
|
|
1798
|
+
* Returns the response headers of a request to the given path.
|
|
1799
|
+
*
|
|
1800
|
+
* @async
|
|
1801
|
+
* @param {string} path - The path to the resource you want to access.
|
|
1802
|
+
* @param {RequestOptions} [options={}] - The options for the request.
|
|
1803
|
+
* @returns {Promise<ResponseBody>} A promise that resolves to the response object.
|
|
1804
|
+
*/
|
|
611
1805
|
async head(path, options = {}) {
|
|
612
1806
|
return __privateMethod(this, _request, request_fn).call(this, path, object_merge_default(options, { method: http_request_methods_default.HEAD }));
|
|
613
1807
|
}
|
|
1808
|
+
/**
|
|
1809
|
+
* It takes a path and options, and returns a request with the method set to OPTIONS.
|
|
1810
|
+
*
|
|
1811
|
+
* @async
|
|
1812
|
+
* @param {string} path - The path to the resource.
|
|
1813
|
+
* @param {RequestOptions} [options={}] - The options for the request.
|
|
1814
|
+
* @returns {Promise<ResponseBody>} The return value of the #request method.
|
|
1815
|
+
*/
|
|
614
1816
|
async options(path, options = {}) {
|
|
615
1817
|
return __privateMethod(this, _request, request_fn).call(this, path, object_merge_default(options, { method: http_request_methods_default.OPTIONS }));
|
|
616
1818
|
}
|
|
1819
|
+
/**
|
|
1820
|
+
* It takes a path and options, and makes a request to the server.
|
|
1821
|
+
*
|
|
1822
|
+
* @async
|
|
1823
|
+
* @param {string} path - The path to the endpoint you want to hit.
|
|
1824
|
+
* @param {RequestOptions} [options={}] - The options for the request.
|
|
1825
|
+
* @returns {Promise<ResponseBody>} The return value of the function is the return value of the function that is passed to the `then` method of the promise returned by the `fetch` method.
|
|
1826
|
+
*/
|
|
617
1827
|
async request(path, options = {}) {
|
|
618
1828
|
return __privateMethod(this, _request, request_fn).call(this, path, options);
|
|
619
1829
|
}
|
|
1830
|
+
/**
|
|
1831
|
+
* It gets a JSON resource from the server.
|
|
1832
|
+
*
|
|
1833
|
+
* @async
|
|
1834
|
+
* @param {string} path - The path to the resource.
|
|
1835
|
+
* @param {RequestOptions} [options={}] - The options object to pass to the request.
|
|
1836
|
+
* @returns {Promise<JsonObject>} A promise that resolves to the response body as a JSON object.
|
|
1837
|
+
*/
|
|
620
1838
|
async getJson(path, options = {}) {
|
|
621
1839
|
return __privateMethod(this, _get, get_fn).call(this, path, object_merge_default(options, { headers: { [http_request_headers_default.ACCEPT]: _Transportr.MediaType.JSON } }), _handleJson);
|
|
622
1840
|
}
|
|
1841
|
+
/**
|
|
1842
|
+
* It gets the XML representation of the resource at the given path.
|
|
1843
|
+
*
|
|
1844
|
+
* @async
|
|
1845
|
+
* @param {string} path - The path to the resource you want to get.
|
|
1846
|
+
* @param {RequestOptions} [options={}] - The options for the request.
|
|
1847
|
+
* @returns {Promise<Document>} The result of the function call to #get.
|
|
1848
|
+
*/
|
|
623
1849
|
async getXml(path, options = {}) {
|
|
624
1850
|
return await __privateMethod(this, _get, get_fn).call(this, path, object_merge_default(options, { headers: { [http_request_headers_default.ACCEPT]: _Transportr.MediaType.XML } }), _handleXml);
|
|
625
1851
|
}
|
|
1852
|
+
/**
|
|
1853
|
+
* TODO - Add way to return portion of the retrieved HTML using a selector. Like jQuery.
|
|
1854
|
+
*
|
|
1855
|
+
* @async
|
|
1856
|
+
* @param {string} path
|
|
1857
|
+
* @param {RequestOptions} [options = {}]
|
|
1858
|
+
* @returns {Promise<Document>}
|
|
1859
|
+
*/
|
|
1860
|
+
/**
|
|
1861
|
+
* Get the HTML content of the specified path.
|
|
1862
|
+
*
|
|
1863
|
+
* @todo Add way to return portion of the retrieved HTML using a selector. Like jQuery.
|
|
1864
|
+
* @async
|
|
1865
|
+
* @param {string} path - The path to the resource.
|
|
1866
|
+
* @param {RequestOptions} [options={}] - The options for the request.
|
|
1867
|
+
* @returns {Promise<Document>} The return value of the function is the return value of the function passed to the `then`
|
|
1868
|
+
* method of the promise returned by the `#get` method.
|
|
1869
|
+
*/
|
|
626
1870
|
async getHtml(path, options = {}) {
|
|
627
1871
|
return __privateMethod(this, _get, get_fn).call(this, path, object_merge_default(options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.HTML } }), _handleHtml);
|
|
628
1872
|
}
|
|
1873
|
+
/**
|
|
1874
|
+
* It returns a promise that resolves to the HTML fragment at the given path.
|
|
1875
|
+
*
|
|
1876
|
+
* @todo - Add way to return portion of the retrieved HTML using a selector. Like jQuery.
|
|
1877
|
+
* @async
|
|
1878
|
+
* @param {string} path - The path to the resource.
|
|
1879
|
+
* @param {RequestOptions} [options={}] - The options for the request.
|
|
1880
|
+
* @returns {Promise<DocumentFragment>} A promise that resolves to an HTML fragment.
|
|
1881
|
+
*/
|
|
629
1882
|
async getHtmlFragment(path, options = {}) {
|
|
630
1883
|
return __privateMethod(this, _get, get_fn).call(this, path, object_merge_default(options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.HTML } }), _handleHtmlFragment);
|
|
631
1884
|
}
|
|
1885
|
+
/**
|
|
1886
|
+
* It gets a script from the server, and appends the script to the {@link Document} {@link HTMLHeadElement}
|
|
1887
|
+
* CORS is enabled by default.
|
|
1888
|
+
*
|
|
1889
|
+
* @async
|
|
1890
|
+
* @param {string} path - The path to the script.
|
|
1891
|
+
* @param {RequestOptions} [options={}] - The options for the request.
|
|
1892
|
+
* @returns {Promise<void>} A promise that has been resolved.
|
|
1893
|
+
*/
|
|
632
1894
|
async getScript(path, options = {}) {
|
|
633
1895
|
return __privateMethod(this, _get, get_fn).call(this, path, object_merge_default(options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.JAVA_SCRIPT } }), _handleScript);
|
|
634
1896
|
}
|
|
1897
|
+
/**
|
|
1898
|
+
* Gets a stylesheet from the server, and adds it as a {@link Blob} {@link URL}.
|
|
1899
|
+
*
|
|
1900
|
+
* @async
|
|
1901
|
+
* @param {string} path - The path to the stylesheet.
|
|
1902
|
+
* @param {RequestOptions} [options={}] - The options for the request.
|
|
1903
|
+
* @returns {Promise<void>} A promise that has been resolved.
|
|
1904
|
+
*/
|
|
635
1905
|
async getStylesheet(path, options = {}) {
|
|
636
1906
|
return __privateMethod(this, _get, get_fn).call(this, path, object_merge_default(options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.CSS } }), _handleCss);
|
|
637
1907
|
}
|
|
1908
|
+
/**
|
|
1909
|
+
* It returns a blob from the specified path.
|
|
1910
|
+
*
|
|
1911
|
+
* @async
|
|
1912
|
+
* @param {string} path - The path to the resource.
|
|
1913
|
+
* @param {RequestOptions} [options={}] - The options for the request.
|
|
1914
|
+
* @returns {Promise<Blob>} A promise that resolves to a blob.
|
|
1915
|
+
*/
|
|
638
1916
|
async getBlob(path, options = {}) {
|
|
639
1917
|
return await __privateMethod(this, _get, get_fn).call(this, path, object_merge_default(options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.BIN } }), _handleBlob);
|
|
640
1918
|
}
|
|
1919
|
+
/**
|
|
1920
|
+
* It returns a promise that resolves to an object URL.
|
|
1921
|
+
*
|
|
1922
|
+
* @async
|
|
1923
|
+
* @param {string} path - The path to the resource.
|
|
1924
|
+
* @param {RequestOptions} [options={}] - The options for the request.
|
|
1925
|
+
* @returns {Promise<string>} A promise that resolves to an object URL.
|
|
1926
|
+
*/
|
|
641
1927
|
async getImage(path, options = {}) {
|
|
642
|
-
return await __privateMethod(this, _get, get_fn).call(this, path, object_merge_default(options, { headers: { [http_request_headers_default.ACCEPT]: "image/*" } }),
|
|
643
|
-
}
|
|
1928
|
+
return await __privateMethod(this, _get, get_fn).call(this, path, object_merge_default(options, { headers: { [http_request_headers_default.ACCEPT]: "image/*" } }), _handleImage);
|
|
1929
|
+
}
|
|
1930
|
+
/**
|
|
1931
|
+
* It gets a buffer from the specified path
|
|
1932
|
+
*
|
|
1933
|
+
* @async
|
|
1934
|
+
* @param {string} path - The path to the resource.
|
|
1935
|
+
* @param {RequestOptions} [options={}] - The options for the request.
|
|
1936
|
+
* @returns {Promise<ArrayBuffer>} A promise that resolves to a buffer.
|
|
1937
|
+
*/
|
|
644
1938
|
async getBuffer(path, options = {}) {
|
|
645
1939
|
return await __privateMethod(this, _get, get_fn).call(this, path, object_merge_default(options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.BIN } }), _handleBuffer);
|
|
646
1940
|
}
|
|
1941
|
+
/**
|
|
1942
|
+
* It returns a readable stream of the response body from the specified path.
|
|
1943
|
+
*
|
|
1944
|
+
* @async
|
|
1945
|
+
* @param {string} path - The path to the resource.
|
|
1946
|
+
* @param {RequestOptions} [options={}] - The options for the request.
|
|
1947
|
+
* @returns {Promise<ReadableStream<Uint8Array>>} A readable stream.
|
|
1948
|
+
*/
|
|
647
1949
|
async getStream(path, options = {}) {
|
|
648
1950
|
return await __privateMethod(this, _get, get_fn).call(this, path, object_merge_default(options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.BIN } }), _handleReadableStream);
|
|
649
1951
|
}
|
|
@@ -652,73 +1954,112 @@ var Transportr = (() => {
|
|
|
652
1954
|
_baseUrl = new WeakMap();
|
|
653
1955
|
_options = new WeakMap();
|
|
654
1956
|
_contentTypeHandlers = new WeakMap();
|
|
655
|
-
_contentSubtypeHandlers = new WeakMap();
|
|
656
1957
|
_defaultRequestOptions = new WeakMap();
|
|
657
1958
|
_get = new WeakSet();
|
|
658
1959
|
get_fn = async function(path, options, responseHandler) {
|
|
659
1960
|
return __privateMethod(this, _request, request_fn).call(this, path, object_merge_default(options, { method: _Transportr.Method.GET }), responseHandler);
|
|
660
1961
|
};
|
|
1962
|
+
_createUrl = new WeakSet();
|
|
1963
|
+
createUrl_fn = function(url, path, searchParams = new URLSearchParams()) {
|
|
1964
|
+
url = path.startsWith("/") ? new URL(`${url.pathname.replace(endsWithSlashRegEx, "")}${path}`, url.origin) : new URL(path);
|
|
1965
|
+
for (const [name, value] of searchParams) {
|
|
1966
|
+
url.searchParams.append(name, value);
|
|
1967
|
+
}
|
|
1968
|
+
return url;
|
|
1969
|
+
};
|
|
661
1970
|
_request = new WeakSet();
|
|
662
1971
|
request_fn = async function(path, options, responseHandler) {
|
|
663
|
-
var _a, _b;
|
|
1972
|
+
var _a, _b, _c, _d;
|
|
664
1973
|
const requestOptions = object_merge_default(__privateGet(this, _options), options);
|
|
665
1974
|
const headers = new Headers(requestOptions.headers);
|
|
666
1975
|
const errorMessage = `An error has occurred with your Request: ${path}`;
|
|
667
|
-
if (
|
|
1976
|
+
if (__privateMethod(_a = _Transportr, _needsSerialization, needsSerialization_fn).call(_a, options.method, headers)) {
|
|
668
1977
|
requestOptions.body = JSON.stringify(requestOptions.body);
|
|
669
1978
|
}
|
|
1979
|
+
if (requestOptions.searchParams && !(requestOptions.searchParams instanceof URLSearchParams)) {
|
|
1980
|
+
requestOptions.searchParams = new URLSearchParams(requestOptions.searchParams);
|
|
1981
|
+
}
|
|
670
1982
|
let response;
|
|
671
1983
|
try {
|
|
672
|
-
response = await fetch(__privateMethod(
|
|
1984
|
+
response = await fetch(__privateMethod(_b = _Transportr, _createUrl, createUrl_fn).call(_b, __privateGet(this, _baseUrl), path, requestOptions.searchParams), requestOptions);
|
|
673
1985
|
} catch (error) {
|
|
674
1986
|
console.error(errorMessage, error);
|
|
675
|
-
throw new
|
|
1987
|
+
throw new http_error_default(errorMessage, { cause: error, status: new ResponseStatus(response.status, response.statusText) });
|
|
676
1988
|
}
|
|
677
1989
|
if (!response.ok) {
|
|
678
|
-
throw new
|
|
679
|
-
}
|
|
680
|
-
try {
|
|
681
|
-
return await (responseHandler ? responseHandler(response) : __privateMethod(_b = _Transportr, _processResponse, processResponse_fn).call(_b, response));
|
|
682
|
-
} catch (error) {
|
|
683
|
-
console.error(errorMessage, error);
|
|
684
|
-
throw new HttpError(errorMessage);
|
|
1990
|
+
throw new http_error_default(errorMessage, { status: new ResponseStatus(response.status, response.statusText), entity: await __privateMethod(_c = _Transportr, _processResponse, processResponse_fn).call(_c, response) });
|
|
685
1991
|
}
|
|
686
|
-
|
|
687
|
-
_createUrl = new WeakSet();
|
|
688
|
-
createUrl_fn = function(url, path, searchParams = {}) {
|
|
689
|
-
url = path.startsWith("/") ? new URL(`${url.pathname.replace(endsWithSlashRegEx, "")}${path}`, url.origin) : new URL(path);
|
|
690
|
-
for (const [name, value] of Object.entries(searchParams)) {
|
|
691
|
-
if (Array.isArray(value)) {
|
|
692
|
-
value.forEach((v) => url.searchParams.set(name, v));
|
|
693
|
-
} else {
|
|
694
|
-
url.searchParams.append(name, value);
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
return url;
|
|
1992
|
+
return await __privateMethod(_d = _Transportr, _processResponse, processResponse_fn).call(_d, response, responseHandler);
|
|
698
1993
|
};
|
|
699
1994
|
_processResponse = new WeakSet();
|
|
700
|
-
processResponse_fn = async function(response) {
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
1995
|
+
processResponse_fn = async function(response, handler) {
|
|
1996
|
+
try {
|
|
1997
|
+
if (!handler) {
|
|
1998
|
+
const mediaType = new MediaType(response.headers.get(http_response_headers_default.CONTENT_TYPE));
|
|
1999
|
+
if (mediaType) {
|
|
2000
|
+
for (const [responseHandler, contentTypes] of __privateGet(_Transportr, _contentTypeHandlers)) {
|
|
2001
|
+
if (contentTypes.has(mediaType.type) || contentTypes.has(mediaType.subtype)) {
|
|
2002
|
+
handler = responseHandler;
|
|
2003
|
+
break;
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
710
2007
|
}
|
|
2008
|
+
return (handler ?? _handleText)(response);
|
|
2009
|
+
} catch (error) {
|
|
2010
|
+
const errorMessage = "Unable to process response.";
|
|
2011
|
+
console.error(errorMessage, error, response);
|
|
2012
|
+
throw new http_error_default(errorMessage, { cause: error });
|
|
711
2013
|
}
|
|
712
|
-
console.warn("Unable to process response. Unknown content-type or no response handler defined.");
|
|
713
|
-
return response;
|
|
714
2014
|
};
|
|
2015
|
+
_needsSerialization = new WeakSet();
|
|
2016
|
+
needsSerialization_fn = function(method, headers) {
|
|
2017
|
+
return [http_request_methods_default.POST, http_request_methods_default.PUT, http_request_methods_default.PATCH].includes(method) && headers.get(_Transportr.RequestHeader.CONTENT_TYPE) == _Transportr.MediaType.JSON;
|
|
2018
|
+
};
|
|
2019
|
+
/**
|
|
2020
|
+
* It takes a URL, a path, and a set of search parameters, and returns a new URL with the path and
|
|
2021
|
+
* search parameters applied.
|
|
2022
|
+
*
|
|
2023
|
+
* @private
|
|
2024
|
+
* @static
|
|
2025
|
+
* @param {URL} url - The URL to use as a base.
|
|
2026
|
+
* @param {string} path - The path to the resource. This can be a relative path or a full URL.
|
|
2027
|
+
* @param {URLSearchParams} [searchParams=new URLSearchParams()] - An object containing the query parameters to be added to the URL.
|
|
2028
|
+
* @returns {URL} A new URL object with the pathname and origin of the url parameter, and the path parameter
|
|
2029
|
+
* appended to the end of the pathname.
|
|
2030
|
+
*/
|
|
715
2031
|
__privateAdd(Transportr, _createUrl);
|
|
2032
|
+
/**
|
|
2033
|
+
* It takes a response and a handler, and if the handler is not defined, it tries to find a handler
|
|
2034
|
+
* based on the response's content type
|
|
2035
|
+
*
|
|
2036
|
+
* @private
|
|
2037
|
+
* @static
|
|
2038
|
+
* @async
|
|
2039
|
+
* @param {Response} response - The response object returned by the fetch API.
|
|
2040
|
+
* @param {ResponseHandler<ResponseBody>} [handler] - The handler to use for processing the response.
|
|
2041
|
+
* @returns {Promise<ResponseBody>} The response is being returned.
|
|
2042
|
+
*/
|
|
716
2043
|
__privateAdd(Transportr, _processResponse);
|
|
2044
|
+
/**
|
|
2045
|
+
* If the request method is POST, PUT, or PATCH, and the content type is JSON, then the request body
|
|
2046
|
+
* needs to be serialized.
|
|
2047
|
+
*
|
|
2048
|
+
* @private
|
|
2049
|
+
* @static
|
|
2050
|
+
* @param {RequestMethod} method - The HTTP request method.
|
|
2051
|
+
* @param {RequestHeaders} headers - The headers of the request.
|
|
2052
|
+
* @returns {boolean} `true` if the request body needs to be serialized, `false` otherwise.
|
|
2053
|
+
*/
|
|
2054
|
+
__privateAdd(Transportr, _needsSerialization);
|
|
2055
|
+
/**
|
|
2056
|
+
* @private
|
|
2057
|
+
* @static
|
|
2058
|
+
* @type {SetMultiMap<ResponseHandler<ResponseBody>, string>}
|
|
2059
|
+
*/
|
|
717
2060
|
__privateAdd(Transportr, _contentTypeHandlers, new SetMultiMap([
|
|
718
2061
|
[_handleImage, new MediaType(http_media_type_default.PNG).type],
|
|
719
|
-
[_handleText, new MediaType(http_media_type_default.TEXT).type]
|
|
720
|
-
]));
|
|
721
|
-
__privateAdd(Transportr, _contentSubtypeHandlers, new SetMultiMap([
|
|
2062
|
+
[_handleText, new MediaType(http_media_type_default.TEXT).type],
|
|
722
2063
|
[_handleJson, new MediaType(http_media_type_default.JSON).subtype],
|
|
723
2064
|
[_handleHtml, new MediaType(http_media_type_default.HTML).subtype],
|
|
724
2065
|
[_handleScript, new MediaType(http_media_type_default.JAVA_SCRIPT).subtype],
|
|
@@ -726,10 +2067,30 @@ var Transportr = (() => {
|
|
|
726
2067
|
[_handleXml, new MediaType(http_media_type_default.XML).subtype],
|
|
727
2068
|
[_handleReadableStream, new MediaType(http_media_type_default.BIN).subtype]
|
|
728
2069
|
]));
|
|
2070
|
+
/**
|
|
2071
|
+
* @static
|
|
2072
|
+
* @constant {Object<string, RequestMethod>}
|
|
2073
|
+
*/
|
|
729
2074
|
__publicField(Transportr, "Method", Object.freeze(http_request_methods_default));
|
|
2075
|
+
/**
|
|
2076
|
+
* @static
|
|
2077
|
+
* @constant {Object<string, string>}
|
|
2078
|
+
*/
|
|
730
2079
|
__publicField(Transportr, "MediaType", http_media_type_default);
|
|
2080
|
+
/**
|
|
2081
|
+
* @static
|
|
2082
|
+
* @constant {Object<string, string>}
|
|
2083
|
+
*/
|
|
731
2084
|
__publicField(Transportr, "RequestHeader", http_request_headers_default);
|
|
2085
|
+
/**
|
|
2086
|
+
* @static
|
|
2087
|
+
* @constant {Object<string, string>}
|
|
2088
|
+
*/
|
|
732
2089
|
__publicField(Transportr, "ResponseHeader", Object.freeze(http_response_headers_default));
|
|
2090
|
+
/**
|
|
2091
|
+
* @static
|
|
2092
|
+
* @constant {Object<string, RequestCache>}
|
|
2093
|
+
*/
|
|
733
2094
|
__publicField(Transportr, "CachingPolicy", {
|
|
734
2095
|
DEFAULT: "default",
|
|
735
2096
|
FORCE_CACHE: "force-cache",
|
|
@@ -738,22 +2099,38 @@ var Transportr = (() => {
|
|
|
738
2099
|
ONLY_IF_CACHED: "only-if-cached",
|
|
739
2100
|
RELOAD: "reload"
|
|
740
2101
|
});
|
|
2102
|
+
/**
|
|
2103
|
+
* @static
|
|
2104
|
+
* @constant {Object<string, RequestCredentials>}
|
|
2105
|
+
*/
|
|
741
2106
|
__publicField(Transportr, "CredentialsPolicy", {
|
|
742
2107
|
INCLUDE: "include",
|
|
743
2108
|
OMIT: "omit",
|
|
744
2109
|
SAME_ORIGIN: "same-origin"
|
|
745
2110
|
});
|
|
2111
|
+
/**
|
|
2112
|
+
* @static
|
|
2113
|
+
* @constant {Object<string, RequestMode>}
|
|
2114
|
+
*/
|
|
746
2115
|
__publicField(Transportr, "RequestMode", {
|
|
747
2116
|
CORS: "cors",
|
|
748
2117
|
NAVIGATE: "navigate",
|
|
749
2118
|
NO_CORS: "no-cors",
|
|
750
2119
|
SAME_ORIGIN: "same-origin"
|
|
751
2120
|
});
|
|
2121
|
+
/**
|
|
2122
|
+
* @static
|
|
2123
|
+
* @constant {Object<string, RequestRedirect>}
|
|
2124
|
+
*/
|
|
752
2125
|
__publicField(Transportr, "RedirectPolicy", {
|
|
753
2126
|
ERROR: "error",
|
|
754
2127
|
FOLLOW: "follow",
|
|
755
2128
|
MANUAL: "manual"
|
|
756
2129
|
});
|
|
2130
|
+
/**
|
|
2131
|
+
* @static
|
|
2132
|
+
* @constant {Object<string, ReferrerPolicy>}
|
|
2133
|
+
*/
|
|
757
2134
|
__publicField(Transportr, "ReferrerPolicy", {
|
|
758
2135
|
NO_REFERRER: "no-referrer",
|
|
759
2136
|
NO_REFERRER_WHEN_DOWNGRADE: "no-referrer-when-downgrade",
|
|
@@ -764,6 +2141,10 @@ var Transportr = (() => {
|
|
|
764
2141
|
STRICT_ORIGIN_WHEN_CROSS_ORIGIN: "strict-origin-when-cross-origin",
|
|
765
2142
|
UNSAFE_URL: "unsafe-url"
|
|
766
2143
|
});
|
|
2144
|
+
/**
|
|
2145
|
+
* @static
|
|
2146
|
+
* @type {RequestOptions}
|
|
2147
|
+
*/
|
|
767
2148
|
__privateAdd(Transportr, _defaultRequestOptions, {
|
|
768
2149
|
body: null,
|
|
769
2150
|
cache: _Transportr.CachingPolicy.NO_STORE,
|