This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for custom headers to send-request (#741)
* add support for custom headers to send-request * add custom headers test * add custom header documentation * fix: clone config.headers to avoid prev headers in next req License: MIT Signed-off-by: Alan Shaw <[email protected]>
- Loading branch information
Showing
3 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const isNode = require('detect-node') | ||
const chai = require('chai') | ||
const dirtyChai = require('dirty-chai') | ||
const expect = chai.expect | ||
chai.use(dirtyChai) | ||
|
||
const IPFSApi = require('../src') | ||
const f = require('./utils/factory') | ||
|
||
describe('custom headers', function () { | ||
// do not test in browser | ||
if (!isNode) { return } | ||
this.timeout(50 * 1000) // slow CI | ||
let ipfs | ||
let ipfsd | ||
// initialize ipfs with custom headers | ||
before(done => { | ||
f.spawn({ initOptions: { bits: 1024 } }, (err, _ipfsd) => { | ||
expect(err).to.not.exist() | ||
ipfsd = _ipfsd | ||
ipfs = IPFSApi({ | ||
host: 'localhost', | ||
port: 6001, | ||
protocol: 'http', | ||
headers: { | ||
authorization: 'Bearer ' + 'YOLO' | ||
} | ||
}) | ||
done() | ||
}) | ||
}) | ||
|
||
it('are supported', done => { | ||
// spin up a test http server to inspect the requests made by the library | ||
const server = require('http').createServer((req, res) => { | ||
req.on('data', () => {}) | ||
req.on('end', () => { | ||
res.writeHead(200) | ||
res.end() | ||
// ensure custom headers are present | ||
expect(req.headers.authorization).to.equal('Bearer ' + 'YOLO') | ||
server.close() | ||
done() | ||
}) | ||
}) | ||
|
||
server.listen(6001, () => { | ||
ipfs.id((err, res) => { | ||
if (err) { | ||
throw new Error('Unexpected error.') | ||
} | ||
// this call is used to test that headers are being sent. | ||
}) | ||
}) | ||
}) | ||
|
||
after(done => ipfsd.stop(done)) | ||
}) |