Browse Source

request.respond(null) sends eof

v0.7.4-release
Ryan 16 years ago
parent
commit
90ea571602
  1. 8
      count-hosts.js
  2. 7
      http_request.h
  3. 24
      js_http_request_processor.cc

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

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

24
js_http_request_processor.cc

@ -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();
}

Loading…
Cancel
Save