| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f49704b commit eacfbd0
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -526,7 +526,9 @@ function ClientRequest(input, options, cb) { | |||
| 526 | 526 | const userHostHeader = this.getHeader('host'); | |
| 527 | 527 | ||
| 528 | 528 | if (host && !this.getHeader('host') && setHost) { | |
| 529 | - this.setHeader('Host', hostHeaderFromOptions); | ||
| 529 | + const hostHeader = method === 'CONNECT' && options.path ? | ||
| 530 | + String(this.path) : hostHeaderFromOptions; | ||
| 531 | + this.setHeader('Host', hostHeader); | ||
| 530 | 532 | } | |
| 531 | 533 | ||
| 532 | 534 | if (options.auth && !this.getHeader('Authorization')) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,37 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + const http = require('http'); | ||
| 6 | + const net = require('net'); | ||
| 7 | + | ||
| 8 | + const target = 'target.example.com:443'; | ||
| 9 | + | ||
| 10 | + const server = net.createServer(common.mustCall((socket) => { | ||
| 11 | + socket.once('data', common.mustCall((data) => { | ||
| 12 | + const rawRequest = data.toString(); | ||
| 13 | + const requestLines = rawRequest.split('\r\n'); | ||
| 14 | + | ||
| 15 | + assert.strictEqual(requestLines[0], `CONNECT ${target} HTTP/1.1`); | ||
| 16 | + assert(requestLines.includes(`Host: ${target}`)); | ||
| 17 | + | ||
| 18 | + socket.end('HTTP/1.1 200 Connection established\r\n\r\n'); | ||
| 19 | + })); | ||
| 20 | + })); | ||
| 21 | + | ||
| 22 | + server.listen(0, common.localhostIPv4, common.mustCall(() => { | ||
| 23 | + const req = http.request({ | ||
| 24 | + host: common.localhostIPv4, | ||
| 25 | + port: server.address().port, | ||
| 26 | + method: 'CONNECT', | ||
| 27 | + path: target, | ||
| 28 | + }, common.mustNotCall()); | ||
| 29 | + | ||
| 30 | + req.on('connect', common.mustCall((res, socket) => { | ||
| 31 | + assert.strictEqual(res.statusCode, 200); | ||
| 32 | + socket.destroy(); | ||
| 33 | + server.close(); | ||
| 34 | + })); | ||
| 35 | + | ||
| 36 | + req.end(); | ||
| 37 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -61,7 +61,7 @@ const proxy = net.createServer(common.mustCall((clientSocket) => { | |||
| 61 | 61 | `CONNECT localhost:${server.address().port} ` + | |
| 62 | 62 | 'HTTP/1.1\r\n' + | |
| 63 | 63 | 'Proxy-Connections: keep-alive\r\n' + | |
| 64 | - `Host: localhost:${proxy.address().port}\r\n` + | ||
| 64 | + `Host: localhost:${server.address().port}\r\n` + | ||
| 65 | 65 | 'Connection: keep-alive\r\n\r\n'); | |
| 66 | 66 | ||
| 67 | 67 | console.log('PROXY: got CONNECT request'); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments