Skip to content
This repository has been archived by the owner. It is now read-only.

Gather all chunks of POST body before splitting #6

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Gather all chunks of POST body before splitting.

The boundary between chunks is not guaranteed to fall at the end of a PUTVAL line.

The worst possible place this boundary can fall is in the value.  In this case, the truncated line will pass putval_re and be loaded into Graphite with an incorrect value.
  • Loading branch information
rcrowley committed Feb 16, 2012
commit 633d977a613770032a65521a5c085d5db7a5d3da
@@ -58,8 +58,17 @@ graphite_connection.on("error", function() {

var request_handler = function(request, response) {
var putval_re = /^PUTVAL ([^ ]+)(?: ([^ ]+=[^ ]+)?) ([0-9.]+)(:.*)/;
var chunks = [];
request.addListener("data", function(chunk) {
metrics = chunk.toString().split("\n");
chunks.push(chunk.toString());
});
request.addListener("end", function(chunk) {
var body = chunks.join("");
if (parseInt(request.headers["content-length"]) != body.length) {
console.log("Content-Length: %d != body.length: %d\n",
request.headers["content-length"], body.length);
}
var metrics = body.split("\n");
for (var i in metrics) {
var m = putval_re.exec(metrics[i]);
if (!m) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.