Skip to content

http/server: request.socket.bytesRead always 0 for IncomingMessage #3021

Description

@skenqbx

Tested with node.js v4.1.0 & v4.1.1 (v0.10.x does not have this issue)

See the following test (parallel/test-http-bytesread.js) to reproduce the issue;

'use strict';varcommon=require('../common');varassert=require('assert');varhttp=require('http');varbody='hello world\n';varsawEnd=false;varbytesReadServer=0;varbytesReadClient=0;process.on('exit',function(){assert(sawEnd);console.log('ok');});varhttpServer=http.createServer(function(req,res){httpServer.close();req.on('readable',function(){vardata=req.read();if(data!==null){bytesReadServer+=data.length;}});req.on('end',function(){assert(bytesReadServer>0);assert(req.socket.bytesRead>0);sawEnd=true;res.writeHead(200,{'Content-Type': 'text/plain'});res.end(body);});});httpServer.listen(common.PORT,function(){varreq=http.request({method: 'PUT',port: common.PORT},function(res){res.on('readable',function(){vardata=res.read();if(data!==null){bytesReadClient+=data.length;}});res.on('end',function(){assert(bytesReadClient>0);assert(res.socket.bytesRead>0);});});varchunk=newArray(1024+1).join('7');varbchunk=newBuffer(chunk);for(vari=0;i<1024;i++){req.write(chunk);req.write(bchunk);req.write(chunk,'hex');}req.end();});

I could not yet figure out what causes this, any help is appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.httpIssues or PRs related to the http subsystem.netIssues and PRs related to the net subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions