Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit c01db10

Browse files
committed
test: adding tests for trailer header errors
1 parent 1845f2b commit c01db10

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

test/request-api.spec.js

+34-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ const expect = chai.expect
77
chai.use(dirtyChai)
88
const isNode = require('detect-node')
99
const ipfsAPI = require('../src/index.js')
10+
const ndjson = require('ndjson')
11+
const pump = require('pump')
1012

1113
describe('\'deal with HTTP weirdness\' tests', () => {
1214
it('does not crash if no content-type header is provided', (done) => {
13-
if (!isNode) { return done() }
15+
if (!isNode) {
16+
return done()
17+
}
1418

1519
// go-ipfs always (currently) adds a content-type header, even if no content is present,
1620
// the standard behaviour for an http-api is to omit this header if no content is present
@@ -27,3 +31,32 @@ describe('\'deal with HTTP weirdness\' tests', () => {
2731
})
2832
})
2933
})
34+
35+
describe('trailer headers', () => {
36+
it('should deal with trailer x-stream-error correctly', (done) => {
37+
if (!isNode) {
38+
return done()
39+
}
40+
41+
const server = require('http').createServer((req, res) => {
42+
const resStream = pump(res, ndjson.stringify())
43+
res.setHeader('x-chunked-output', '1')
44+
res.setHeader('content-type', 'application/json')
45+
res.setHeader('Trailer', 'X-Stream-Error')
46+
res.addTrailers({ 'X-Stream-Error': JSON.stringify({ Message: 'ups, something went wrong', Code: 500 }) })
47+
resStream.write({ Bytes: 1 })
48+
res.end()
49+
})
50+
51+
server.listen(6001, () => {
52+
const ipfs = ipfsAPI('/ip4/127.0.0.1/tcp/6001')
53+
/* eslint-disable */
54+
ipfs.files.add(Buffer.from('Hello there!'), (err, res) => {
55+
// expect(err).to.exist()
56+
expect(res).to.not.equal(0)
57+
server.close(done)
58+
})
59+
/* eslint-enable */
60+
})
61+
})
62+
})

0 commit comments

Comments
 (0)