mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[fix] make more functional
This commit is contained in:
parent
3d2350c54f
commit
cea0e8676b
@ -1,6 +1,5 @@
|
|||||||
var http = require('http'),
|
var http = require('http'),
|
||||||
https = require('https'),
|
https = require('https'),
|
||||||
util = require('util'),
|
|
||||||
common = require('../common'),
|
common = require('../common'),
|
||||||
passes = exports;
|
passes = exports;
|
||||||
|
|
||||||
@ -114,24 +113,27 @@ var passes = exports;
|
|||||||
|
|
||||||
if (proxyHead && proxyHead.length) proxySocket.unshift(proxyHead);
|
if (proxyHead && proxyHead.length) proxySocket.unshift(proxyHead);
|
||||||
|
|
||||||
var writeHead = [
|
//
|
||||||
'HTTP/1.1 101 Switching Protocols'
|
// Remark: Handle writing the headers to the socket when switching protocols
|
||||||
];
|
// Also handles when a header is an array
|
||||||
|
//
|
||||||
|
socket.write(
|
||||||
|
Object.keys(proxyRes.headers).reduce(function (head, key) {
|
||||||
|
var value = proxyRes.headers[key];
|
||||||
|
|
||||||
for(var i in proxyRes.headers) {
|
if (!Array.isArray(value)) {
|
||||||
if (util.isArray(proxyRes.headers[i])) {
|
head.push(key + ': ' + value);
|
||||||
var a = proxyRes.headers[i];
|
return head;
|
||||||
var len = a.length;
|
}
|
||||||
|
|
||||||
for (var x = 0; x < len; x++) {
|
for (var i = 0; i < value.length; i++) {
|
||||||
writeHead.push(i + ": " + a[x]);
|
head.push(key + ': ' + value[i]);
|
||||||
}
|
}
|
||||||
} else {
|
return head;
|
||||||
writeHead.push(i + ": " + proxyRes.headers[i]);
|
}, ['HTTP/1.1 101 Switching Protocols'])
|
||||||
}
|
.join('\r\n') + '\r\n\r\n'
|
||||||
}
|
);
|
||||||
|
|
||||||
socket.write(writeHead.join('\r\n') + '\r\n\r\n');
|
|
||||||
proxySocket.pipe(socket).pipe(proxySocket);
|
proxySocket.pipe(socket).pipe(proxySocket);
|
||||||
|
|
||||||
server.emit('open', proxySocket);
|
server.emit('open', proxySocket);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user