We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
You can continue the conversation there. Go to discussion →
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The pipe request forwards all the client headers including the "Host"
The pipe request should forwards all the client headers but not the "Host"
npm install got nock express request
const got = require('got') const nock = require('nock') const express = require('express') const request = require('request') nock('http://www.google.com') .persist() .get('/echo') .reply(function (uri, body) { return [200, { headers: this.req.headers }] }) const proxy = express() proxy.get('/got/pipe', (req, res) => { req.pipe(got.stream('http://www.google.com/echo')).pipe(res) }) proxy.get('/request/pipe', (req, res) => { req.pipe(request.get('http://www.google.com/echo')).pipe(res) }) proxy.listen(3000, () => { console.log('Try the following:') console.log("curl -H 'Hi: Bye' -H 'Host: Value' 'http://127.0.0.1:3000/got/pipe'") console.log("curl -H 'Hi: Bye' -H 'Host: Value' 'http://127.0.0.1:3000/request/pipe'") })
Output
// With Got curl -H 'Hi: Bye' -H 'Host: Value' 'http://127.0.0.1:3000/got/pipe' { "headers": { "accept": "*/*", "accept-encoding": "gzip, deflate, br", "hi": "Bye", "host": "Value", **// Should not have been this.** "user-agent": "got (https://github.com/sindresorhus/got)" } } // With Request curl -H 'Hi: Bye' -H 'Host: Value' 'http://127.0.0.1:3000/request/pipe' { "headers": { "accept": "*/*", "hi": "Bye", "host": "www.google.com", "user-agent": "curl/7.64.1" } }
Since the host doesn't match the hostname in the URL, it leads to a certificate error when hitting the actual service than the mocked one.
The text was updated successfully, but these errors were encountered:
Simply delete req.headers.host; before piping to got.
delete req.headers.host;
Sorry, something went wrong.
got/source/core/index.ts
Lines 1415 to 1422 in f896aa5
Or you can use a beforeRequest hook:
beforeRequest
{ hooks: { beforeRequest: [ options => { delete options.headers.host; } ] } } }
No branches or pull requests
Describe the bug
Actual behavior
The pipe request forwards all the client headers including the "Host"
Expected behavior
The pipe request should forwards all the client headers but not the "Host"
Code to reproduce
Output
Since the host doesn't match the hostname in the URL, it leads to a certificate error when hitting the actual service than the mocked one.
Checklist
The text was updated successfully, but these errors were encountered: