Skip to content

Commit

Permalink
Fixed tests for HTTP/2
Browse files Browse the repository at this point in the history
  • Loading branch information
parthverma1 committed Jul 23, 2024
1 parent 95608e2 commit a3b3e65
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lib/http2/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class ResponseProxy extends EventEmitter {
}

pipe (dest) {
this.reqStream.pipe(dest)
return this.reqStream.pipe(dest)
}

setEncoding (encoding) {
Expand Down
9 changes: 0 additions & 9 deletions tests/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ exports.createPostValidator = function (text, reqContentType) {
resp.writeHead(200, { 'content-type': 'text/plain' })
resp.write(r)
resp.end()
// Close the session if it's a HTTP/2 request. This is not representative of a true http/2 server that might keep the session open. But we need this to close the server in the tests.
req || req.stream || req.stream.session || req.stream.session.close || req.stream.session.close()
})
}
return l
Expand All @@ -133,8 +131,6 @@ exports.createPostJSONValidator = function (value, reqContentType) {
resp.writeHead(200, { 'content-type': 'application/json' })
resp.write(r)
resp.end()
// Close the session if it's a HTTP/2 request. This is not representative of a true http/2 server that might keep the session open. But we need this to close the server in the tests.
req || req.stream || req.stream.session || req.stream.session.close || req.stream.session.close()
})
}
return l
Expand All @@ -145,9 +141,6 @@ exports.createGetResponse = function (text, contentType) {
resp.writeHead(200, { 'content-type': contentType })
resp.write(text)
resp.end()

// Close the session if it's a HTTP/2 request. This is not representative of a true http/2 server that might keep the session open. But we need this to close the server in the tests.
req || req.stream || req.stream.session || req.stream.session.close || req.stream.session.close()
}
return l
}
Expand All @@ -159,8 +152,6 @@ exports.createChunkResponse = function (chunks, contentType) {
resp.write(chunk)
})
resp.end()
// Close the session if it's a HTTP/2 request. This is not representative of a true http/2 server that might keep the session open. But we need this to close the server in the tests.
req || req.stream || req.stream.session || req.stream.session.close || req.stream.session.close()
}
return l
}
Expand Down
8 changes: 3 additions & 5 deletions tests/test-body-http2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ var request = require('../index')
var tape = require('tape')
var path = require('path')
var fs = require('fs')
var destroyable = require('server-destroy')

var s = server.createHttp2Server()
destroyable(s)

tape('setup', function (t) {
s.listen(0, function () {
Expand Down Expand Up @@ -154,8 +156,6 @@ addTest('testPutMultipartPostambleCRLF', {
tape('testBinaryFile', function (t) {
s.on('/', function (req, res) {
req.pipe(res)
// Close the session if it's a HTTP/2 request. This is not representative of a true http/2 server that might keep the session open. But we need this to close the server in the tests.
req.stream && req.stream.session && req.stream.session.close && req.stream.session.close()
})

request(
Expand All @@ -178,8 +178,6 @@ tape('testBinaryFile', function (t) {
tape('typed array', function (t) {
s.on('/', function (req, res) {
req.pipe(res)
// Close the session if it's a HTTP/2 request. This is not representative of a true http/2 server that might keep the session open. But we need this to close the server in the tests.
req.stream && req.stream.session && req.stream.session.close && req.stream.session.close()
})

var data = new Uint8Array([1, 2, 3])
Expand All @@ -203,7 +201,7 @@ tape('typed array', function (t) {
})

tape('cleanup', function (t) {
s.close(function () {
s.destroy(function () {
t.end()
})
})
7 changes: 3 additions & 4 deletions tests/test-cookies-http2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

var request = require('../index')
var tape = require('tape')
var destroyable = require('server-destroy')
var server = require('./server')

var validUrl
var malformedUrl
var invalidUrl

var s = server.createHttp2Server()
destroyable(s)

tape('setup', function (t) {
s.listen(0, function () {
Expand All @@ -19,17 +21,14 @@ tape('setup', function (t) {
s.on('/valid', (req, res) => {
res.setHeader('set-cookie', 'foo=bar')
res.end('okay')
res.stream.session.close()
})
s.on('/malformed', (req, res) => {
res.setHeader('set-cookie', 'foo')
res.end('okay')
res.stream.session.close()
})
s.on('/invalid', (req, res) => {
res.setHeader('set-cookie', 'foo=bar; Domain=foo.com')
res.end('okay')
res.stream.session.close()
})

t.end()
Expand Down Expand Up @@ -137,7 +136,7 @@ tape('custom store', function (t) {
})

tape('cleanup', function (t) {
s.close(function () {
s.destroy(function () {
t.end()
})
})
8 changes: 4 additions & 4 deletions tests/test-verbose-auto-http2.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ tape('HTTP: verbose=true', function (t) {
t.deepEqual(Object.keys(debug[0].session), ['id', 'reused', 'data'])
t.deepEqual(Object.keys(debug[0].session.data), ['addresses'])
t.equal(debug[0].session.reused, false)
t.deepEqual(Object.keys(debug[0].response), ['statusCode', 'headers', 'httpVersion'])
t.deepEqual(Object.keys(debug[0].response), ['statusCode', 'headers', 'httpVersion', 'downloadedBytes'])

t.notEqual(debug[0].response.headers.length, 0)
t.equal(debug[0].response.headers[0].key, 'Date')
Expand Down Expand Up @@ -116,7 +116,7 @@ tape('HTTP: redirect(HTTPS) + verbose=true', function (t) {
t.deepEqual(Object.keys(debug[1].session.data), ['addresses', 'tls'])
t.deepEqual(Object.keys(debug[1].session.data.tls), ['reused', 'authorized', 'authorizationError', 'cipher', 'protocol', 'ephemeralKeyInfo', 'peerCertificate'])
t.equal(debug[1].session.reused, false)
t.deepEqual(Object.keys(debug[1].response), ['statusCode', 'headers', 'httpVersion'])
t.deepEqual(Object.keys(debug[1].response), ['statusCode', 'headers', 'httpVersion', 'downloadedBytes'])

t.end()
})
Expand Down Expand Up @@ -144,7 +144,7 @@ tape('HTTPS: verbose=true', function (t) {
t.deepEqual(Object.keys(debug[0].session.data), ['addresses', 'tls'])
t.deepEqual(Object.keys(debug[0].session.data.tls), ['reused', 'authorized', 'authorizationError', 'cipher', 'protocol', 'ephemeralKeyInfo', 'peerCertificate'])
t.equal(debug[0].session.reused, true)
t.deepEqual(Object.keys(debug[0].response), ['statusCode', 'headers', 'httpVersion'])
t.deepEqual(Object.keys(debug[0].response), ['statusCode', 'headers', 'httpVersion', 'downloadedBytes'])

t.end()
})
Expand Down Expand Up @@ -179,7 +179,7 @@ tape('HTTPS: redirect(HTTP) + verbose=true', function (t) {
t.deepEqual(Object.keys(debug[1].session), ['id', 'reused', 'data'])
t.deepEqual(Object.keys(debug[1].session.data), ['addresses'])
t.equal(debug[1].session.reused, false)
t.deepEqual(Object.keys(debug[1].response), ['statusCode', 'headers', 'httpVersion'])
t.deepEqual(Object.keys(debug[1].response), ['statusCode', 'headers', 'httpVersion', 'downloadedBytes'])

t.end()
})
Expand Down
8 changes: 4 additions & 4 deletions tests/test-verbose-http2.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ tape('HTTP: verbose=true', function (t) {
t.deepEqual(Object.keys(debug[0].session), ['id', 'reused', 'data'])
t.deepEqual(Object.keys(debug[0].session.data), ['addresses'])
t.equal(debug[0].session.reused, false)
t.deepEqual(Object.keys(debug[0].response), ['statusCode', 'headers', 'httpVersion'])
t.deepEqual(Object.keys(debug[0].response), ['statusCode', 'headers', 'httpVersion', 'downloadedBytes'])

t.notEqual(debug[0].response.headers.length, 0)
t.equal(debug[0].response.headers[0].key, 'Date')
Expand Down Expand Up @@ -116,7 +116,7 @@ tape('HTTP: redirect(HTTPS) + verbose=true', function (t) {
t.deepEqual(Object.keys(debug[1].session.data), ['addresses', 'tls'])
t.deepEqual(Object.keys(debug[1].session.data.tls), ['reused', 'authorized', 'authorizationError', 'cipher', 'protocol', 'ephemeralKeyInfo', 'peerCertificate'])
t.equal(debug[1].session.reused, false)
t.deepEqual(Object.keys(debug[1].response), ['statusCode', 'headers', 'httpVersion'])
t.deepEqual(Object.keys(debug[1].response), ['statusCode', 'headers', 'httpVersion', 'downloadedBytes'])

t.end()
})
Expand Down Expand Up @@ -144,7 +144,7 @@ tape('HTTPS: verbose=true', function (t) {
t.deepEqual(Object.keys(debug[0].session.data), ['addresses', 'tls'])
t.deepEqual(Object.keys(debug[0].session.data.tls), ['reused', 'authorized', 'authorizationError', 'cipher', 'protocol', 'ephemeralKeyInfo', 'peerCertificate'])
t.equal(debug[0].session.reused, true)
t.deepEqual(Object.keys(debug[0].response), ['statusCode', 'headers', 'httpVersion'])
t.deepEqual(Object.keys(debug[0].response), ['statusCode', 'headers', 'httpVersion', 'downloadedBytes'])

t.end()
})
Expand Down Expand Up @@ -179,7 +179,7 @@ tape('HTTPS: redirect(HTTP) + verbose=true', function (t) {
t.deepEqual(Object.keys(debug[1].session), ['id', 'reused', 'data'])
t.deepEqual(Object.keys(debug[1].session.data), ['addresses'])
t.equal(debug[1].session.reused, false)
t.deepEqual(Object.keys(debug[1].response), ['statusCode', 'headers', 'httpVersion'])
t.deepEqual(Object.keys(debug[1].response), ['statusCode', 'headers', 'httpVersion', 'downloadedBytes'])

t.end()
})
Expand Down

0 comments on commit a3b3e65

Please sign in to comment.