From 0ef5c99973f3596a481457e1d79e63e65ffc887f Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 20 May 2009 10:17:07 +0200 Subject: [PATCH] Add http.ServerRequest.setBodyEncoding. Needs test still. --- src/http.cc | 16 +--------------- src/http.js | 3 +++ test/test-http-server.js | 3 ++- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/http.cc b/src/http.cc index 4ebc639..936dcf3 100644 --- a/src/http.cc +++ b/src/http.cc @@ -225,24 +225,10 @@ HTTPConnection::on_body (http_parser *parser, const char *buf, size_t len) if (on_body_v->IsFunction() == false) return 0; Handle on_body = Handle::Cast(on_body_v); - /* Look at the value of message_handler.encoding to decide how to - * send the body chunk. This is rather sloppy and unnecesary. FIXME - */ - enum encoding encoding = RAW; - Local encoding_v = message_handler->Get(ENCODING_SYMBOL); - if (encoding_v->IsString()) { - Local encoding_string = encoding_v->ToString(); - char buf[5]; // need enough room for "utf8" or "raw" - encoding_string->WriteAscii(buf, 0, 4); - buf[4] = '\0'; - if(strcasecmp(buf, "utf8") == 0) - encoding = UTF8; - } - Handle argv[1]; // TODO each message should have their encoding. // don't look at the conneciton for encoding - if(encoding == UTF8) { + if (connection->encoding_ == UTF8) { // utf8 encoding Handle chunk = String::New((const char*)buf, len); argv[0] = chunk; diff --git a/src/http.js b/src/http.js index 8e5cfca..c1b51a8 100644 --- a/src/http.js +++ b/src/http.js @@ -265,6 +265,9 @@ node.http.Server = function (RequestHandler, options) { , headers : [] // at onHeaderField, onHeaderValue , onBody : null // by user , onBodyComplete : null // by user + , setBodyEncoding : function (enc) { + connection.setEncoding(enc); + } } var res = new node.http.ServerResponse(connection, responses); diff --git a/test/test-http-server.js b/test/test-http-server.js index 59300cf..a813d0a 100644 --- a/test/test-http-server.js +++ b/test/test-http-server.js @@ -35,6 +35,7 @@ function onLoad() { }).listen(port); var c = new node.tcp.Connection(); + c.setEncoding("utf8"); var req_sent = 0; c.onConnect = function () { //puts("send get"); @@ -45,7 +46,7 @@ function onLoad() { c.onReceive = function (chunk) { //puts("client recv"); - total += chunk.encodeUtf8(); + total += chunk; puts("total: " + JSON.stringify(total)); if ( req_sent == 1) { -- 2.7.4