Add http.ServerRequest.setBodyEncoding. Needs test still.
authorRyan <ry@tinyclouds.org>
Wed, 20 May 2009 08:17:07 +0000 (10:17 +0200)
committerRyan <ry@tinyclouds.org>
Wed, 20 May 2009 08:17:07 +0000 (10:17 +0200)
src/http.cc
src/http.js
test/test-http-server.js

index 4ebc639..936dcf3 100644 (file)
@@ -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<Function> on_body = Handle<Function>::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<Value> encoding_v = message_handler->Get(ENCODING_SYMBOL);
-  if (encoding_v->IsString()) {
-    Local<String> 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<Value> 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<String> chunk = String::New((const char*)buf, len);
     argv[0] = chunk;
index 8e5cfca..c1b51a8 100644 (file)
@@ -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);
 
index 59300cf..a813d0a 100644 (file)
@@ -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) {