tests: add test for http2 stream api · stream-utils/raw-body@836fb51 (original) (raw)
`@@ -8,7 +8,7 @@ var describeHttp2 = !http2
`
8
8
` : describe
`
9
9
``
10
10
`describeHttp2('using http2 streams', function () {
`
11
``
`-
it('should read body streams', function (done) {
`
``
11
`+
it('should read from compatibility api', function (done) {
`
12
12
`var server = http2.createServer(function onRequest (req, res) {
`
13
13
`getRawBody(req, { length: req.headers['content-length'] }, function (err, body) {
`
14
14
`if (err) {
`
`@@ -32,6 +32,43 @@ describeHttp2('using http2 streams', function () {
`
32
32
`getRawBody(request, { encoding: true }, function (err, str) {
`
33
33
`http2close(server, session, function onClose () {
`
34
34
`assert.ifError(err)
`
``
35
`+
assert.strictEqual(headers[':status'], 200)
`
``
36
`+
assert.strictEqual(str, 'hello, world!')
`
``
37
`+
done()
`
``
38
`+
})
`
``
39
`+
})
`
``
40
`+
})
`
``
41
`+
})
`
``
42
`+
})
`
``
43
+
``
44
`+
it('should read body streams', function (done) {
`
``
45
`+
var server = http2.createServer()
`
``
46
+
``
47
`+
server.on('stream', function onStream (stream, headers) {
`
``
48
`+
getRawBody(stream, { length: headers['content-length'] }, function (err, body) {
`
``
49
`+
if (err) {
`
``
50
`+
stream.resume()
`
``
51
`+
stream.respond({ ':status': 500 })
`
``
52
`+
stream.end(err.message)
`
``
53
`+
return
`
``
54
`+
}
`
``
55
+
``
56
`+
stream.end(body)
`
``
57
`+
})
`
``
58
`+
})
`
``
59
+
``
60
`+
server.listen(function onListen () {
`
``
61
`+
var addr = server.address()
`
``
62
`+
var session = http2.connect('http://localhost:' + addr.port)
`
``
63
`+
var request = session.request({ ':method': 'POST', ':path': '/' })
`
``
64
+
``
65
`+
request.end('hello, world!')
`
``
66
+
``
67
`+
request.on('response', function onResponse (headers) {
`
``
68
`+
getRawBody(request, { encoding: true }, function (err, str) {
`
``
69
`+
http2close(server, session, function onClose () {
`
``
70
`+
assert.ifError(err)
`
``
71
`+
assert.strictEqual(headers[':status'], 200)
`
35
72
`assert.strictEqual(str, 'hello, world!')
`
36
73
`done()
`
37
74
`})
`
`@@ -61,10 +98,11 @@ describeHttp2('using http2 streams', function () {
`
61
98
``
62
99
`request.end('hello, world!')
`
63
100
``
64
``
`-
request.on('response', function onResponse (res) {
`
``
101
`+
request.on('response', function onResponse (headers) {
`
65
102
`getRawBody(request, { encoding: true }, function (err, str) {
`
66
103
`http2close(server, session, function onClose () {
`
67
104
`assert.ifError(err)
`
``
105
`+
assert.strictEqual(headers[':status'], 500)
`
68
106
`assert.strictEqual(str, 'stream encoding should not be set')
`
69
107
`done()
`
70
108
`})
`