0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-29 15:06:33 +01:00

Add http.ServerRequest.setBodyEncoding. Needs test still.

This commit is contained in:
Ryan 2009-05-20 10:17:07 +02:00
parent 1b54e3d87d
commit 0ef5c99973
3 changed files with 6 additions and 16 deletions

View 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;

View 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);

View 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) {