Fix pipelined requests with content-length header. #1

Merged
merged 1 commit into from Nov 12, 2011

Projects

None yet

2 participants

@sethml
Contributor
sethml commented Nov 11, 2011

When a request includes a Content-length header, it does not include a
terminating CRLF after the content - the next request begins immediately.
This change prevents us from misparsing the next request.

My brain's parser is not RFC-compliant enough to manage to extract this information from the RFC, but a quick test with each of Chrome 15, FireFox 8, and Safari 5 show this behavior, so I'm reasonably confident that it's correct.

@sethml sethml Fix pipelined requests with content-length header.
When a request includes a Content-length header, it does not include a
terminating CRLF after the content - the next request begins immediately.
This change prevents us from misparsing the next request.
e65957e
@sethml
Contributor
sethml commented Nov 11, 2011

For posterity, here's my little test script - save this in a .html file, then point the browser to it with a file: URL:

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<script>
  for (var i = 0; i < 10; ++i) {
    $.post('http://localhost:8888/', '0123456789');
  }
</script>
</body>
</html>

Here's the node server side:

var http = require('http');
var debug = require('util').debug; 

var server = http.createServer();
var connectionCount = 0;
server.on('connection', function(socket) {
  var connectionNumber = connectionCount++;
  debug('connection ' + connectionNumber);
  socket.on('data', function(chunk) {
    debug(connectionNumber + ' Got chunk: ' + chunk.toString());
  });
  socket.on('end', function() {
    debug(connectionNumber + ' Socket end.');
  });
});
server.on('request', function(req, res) {
  res.end('response!');
});
server.listen(8888);
@substack substack merged commit e65957e into substack:master Nov 12, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment