diff --git a/count-hosts.js b/count-hosts.js index 555f05f1b1..e4bf3f9b68 100644 --- a/count-hosts.js +++ b/count-hosts.js @@ -1,12 +1,12 @@ function Process(request) { log("Processing " + request.path + ". method: " + request.method); + // sends null on the last chunk. request.onBody = function (chunk) { - log("body chunk: " + chunk); + log("body chunk: '" + chunk + "'"); } + request.respond("HTTP/1.0 200 OK\r\n") request.respond("Content-Type: text-plain\r\nContent-Length: 6\r\n\r\nhello\n"); - /* - request.response_complete(); - */ + request.respond(null); // eof } diff --git a/http_request.h b/http_request.h index 3c679dfea5..5564315593 100644 --- a/http_request.h +++ b/http_request.h @@ -21,11 +21,12 @@ public: class HttpRequest { public: - HttpRequest (Connection &c) : connection(c) { ebb_request_init(&parser_info); } + HttpRequest (Connection &c) : connection(c) + { + ebb_request_init(&parser_info); + } ~HttpRequest() { } - const string& Path () { return path; } - string path; Connection &connection; diff --git a/js_http_request_processor.cc b/js_http_request_processor.cc index d269ce3e96..af2f6caf3e 100644 --- a/js_http_request_processor.cc +++ b/js_http_request_processor.cc @@ -387,8 +387,7 @@ Handle JsHttpRequestProcessor::GetPath ) { HttpRequest* request = UnwrapRequest(info.Holder()); - const string& path = request->Path(); - return String::New(path.c_str(), path.length()); + return String::New(request->path.c_str(), request->path.length()); } Handle JsHttpRequestProcessor::GetMethod @@ -426,12 +425,25 @@ Handle JsHttpRequestProcessor::RespondCallback if (args.Length() < 1) return v8::Undefined(); HandleScope scope; Handle arg = args[0]; - Local s = arg->ToString(); - oi_buf *buf = oi_buf_new2(s->Length()); - s->WriteAscii(buf->base); + // TODO Make sure that we write reponses in the correct order. With + // keep-alive it's possible that one response can return before the last + // one has been sent!!! - oi_socket_write(&request->connection.socket, buf); + if(arg == Null()) { + + request->connection.socket.on_drain = oi_socket_close; + + } else { + + Local s = arg->ToString(); + + oi_buf *buf = oi_buf_new2(s->Length()); + s->WriteAscii(buf->base); + + oi_socket_write(&request->connection.socket, buf); + + } return v8::Undefined(); }