[英]Ignore header validation for HTTP requests in Node
I am building a proxy server which is supposed to forward data from an Shoutcast server to the client. 我正在构建一个代理服务器,该代理服务器应该将数据从Shoutcast服务器转发到客户端。 Using request
or even Node's http
module this fails due to missing HTTP header: 使用request
甚至Node的http
模块都会由于缺少HTTP标头而失败:
{ [Error: Parse Error] bytesParsed: 0, code: 'HPE_INVALID_CONSTANT' }
The URL in question is: http://stream6.jungletrain.net:8000 有问题的URL是: http : //stream6.jungletrain.net : 8000
Doing a header request with curl I was able to verify this: 用curl进行标头请求,我能够验证这一点:
$ curl -I http://stream6.jungletrain.net:8000
curl: (52) Empty reply from server
Yet the stream is working fine as tested with curl stream6.jungletrain.net:8000
. 但是,通过curl stream6.jungletrain.net:8000
进行测试,该流工作正常。
Is there a way to disable the header verification in request
or Node's http
? 有没有一种方法可以在request
或Node的http
禁用标头验证? This is the code I am testing it on: 这是我正在测试的代码:
var express = require('express');
var request = require('request');
var app = express();
app.get('/', function (req, res) {
request('http://stream6.jungletrain.net:8000').pipe(res);
stream.pipe(res);
});
var server = app.listen(3000, function () {
console.log('Server started')
});
I am aware this can be achieved by rolling an implementation with net
, there is also icecast-stack
but subjectively seen it only implements half of the Stream
interfaces properly. 我知道这可以通过使用net
滚动实现来net
,这里也有icecast-stack
但主观上看它仅正确实现了一半的Stream
接口。
Using icecast
, I was able to get this working both using the on('data')
event and by piping it to the Express response: 使用icecast
,我可以使用on('data')
事件并将其传递给Express响应来使其工作:
var express = require('express');
var app = express();
var icecast = require('icecast');
var url = 'http://stream6.jungletrain.net:8000';
app.get('/', function(req, res) {
icecast.get(url, function(icecastRes) {
console.error(icecastRes.headers);
icecastRes.on('metadata', function(metadata) {
var parsed = icecast.parse(metadata);
console.error(parsed);
});
icecastRes.on('data', function(chunk) {
console.log(chunk);
})
});
});
var server = app.listen(3000, function() {
console.log('Server started')
});
Or simply: 或者简单地:
app.get('/', function(req, res) {
icecast.get(url).pipe(res);
});
Also of some note: 还有一些注意事项:
It appears the icecast package has been superseded by https://www.npmjs.com/package/icy 看来icecast软件包已被https://www.npmjs.com/package/icy取代
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.