mirror of
https://github.com/JonasunderscoreJones/api-worker.git
synced 2025-10-23 10:29:19 +02:00
Initial commit (by create-cloudflare CLI)
This commit is contained in:
commit
58a42872a0
1745 changed files with 741893 additions and 0 deletions
77
node_modules/mimic-response/index.js
generated
vendored
Normal file
77
node_modules/mimic-response/index.js
generated
vendored
Normal file
|
@ -0,0 +1,77 @@
|
|||
'use strict';
|
||||
|
||||
// We define these manually to ensure they're always copied
|
||||
// even if they would move up the prototype chain
|
||||
// https://nodejs.org/api/http.html#http_class_http_incomingmessage
|
||||
const knownProperties = [
|
||||
'aborted',
|
||||
'complete',
|
||||
'headers',
|
||||
'httpVersion',
|
||||
'httpVersionMinor',
|
||||
'httpVersionMajor',
|
||||
'method',
|
||||
'rawHeaders',
|
||||
'rawTrailers',
|
||||
'setTimeout',
|
||||
'socket',
|
||||
'statusCode',
|
||||
'statusMessage',
|
||||
'trailers',
|
||||
'url'
|
||||
];
|
||||
|
||||
module.exports = (fromStream, toStream) => {
|
||||
if (toStream._readableState.autoDestroy) {
|
||||
throw new Error('The second stream must have the `autoDestroy` option set to `false`');
|
||||
}
|
||||
|
||||
const fromProperties = new Set(Object.keys(fromStream).concat(knownProperties));
|
||||
|
||||
const properties = {};
|
||||
|
||||
for (const property of fromProperties) {
|
||||
// Don't overwrite existing properties.
|
||||
if (property in toStream) {
|
||||
continue;
|
||||
}
|
||||
|
||||
properties[property] = {
|
||||
get() {
|
||||
const value = fromStream[property];
|
||||
const isFunction = typeof value === 'function';
|
||||
|
||||
return isFunction ? value.bind(fromStream) : value;
|
||||
},
|
||||
set(value) {
|
||||
fromStream[property] = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: false
|
||||
};
|
||||
}
|
||||
|
||||
Object.defineProperties(toStream, properties);
|
||||
|
||||
fromStream.once('aborted', () => {
|
||||
toStream.destroy();
|
||||
|
||||
toStream.emit('aborted');
|
||||
});
|
||||
|
||||
fromStream.once('close', () => {
|
||||
if (fromStream.complete) {
|
||||
if (toStream.readable) {
|
||||
toStream.once('end', () => {
|
||||
toStream.emit('close');
|
||||
});
|
||||
} else {
|
||||
toStream.emit('close');
|
||||
}
|
||||
} else {
|
||||
toStream.emit('close');
|
||||
}
|
||||
});
|
||||
|
||||
return toStream;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue