From 808ba9eae634bb295cd04682f099416541f3cb19 Mon Sep 17 00:00:00 2001 From: Phus Lu Date: Wed, 1 Oct 2014 17:03:27 +0800 Subject: [PATCH] bugfix for index.js --- server/php/index.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/server/php/index.js b/server/php/index.js index 3637833b2..689dcc1f3 100644 --- a/server/php/index.js +++ b/server/php/index.js @@ -56,22 +56,24 @@ function decode_request(data, callback) { request.body = data.slice(2+headers_length); zlib.inflateRaw(data.slice(2, 2+headers_length), function(error, buff) { - lines = buff.toString().split("\r\n"); - request_line_items = lines.shift().split(" "); + var lines = buff.toString().split("\r\n"); + var request_line_items = lines.shift().split(" "); request.method = request_line_items[0]; request.url = request_line_items[1]; - lines.forEach(function(line) { + for (var i = 0; i < lines.length; i++) { + var line = lines[i]; var pos = line.indexOf(':'); if (pos > 0) { var key = line.substring(0, pos); - var value = line.substring(pos+1); - if (key.indexOf('X-URLFETCH-') == 0) { - request.kwargs[key.substring(11)] = value; + var value = line.substring(pos+1).trim(); + if (key.toLowerCase().indexOf('x-urlfetch-') == 0) { + request.kwargs[key.substring(11).toLowerCase()] = value; } else { + key = key.replace(/\w[^\-]*/g, function(w){return w.charAt(0).toUpperCase() + w.substr(1).toLowerCase();}) request.headers[key] = value; } } - }); + } if (request.headers.hasOwnProperty('Content-Encoding') && request.headers['Content-Encoding'] == 'deflate') { zlib.inflateRaw(request.body, function(error, buff) {