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

No data returned from server when using injector #10

Closed
schmich opened this issue Aug 8, 2014 · 3 comments
Closed

No data returned from server when using injector #10

schmich opened this issue Aug 8, 2014 · 3 comments

Comments

@schmich
Copy link

schmich commented Aug 8, 2014

I feel like I'm missing something obvious, but when I use an injector, I'm not receiving data from the server.

I've created a minimal repro at https://github.com/schmich/connect-injector-issue:

git clone https://github.com/schmich/connect-injector-issue
cd connect-injector-issue
npm install
node test
curl -v :9001

The code is simple:

var connect = require('connect');
var http = require('http');
var injector = require('connect-injector');

var rewrite = injector(function(req, res) {
    return true;
  }, function(data, req, res, callback) {
    callback(null, 'rewrite');
  }
);

var app = connect().use(rewrite).use(function(req, res) {
  res.end('test');
});

var port = 9001;
var server = http.createServer(app).listen(port, function() {
  console.log('Listening on port ' + port);
});

On my two machines, I get the following output:

* Adding handle: conn: 0x7f9152804000
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7f9152804000) send_pipe: 1, recv_pipe: 0
* About to connect() to  port 9001 (#0)
*   Trying 127.0.0.1...
* Connected to  (127.0.0.1) port 9001 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.30.0
> Host: :9001
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Fri, 08 Aug 2014 21:22:54 GMT
< Connection: keep-alive
< Transfer-Encoding: chunked
< 
* Connection #0 to host  left intact

curl terminates, so there's no more output. I expect the "rewrite" string to be in the response, but it's not. If I remove the injector, I see the "test" string as expected.

  • Win7 x64 & OSX
  • Node v0.11.12
  • Connect v3.1.0
  • connect-injector v0.4.0

Thanks,
Chris

@daffl
Copy link
Owner

daffl commented Aug 8, 2014

Weird, that seems to be exactly what's being tested in https://github.com/daffl/connect-injector/blob/master/test/injector_tests.js#L53. Could you try adding res.writeHead(200, { 'Content-Type': 'text/plain' }); before res.end? I thought it would do a default writeHead but maybe I'm wrong and the injector is patching the wrong methods.

@schmich
Copy link
Author

schmich commented Aug 9, 2014

Adding writeHead makes no difference, however, this appears to be an issue with the (unstable) version of Node I'm using (v0.11.12).

I tested this on an Ubuntu box with v0.10.30 installed, and everything works as expected.

At this point, I'm guessing it's either a bug in the unstable version of Node, or an intentional breaking change they made. Unfortunately, I don't have the time to investigate further, but I might bring this to the Node team's attention.

Thanks for your help!

@schmich schmich closed this as completed Aug 9, 2014
@daffl
Copy link
Owner

daffl commented Aug 9, 2014

Cool thanks for investigating. I didn't add unstable to the tests but once 0.12 is officially released and the issue still persists I'd probably have to do some more investigating.

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

2 participants