This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 297
/
Copy pathrequest-api.spec.js
67 lines (60 loc) · 2.18 KB
/
request-api.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* eslint-env mocha */
'use strict'
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const isNode = require('detect-node')
const ipfsClient = require('../src/index.js')
const ndjson = require('ndjson')
const pump = require('pump')
describe('\'deal with HTTP weirdness\' tests', () => {
it('does not crash if no content-type header is provided', (done) => {
if (!isNode) {
return done()
}
// go-ipfs always (currently) adds a content-type header, even if no content is present,
// the standard behaviour for an http-api is to omit this header if no content is present
const server = require('http').createServer((req, res) => {
// Consume the entire request, before responding.
req.on('data', () => {})
req.on('end', () => {
res.writeHead(200)
res.end()
})
})
server.listen(6001, () => {
ipfsClient('/ip4/127.0.0.1/tcp/6001').config.replace('test/fixtures/r-config.json', (err) => {
expect(err).to.not.exist()
server.close(done)
})
})
})
})
describe('trailer headers', () => {
// TODO: needs fixing https://github.com/ipfs/js-ipfs-http-client/pull/624#issuecomment-344181950
it.skip('should deal with trailer x-stream-error correctly', (done) => {
if (!isNode) { return done() }
const server = require('http').createServer((req, res) => {
const resStream = pump(res, ndjson.stringify())
res.setHeader('x-chunked-output', '1')
res.setHeader('content-type', 'application/json')
res.setHeader('Trailer', 'X-Stream-Error')
res.addTrailers({ 'X-Stream-Error': JSON.stringify({ Message: 'ups, something went wrong', Code: 500 }) })
resStream.write({ Bytes: 1 })
res.end()
})
server.listen(6001, () => {
const ipfs = ipfsClient('/ip4/127.0.0.1/tcp/6001')
/* eslint-disable */
ipfs.add(Buffer.from('Hello there!'), (err, res) => {
// TODO: error's are not being correctly
// propagated with Trailer headers yet
// expect(err).to.exist()
expect(res).to.not.equal(0)
server.close(done)
})
/* eslint-enable */
})
})
})