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'),
|
||||
https = require('https'),
|
||||
util = require('util'),
|
||||
common = require('../common'),
|
||||
passes = exports;
|
||||
|
||||
@ -114,24 +113,27 @@ var passes = exports;
|
||||
|
||||
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 (util.isArray(proxyRes.headers[i])) {
|
||||
var a = proxyRes.headers[i];
|
||||
var len = a.length;
|
||||
|
||||
for (var x = 0; x < len; x++) {
|
||||
writeHead.push(i + ": " + a[x]);
|
||||
}
|
||||
} else {
|
||||
writeHead.push(i + ": " + proxyRes.headers[i]);
|
||||
}
|
||||
if (!Array.isArray(value)) {
|
||||
head.push(key + ': ' + value);
|
||||
return head;
|
||||
}
|
||||
|
||||
socket.write(writeHead.join('\r\n') + '\r\n\r\n');
|
||||
for (var i = 0; i < value.length; i++) {
|
||||
head.push(key + ': ' + value[i]);
|
||||
}
|
||||
return head;
|
||||
}, ['HTTP/1.1 101 Switching Protocols'])
|
||||
.join('\r\n') + '\r\n\r\n'
|
||||
);
|
||||
|
||||
proxySocket.pipe(socket).pipe(proxySocket);
|
||||
|
||||
server.emit('open', proxySocket);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user