request.respond(null) sends eof

This commit is contained in:
Ryan 2009-02-22 18:15:18 +01:00
Родитель 096384ad58
Коммит 90ea571602
3 изменённых файлов: 26 добавлений и 13 удалений

Просмотреть файл

@ -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
}

Просмотреть файл

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

Просмотреть файл

@ -387,8 +387,7 @@ Handle<Value> 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<Value> JsHttpRequestProcessor::GetMethod
@ -426,12 +425,25 @@ Handle<Value> JsHttpRequestProcessor::RespondCallback
if (args.Length() < 1) return v8::Undefined();
HandleScope scope;
Handle<Value> arg = args[0];
Local<String> 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<String> 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();
}