-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This use case is relied upon by fast-proxy and it was working with the Node.js core client but not with Undici.
- Loading branch information
Showing
3 changed files
with
101 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'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() | ||
|
||
t.plan(11) | ||
t.tearDown(instance.close.bind(instance)) | ||
|
||
const target = http.createServer((req, res) => { | ||
t.pass('request proxied') | ||
t.equal(req.method, 'GET') | ||
t.equal(req.url, '/hello') | ||
t.equal(req.headers.connection, 'close') | ||
res.statusCode = 205 | ||
res.setHeader('Content-Type', 'text/plain') | ||
res.setHeader('x-my-header', 'hello!') | ||
res.end('hello world') | ||
}) | ||
|
||
instance.get('/', (request, reply) => { | ||
reply.from('/hello') | ||
}) | ||
|
||
t.tearDown(target.close.bind(target)) | ||
|
||
target.listen(0, (err) => { | ||
t.error(err) | ||
|
||
instance.register(From, { | ||
base: `http://localhost:${target.address().port}/hello`, | ||
http: true | ||
}) | ||
|
||
instance.listen(0, (err) => { | ||
t.error(err) | ||
|
||
get(`http://localhost:${instance.server.address().port}`, (err, res, data) => { | ||
t.error(err) | ||
t.equal(res.headers['content-type'], 'text/plain') | ||
t.equal(res.headers['x-my-header'], 'hello!') | ||
t.equal(res.statusCode, 205) | ||
t.equal(data.toString(), 'hello world') | ||
}) | ||
}) | ||
}) |
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,50 @@ | ||
'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() | ||
|
||
t.plan(11) | ||
t.tearDown(instance.close.bind(instance)) | ||
|
||
const target = http.createServer((req, res) => { | ||
t.pass('request proxied') | ||
t.equal(req.method, 'GET') | ||
t.equal(req.url, '/hello') | ||
t.equal(req.headers.connection, 'keep-alive') | ||
res.statusCode = 205 | ||
res.setHeader('Content-Type', 'text/plain') | ||
res.setHeader('x-my-header', 'hello!') | ||
res.end('hello world') | ||
}) | ||
|
||
instance.get('/', (request, reply) => { | ||
reply.from('/hello') | ||
}) | ||
|
||
t.tearDown(target.close.bind(target)) | ||
|
||
target.listen(0, (err) => { | ||
t.error(err) | ||
|
||
instance.register(From, { | ||
base: `http://localhost:${target.address().port}/hello`, | ||
undici: true | ||
}) | ||
|
||
instance.listen(0, (err) => { | ||
t.error(err) | ||
|
||
get(`http://localhost:${instance.server.address().port}`, (err, res, data) => { | ||
t.error(err) | ||
t.equal(res.headers['content-type'], 'text/plain') | ||
t.equal(res.headers['x-my-header'], 'hello!') | ||
t.equal(res.statusCode, 205) | ||
t.equal(data.toString(), 'hello world') | ||
}) | ||
}) | ||
}) |