* @param {*} body * @returns {*}
(body)
| 32 | * @returns {*} |
| 33 | */ |
| 34 | function wrapRequestBody (body) { |
| 35 | if (isStream(body)) { |
| 36 | // TODO (fix): Provide some way for the user to cache the file to e.g. /tmp |
| 37 | // so that it can be dispatched again? |
| 38 | // TODO (fix): Do we need 100-expect support to provide a way to do this properly? |
| 39 | if (bodyLength(body) === 0) { |
| 40 | body |
| 41 | .on('data', function () { |
| 42 | assert(false) |
| 43 | }) |
| 44 | } |
| 45 | |
| 46 | if (typeof body.readableDidRead !== 'boolean') { |
| 47 | body[kBodyUsed] = false |
| 48 | EE.prototype.on.call(body, 'data', function () { |
| 49 | this[kBodyUsed] = true |
| 50 | }) |
| 51 | } |
| 52 | |
| 53 | return body |
| 54 | } else if (body && typeof body.pipeTo === 'function') { |
| 55 | // TODO (fix): We can't access ReadableStream internal state |
| 56 | // to determine whether or not it has been disturbed. This is just |
| 57 | // a workaround. |
| 58 | return new BodyAsyncIterable(body) |
| 59 | } else if (body && isFormDataLike(body)) { |
| 60 | return body |
| 61 | } else if ( |
| 62 | body && |
| 63 | typeof body !== 'string' && |
| 64 | !ArrayBuffer.isView(body) && |
| 65 | isIterable(body) |
| 66 | ) { |
| 67 | // TODO: Should we allow re-using iterable if !this.opts.idempotent |
| 68 | // or through some other flag? |
| 69 | return new BodyAsyncIterable(body) |
| 70 | } else { |
| 71 | return body |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * @param {*} obj |
no test coverage detected