Skip to content
New issue

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

"Error: Can't set headers after they are sent" with caronte #469

Closed
Rush opened this issue Sep 15, 2013 · 6 comments
Closed

"Error: Can't set headers after they are sent" with caronte #469

Rush opened this issue Sep 15, 2013 · 6 comments

Comments

@Rush
Copy link
Contributor

Rush commented Sep 15, 2013

Again, I am trying the simplest use case:

var caronte = require('./index.js');
var proxy = caronte.createProxyServer({});
var EventEmitter = require('events').EventEmitter;

require('http').createServer(function(req, res) {
    res.end("TEST");
}).listen(8089)

require('http').createServer(function(req, res) {
  proxy.web(req, res, {
            target: require('url').parse("http://127.0.0.1:8089"),
            ee: new EventEmitter()
  });
}).listen(8081);

Testing ab2 -v 2 -c 1 -n 20 http://127.0.0.1:8081/

> node ./test

http.js:708
    throw new Error('Can\'t set headers after they are sent.');
          ^
Error: Can't set headers after they are sent.
    at ServerResponse.OutgoingMessage.setHeader (http.js:708:11)
    at node-http-proxy/lib/caronte/passes/web-outgoing.js:19:11

Thanks for your support!

yawnt added a commit that referenced this issue Sep 15, 2013
@yawnt
Copy link
Contributor

yawnt commented Sep 15, 2013

fixed

@yawnt yawnt closed this as completed Sep 15, 2013
@Rush
Copy link
Contributor Author

Rush commented Sep 15, 2013

I am afraid it is not completely fixed because the request does not finish.
Considering my test:

 # ab2 -v 2 -c 1 -n 1 http://127.0.0.1:8081/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)...INFO: POST header == 
---
GET / HTTP/1.0
Host: 127.0.0.1:8081
User-Agent: ApacheBench/2.3
Accept: */*


---
LOG: header received:
HTTP/1.1 200 OK
date: Sun, 15 Sep 2013 20:10:28 GMT
connection: keep-alive
transfer-encoding: chunked

4
TEST

After that it simply hangs, and sometimes it ends at print 4 and sometimes it prints out TEST as well. The 4 which is content-length should not be there, you write it to socket by accident I think.

@yawnt yawnt reopened this Sep 15, 2013
@yawnt
Copy link
Contributor

yawnt commented Sep 15, 2013

ok i'll give it better look tomorrow morning.. thanks for taking the time to report this :)

@Rush
Copy link
Contributor Author

Rush commented Sep 16, 2013

Still cannot get it work and it seems like the simplest use case. Could you provide any working single file test that would work as a reverse proxy?

@Rush
Copy link
Contributor Author

Rush commented Sep 17, 2013

I will open a different issue cause I seem to have identified the problem and will specify it there.

@Rush Rush closed this as completed Sep 17, 2013
@mizuiren
Copy link

mizuiren commented Sep 4, 2017

I have the same problem, "http-proxy": "^1.16.2"
the code :
/**************************/
app.get(/.
?\.mp3/, proxyer);

function proxyer(req,res,next){
delete req.headers.host;
return proxy.web(req, res, {target: 'http://fs.open.kugou.com'});
}
/***************************/
It show me log "Error: Can't set headers after they are sent..." while I'm playing mp3 music sometimes.
how to fix it?

More detail on "http://www.mizuiren.com/490.html"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants