-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use undici by default * Drop deprecated options & better defaults * Increase code coverage * Code coverage * Minimum node version is v10. * Support for unix sockets
- Loading branch information
Showing
16 changed files
with
435 additions
and
99 deletions.
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
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,66 @@ | ||
'use strict' | ||
|
||
const t = require('tap') | ||
const Fastify = require('fastify') | ||
const From = require('..') | ||
const http = require('http') | ||
const get = require('simple-get').concat | ||
|
||
const instance = Fastify() | ||
instance.register(From, { | ||
http: true | ||
}) | ||
|
||
t.plan(8) | ||
t.tearDown(instance.close.bind(instance)) | ||
|
||
instance.addContentTypeParser('application/octet-stream', function (req, payload, done) { | ||
done(null, payload) | ||
}) | ||
|
||
t.tearDown(instance.close.bind(instance)) | ||
|
||
const target = http.createServer((req, res) => { | ||
t.pass('request proxied') | ||
t.equal(req.method, 'POST') | ||
t.equal(req.headers['content-type'], 'application/octet-stream') | ||
let data = '' | ||
req.setEncoding('utf8') | ||
req.on('data', (d) => { | ||
data += d | ||
}) | ||
req.on('end', () => { | ||
t.deepEqual(JSON.parse(data), { hello: 'world' }) | ||
res.statusCode = 200 | ||
res.setHeader('content-type', 'application/octet-stream') | ||
res.end(JSON.stringify({ something: 'else' })) | ||
}) | ||
}) | ||
|
||
instance.post('/', (request, reply) => { | ||
reply.from(`http://localhost:${target.address().port}`) | ||
}) | ||
|
||
t.tearDown(target.close.bind(target)) | ||
|
||
instance.listen(0, (err) => { | ||
t.error(err) | ||
|
||
target.listen(0, (err) => { | ||
t.error(err) | ||
|
||
get({ | ||
url: `http://localhost:${instance.server.address().port}`, | ||
method: 'POST', | ||
headers: { | ||
'content-type': 'application/octet-stream' | ||
}, | ||
body: JSON.stringify({ | ||
hello: 'world' | ||
}) | ||
}, (err, res, data) => { | ||
t.error(err) | ||
t.deepEqual(JSON.parse(data), { something: 'else' }) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.