Skip to content

Commit

Permalink
Node 12 compatibility (#614)
Browse files Browse the repository at this point in the history
* dev package bump
* test invalid header differently as node 12 no longer accepts invalid headers in response
* add node v10 in travis test list as node 12 has been released
  • Loading branch information
bitinn committed Apr 26, 2019
1 parent 432c9b0 commit 05f5ac1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 36 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -3,6 +3,7 @@ node_js:
- "4"
- "6"
- "8"
- "10"
- "node"
env:
- FORMDATA_VERSION=1.0.0
Expand Down
20 changes: 10 additions & 10 deletions package.json
Expand Up @@ -37,28 +37,28 @@
},
"homepage": "https://github.com/bitinn/node-fetch",
"devDependencies": {
"abort-controller": "^1.0.2",
"abortcontroller-polyfill": "^1.1.9",
"babel-core": "^6.26.0",
"babel-plugin-istanbul": "^4.1.5",
"abort-controller": "^1.1.0",
"abortcontroller-polyfill": "^1.3.0",
"babel-core": "^6.26.3",
"babel-plugin-istanbul": "^4.1.6",
"babel-preset-env": "^1.6.1",
"babel-register": "^6.16.3",
"chai": "^3.5.0",
"chai-as-promised": "^7.1.1",
"chai-iterator": "^1.1.1",
"chai-string": "~1.3.0",
"codecov": "^3.0.0",
"cross-env": "^5.1.3",
"form-data": "^2.3.1",
"codecov": "^3.3.0",
"cross-env": "^5.2.0",
"form-data": "^2.3.3",
"is-builtin-module": "^1.0.0",
"mocha": "^5.0.0",
"nyc": "11.9.0",
"parted": "^0.1.1",
"promise": "^8.0.1",
"promise": "^8.0.3",
"resumer": "0.0.0",
"rollup": "^0.63.4",
"rollup-plugin-babel": "^3.0.3",
"string-to-arraybuffer": "^1.0.0",
"rollup-plugin-babel": "^3.0.7",
"string-to-arraybuffer": "^1.0.2",
"url-search-params": "^1.0.2",
"whatwg-url": "^5.0.0"
},
Expand Down
14 changes: 0 additions & 14 deletions test/server.js
Expand Up @@ -117,20 +117,6 @@ export default class TestServer {
res.end('fake gzip string');
}

if (p === '/invalid-header') {
res.setHeader('Content-Type', 'text/plain');
res.writeHead(200);
// HACK: add a few invalid headers to the generated header string before
// it is actually sent to the socket.
res._header = res._header.replace(/\r\n$/, [
'Invalid-Header : abc\r\n',
'Invalid-Header-Value: \x07k\r\n',
'Set-Cookie: \x07k\r\n',
'Set-Cookie: \x07kk\r\n',
].join('') + '\r\n');
res.end('hello world\n');
}

if (p === '/timeout') {
setTimeout(function() {
res.statusCode = 200;
Expand Down
22 changes: 10 additions & 12 deletions test/test.js
Expand Up @@ -45,7 +45,7 @@ import fetch, {
Response
} from '../src/';
import FetchErrorOrig from '../src/fetch-error.js';
import HeadersOrig from '../src/headers.js';
import HeadersOrig, { createHeadersLenient } from '../src/headers.js';
import RequestOrig from '../src/request.js';
import ResponseOrig from '../src/response.js';
import Body from '../src/body.js';
Expand Down Expand Up @@ -489,17 +489,15 @@ describe('node-fetch', () => {
});

it('should ignore invalid headers', function() {
const url = `${base}invalid-header`;
return fetch(url).then(res => {
expect(res.headers.get('Invalid-Header')).to.be.null;
expect(res.headers.get('Invalid-Header-Value')).to.be.null;
expect(res.headers.get('Set-Cookie')).to.be.null;
expect(Array.from(res.headers.keys()).length).to.equal(4);
expect(res.headers.has('Connection')).to.be.true;
expect(res.headers.has('Content-Type')).to.be.true;
expect(res.headers.has('Date')).to.be.true;
expect(res.headers.has('Transfer-Encoding')).to.be.true;
});
var headers = {
'Invalid-Header ': 'abc\r\n',
'Invalid-Header-Value': '\x07k\r\n',
'Set-Cookie': ['\x07k\r\n', '\x07kk\r\n']
};
headers = createHeadersLenient(headers);
expect(headers).to.not.have.property('Invalid-Header ');
expect(headers).to.not.have.property('Invalid-Header-Value');
expect(headers).to.not.have.property('Set-Cookie');
});

it('should handle client-error response', function() {
Expand Down

0 comments on commit 05f5ac1

Please sign in to comment.