Back to 100%
This commit is contained in:
parent
4a153ff004
commit
0f7e6c15d3
|
@ -149,7 +149,7 @@ export default class Body {
|
|||
return Body.Promise.resolve(this.body);
|
||||
}
|
||||
|
||||
// should never happen
|
||||
// istanbul ignore if: should never happen
|
||||
if (!bodyStream(this.body)) {
|
||||
return Body.Promise.resolve(new Buffer(0));
|
||||
}
|
||||
|
@ -306,6 +306,8 @@ export function clone(instance) {
|
|||
export function extractContentType(instance) {
|
||||
const {body} = instance;
|
||||
|
||||
// istanbul ignore if: Currently, because of a guard in Request, body
|
||||
// can never be null. Included here for completeness.
|
||||
if (body === null) {
|
||||
// body is null
|
||||
return null;
|
||||
|
@ -375,12 +377,9 @@ export function writeToStream(dest, instance) {
|
|||
// body is buffer
|
||||
dest.write(body);
|
||||
dest.end()
|
||||
} else if (bodyStream(body)) {
|
||||
} else {
|
||||
// body is stream
|
||||
body.pipe(dest);
|
||||
} else {
|
||||
// should never happen
|
||||
dest.end();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
43
test/test.js
43
test/test.js
|
@ -719,6 +719,42 @@ describe(`node-fetch with FOLLOW_SPEC = ${defaultFollowSpec}`, () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should allow POST request with blob body without type', function() {
|
||||
url = `${base}inspect`;
|
||||
opts = {
|
||||
method: 'POST'
|
||||
, body: new Blob(['a=1'])
|
||||
};
|
||||
return fetch(url, opts).then(res => {
|
||||
return res.json();
|
||||
}).then(res => {
|
||||
expect(res.method).to.equal('POST');
|
||||
expect(res.body).to.equal('a=1');
|
||||
expect(res.headers['transfer-encoding']).to.be.undefined;
|
||||
expect(res.headers['content-type']).to.be.undefined;
|
||||
expect(res.headers['content-length']).to.equal('3');
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow POST request with blob body with type', function() {
|
||||
url = `${base}inspect`;
|
||||
opts = {
|
||||
method: 'POST',
|
||||
body: new Blob(['a=1'], {
|
||||
type: 'text/plain;charset=UTF-8'
|
||||
})
|
||||
};
|
||||
return fetch(url, opts).then(res => {
|
||||
return res.json();
|
||||
}).then(res => {
|
||||
expect(res.method).to.equal('POST');
|
||||
expect(res.body).to.equal('a=1');
|
||||
expect(res.headers['transfer-encoding']).to.be.undefined;
|
||||
expect(res.headers['content-type']).to.equal('text/plain;charset=utf-8');
|
||||
expect(res.headers['content-length']).to.equal('3');
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow POST request with readable stream as body', function() {
|
||||
let body = resumer().queue('a=1').end();
|
||||
body = body.pipe(new stream.PassThrough());
|
||||
|
@ -1628,6 +1664,13 @@ describe(`node-fetch with FOLLOW_SPEC = ${defaultFollowSpec}`, () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should support blob as body in Response constructor', function() {
|
||||
const res = new Response(new Blob(['a=1']));
|
||||
return res.text().then(result => {
|
||||
expect(result).to.equal('a=1');
|
||||
});
|
||||
});
|
||||
|
||||
it('should default to null as body', function() {
|
||||
const res = new Response();
|
||||
expect(res.body).to.equal(null);
|
||||
|
|
Loading…
Reference in New Issue