Skip to content

Commit 88c2633

Browse files
committed
use endAfterHeaders
1 parent 97c0d7a commit 88c2633

File tree

4 files changed

+55
-14
lines changed

4 files changed

+55
-14
lines changed

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ before_install:
2626
- "test $TRAVIS_NODE_VERSION != '0.6' || npm rm --save-dev istanbul"
2727
- "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev istanbul"
2828
- "test $(echo $TRAVIS_NODE_VERSION | cut -d. -f1) -ge 4 || npm rm --save-dev $(grep -E '\"eslint\\S*\"' package.json | cut -d'\"' -f2)"
29-
- "test -z $(echo $HTTP2_TEST) || npm install https://github.com/visionmedia/superagent.git"
3029

3130
# Update Node.js modules
3231
- "test ! -d node_modules || npm prune"
@@ -40,7 +39,5 @@ after_script:
4039
- "test -e ./coverage/lcov.info && npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"
4140
matrix:
4241
include:
43-
- node_js: "9.5"
44-
env: HTTP2_TEST=1
45-
- node_js: "8.9"
42+
- node_js: "10.11"
4643
env: HTTP2_TEST=1

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function typeis (value, types_) {
9797
*/
9898

9999
function hasbody (req) {
100-
return (ishttp2(req) && (req.stream.readable || !req.stream._readableState.sync)) ||
100+
return (ishttp2(req) && !req.stream.endAfterHeaders) ||
101101
req.headers['transfer-encoding'] !== undefined ||
102102
!isNaN(req.headers['content-length'])
103103
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"scripts": {
3535
"lint": "eslint --plugin markdown --ext js,md .",
3636
"test": "mocha --reporter spec --check-leaks --bail test/",
37+
"test-http2": "HTTP2_TEST=1 mocha --reporter spec --check-leaks --bail test/",
3738
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
3839
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
3940
},

test/test.js

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,11 @@ describe('typeis.hasBody(req)', function () {
216216
assert.strictEqual(typeis.hasBody(req), true)
217217
})
218218

219-
it('should be true when 0', function () {
220-
var req = {headers: {'content-length': '0'}}
221-
assert.strictEqual(typeis.hasBody(req), true)
219+
it('should be true when 0', function (done) {
220+
createZeroLengthBodyRequest('', function (req) {
221+
assert.strictEqual(typeis.hasBody(req), true)
222+
done()
223+
})
222224
})
223225

224226
it('should be false when bogus', function () {
@@ -333,9 +335,15 @@ function createRequest (type, callback) {
333335
var s = new Readable()
334336
s.push('hello')
335337
s.push(null)
336-
var req = request.post('localhost:' + server.address().port + '/')
337-
.set('content-type', type || undefined)
338-
s.pipe(req)
338+
339+
var session = http2.connect('http://localhost:' + server.address().port)
340+
var headers = {
341+
':path': '/',
342+
':method': 'post',
343+
'content-type': type || undefined
344+
}
345+
var request = session.request(headers)
346+
s.pipe(request)
339347
})
340348
} else {
341349
var req = {
@@ -356,9 +364,16 @@ function createBodylessRequest (type, callback) {
356364
})
357365

358366
server = server.listen(function () {
359-
request.get('localhost:' + server.address().port + '/')
360-
.set('content-type', type || undefined)
361-
.end()
367+
var session = http2.connect('http://localhost:' + server.address().port)
368+
var headers = {
369+
':path': '/',
370+
':method': 'get',
371+
'content-type': type || ''
372+
}
373+
var option = {
374+
endStream: true
375+
}
376+
session.request(headers, option)
362377
})
363378
} else {
364379
var req = {
@@ -369,3 +384,31 @@ function createBodylessRequest (type, callback) {
369384
callback(req)
370385
}
371386
}
387+
388+
function createZeroLengthBodyRequest (type, callback) {
389+
if (process.env.HTTP2_TEST) {
390+
var server = http2.createServer(function (req, res) {
391+
callback(req)
392+
server.close()
393+
})
394+
395+
server = server.listen(function () {
396+
var session = http2.connect('http://localhost:' + server.address().port)
397+
var headers = {
398+
':path': '/',
399+
':method': 'get',
400+
'content-type': type || ''
401+
}
402+
var request = session.request(headers)
403+
request.end()
404+
})
405+
} else {
406+
var req = {
407+
headers: {
408+
'content-type': type || '',
409+
'content-length': 0
410+
}
411+
}
412+
callback(req)
413+
}
414+
}

0 commit comments

Comments
 (0)