feat(Xapi#putResource): accept buffers
This commit is contained in:
parent
69c48e2770
commit
8fe3b1a368
@ -37,14 +37,14 @@
|
|||||||
"debug": "^2.6.8",
|
"debug": "^2.6.8",
|
||||||
"event-to-promise": "^0.8.0",
|
"event-to-promise": "^0.8.0",
|
||||||
"exec-promise": "^0.7.0",
|
"exec-promise": "^0.7.0",
|
||||||
"http-request-plus": "^0.1.4",
|
"http-request-plus": "^0.1.5",
|
||||||
"json-rpc-protocol": "^0.11.2",
|
"json-rpc-protocol": "^0.11.2",
|
||||||
"kindof": "^2.0.0",
|
"kindof": "^2.0.0",
|
||||||
"lodash": "^4.17.4",
|
"lodash": "^4.17.4",
|
||||||
"make-error": "^1.3.0",
|
"make-error": "^1.3.0",
|
||||||
"minimist": "^1.2.0",
|
"minimist": "^1.2.0",
|
||||||
"ms": "^2.0.0",
|
"ms": "^2.0.0",
|
||||||
"promise-toolbox": "^0.8.2",
|
"promise-toolbox": "^0.9.1",
|
||||||
"pw": "0.0.4",
|
"pw": "0.0.4",
|
||||||
"xmlrpc": "^1.3.2",
|
"xmlrpc": "^1.3.2",
|
||||||
"xo-collection": "^0.4.1"
|
"xo-collection": "^0.4.1"
|
||||||
|
@ -8,7 +8,6 @@ import { EventEmitter } from 'events'
|
|||||||
import { filter, forEach, isArray, isObject, map, noop, reduce, startsWith } from 'lodash'
|
import { filter, forEach, isArray, isObject, map, noop, reduce, startsWith } from 'lodash'
|
||||||
import {
|
import {
|
||||||
cancelable,
|
cancelable,
|
||||||
CancelToken,
|
|
||||||
catchPlus as pCatch,
|
catchPlus as pCatch,
|
||||||
delay as pDelay
|
delay as pDelay
|
||||||
} from 'promise-toolbox'
|
} from 'promise-toolbox'
|
||||||
@ -332,24 +331,23 @@ export class Xapi extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@cancelable
|
@cancelable
|
||||||
putResource ($cancelToken, stream, pathname, {
|
putResource ($cancelToken, body, pathname, {
|
||||||
host,
|
host,
|
||||||
query
|
query
|
||||||
} = {}) {
|
} = {}) {
|
||||||
const headers = {}
|
const headers = {}
|
||||||
|
|
||||||
// Xen API does not support chunk encoding.
|
// Xen API does not support chunk encoding.
|
||||||
const { length } = stream
|
const { length } = body
|
||||||
if (length === undefined) {
|
if (length === undefined && typeof body.pipe === 'function') {
|
||||||
// add a fake huge content length (1 PiB)
|
// add a fake huge content length (1 PiB)
|
||||||
headers['content-length'] = '1125899906842624'
|
headers['content-length'] = '1125899906842624'
|
||||||
|
|
||||||
const { cancel, token } = CancelToken.source()
|
|
||||||
$cancelToken = CancelToken.race([ $cancelToken, token ])
|
|
||||||
|
|
||||||
// when the data has been emitted, close the connection
|
// when the data has been emitted, close the connection
|
||||||
stream.on('end', () => {
|
$cancelToken = $cancelToken.fork(cancel => {
|
||||||
setTimeout(cancel, 1e3)
|
body.on('end', () => {
|
||||||
|
setTimeout(cancel, 1e3)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,7 +358,7 @@ export class Xapi extends EventEmitter {
|
|||||||
hostname: this.getObject(host).address
|
hostname: this.getObject(host).address
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
body: stream,
|
body,
|
||||||
headers,
|
headers,
|
||||||
path: pathname,
|
path: pathname,
|
||||||
query: {
|
query: {
|
||||||
|
@ -1897,13 +1897,13 @@ html-encoding-sniffer@^1.0.1:
|
|||||||
dependencies:
|
dependencies:
|
||||||
whatwg-encoding "^1.0.1"
|
whatwg-encoding "^1.0.1"
|
||||||
|
|
||||||
http-request-plus@^0.1.4:
|
http-request-plus@^0.1.5:
|
||||||
version "0.1.4"
|
version "0.1.5"
|
||||||
resolved "https://registry.yarnpkg.com/http-request-plus/-/http-request-plus-0.1.4.tgz#c99cd36366e96c13f92da5954b3a2fd2ce2c531e"
|
resolved "https://registry.yarnpkg.com/http-request-plus/-/http-request-plus-0.1.5.tgz#9aead8b230586397928ecbb9a6bed96a3bfe2210"
|
||||||
dependencies:
|
dependencies:
|
||||||
is-redirect "^1.0.0"
|
is-redirect "^1.0.0"
|
||||||
lodash "^4.17.4"
|
lodash "^4.17.4"
|
||||||
promise-toolbox "^0.8.2"
|
promise-toolbox "^0.9.1"
|
||||||
|
|
||||||
http-signature@~1.1.0:
|
http-signature@~1.1.0:
|
||||||
version "1.1.1"
|
version "1.1.1"
|
||||||
@ -2635,7 +2635,7 @@ lru-cache@^4.0.1:
|
|||||||
pseudomap "^1.0.1"
|
pseudomap "^1.0.1"
|
||||||
yallist "^2.0.0"
|
yallist "^2.0.0"
|
||||||
|
|
||||||
make-error@^1.0.2, make-error@^1.2.0, make-error@^1.2.2, make-error@^1.3.0:
|
make-error@^1.0.2, make-error@^1.2.0, make-error@^1.2.3, make-error@^1.3.0:
|
||||||
version "1.3.0"
|
version "1.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.0.tgz#52ad3a339ccf10ce62b4040b708fe707244b8b96"
|
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.0.tgz#52ad3a339ccf10ce62b4040b708fe707244b8b96"
|
||||||
|
|
||||||
@ -3010,11 +3010,11 @@ progress@^1.1.8:
|
|||||||
version "1.1.8"
|
version "1.1.8"
|
||||||
resolved "https://registry.yarnpkg.com/progress/-/progress-1.1.8.tgz#e260c78f6161cdd9b0e56cc3e0a85de17c7a57be"
|
resolved "https://registry.yarnpkg.com/progress/-/progress-1.1.8.tgz#e260c78f6161cdd9b0e56cc3e0a85de17c7a57be"
|
||||||
|
|
||||||
promise-toolbox@^0.8.2:
|
promise-toolbox@^0.9.1:
|
||||||
version "0.8.2"
|
version "0.9.1"
|
||||||
resolved "https://registry.yarnpkg.com/promise-toolbox/-/promise-toolbox-0.8.2.tgz#91722a364e6a2d6d13319491da3068b7de0b348f"
|
resolved "https://registry.yarnpkg.com/promise-toolbox/-/promise-toolbox-0.9.1.tgz#01ad022f7a1272f51049b9561ac522041360fc37"
|
||||||
dependencies:
|
dependencies:
|
||||||
make-error "^1.2.2"
|
make-error "^1.2.3"
|
||||||
|
|
||||||
prr@~0.0.0:
|
prr@~0.0.0:
|
||||||
version "0.0.0"
|
version "0.0.0"
|
||||||
|
Loading…
Reference in New Issue
Block a user