diff --git a/Makefile b/Makefile index 700b9502d5..2519fffed2 100644 --- a/Makefile +++ b/Makefile @@ -10,8 +10,8 @@ ifdef EVDIR LDFLAGS += -L$(EVDIR)/lib endif -server: js_http_request_processor.o server.o oi_socket.o ebb_request_parser.o - g++ -o server $^ $(LDFLAGS) $(V8LIB) +server: js_http_request_processor.o server.o oi_socket.o ebb_request_parser.o oi_buf.o + g++ -o server $^ $(LDFLAGS) $(V8LIB) server.o: server.cc g++ $(CFLAGS) -c $< @@ -20,7 +20,7 @@ js_http_request_processor.o: js_http_request_processor.cc g++ $(CFLAGS) -c $< ebb_request_parser.o: ebb_request_parser.c deps/ebb/ebb_request_parser.h - gcc $(CFLAGS) -c $< + g++ $(CFLAGS) -c $< ebb_request_parser.c: deps/ebb/ebb_request_parser.rl ragel -s -G2 $< -o $@ @@ -28,6 +28,9 @@ ebb_request_parser.c: deps/ebb/ebb_request_parser.rl oi_socket.o: deps/oi/oi_socket.c deps/oi/oi_socket.h gcc $(CFLAGS) -c $< +oi_buf.o: deps/oi/oi_buf.c deps/oi/oi_buf.h + gcc $(CFLAGS) -c $< + clean: rm -f ebb_request_parser.c rm -f *.o diff --git a/count-hosts.js b/count-hosts.js index 0a16d90b94..555f05f1b1 100644 --- a/count-hosts.js +++ b/count-hosts.js @@ -1,11 +1,12 @@ function Process(request) { log("Processing " + request.path + ". method: " + request.method); - /* request.onBody = function (chunk) { log("body chunk: " + chunk); } - request.respond("HTTP/1.1 200 OK\r\nContent-Type: text-plain\r\n\r\nhello"); - request.response_complete + 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(); */ } diff --git a/deps/ebb b/deps/ebb index 6460653599..a919b9a4ef 160000 --- a/deps/ebb +++ b/deps/ebb @@ -1 +1 @@ -Subproject commit 646065359957956c9a0a611aa91ee79fb4928e6d +Subproject commit a919b9a4ef5d1f293bb1039357fb5acf103a09ad diff --git a/deps/oi b/deps/oi index 988d979486..4a27352d40 160000 --- a/deps/oi +++ b/deps/oi @@ -1 +1 @@ -Subproject commit 988d97948634359cf2a6740dd5228c69a27015ae +Subproject commit 4a27352d40d9524dcd221ae612de5abc133bf616 diff --git a/js_http_request_processor.cc b/js_http_request_processor.cc index 46fed66379..d269ce3e96 100644 --- a/js_http_request_processor.cc +++ b/js_http_request_processor.cc @@ -33,6 +33,7 @@ #include #include "js_http_request_processor.h" +#include using namespace std; using namespace v8; @@ -398,25 +399,43 @@ Handle JsHttpRequestProcessor::GetMethod HttpRequest* request = UnwrapRequest(info.Holder()); // TODO allocate these strings only once. reference global switch(request->parser_info.method) { - case ebb_request::EBB_COPY: return String::New("COPY"); - case ebb_request::EBB_DELETE: return String::New("DELETE"); - case ebb_request::EBB_GET: return String::New("GET"); - case ebb_request::EBB_HEAD: return String::New("HEAD"); - case ebb_request::EBB_LOCK: return String::New("LOCK"); - case ebb_request::EBB_MKCOL: return String::New("MKCOL"); - case ebb_request::EBB_MOVE: return String::New("MOVE"); - case ebb_request::EBB_OPTIONS: return String::New("OPTIONS"); - case ebb_request::EBB_POST: return String::New("POST"); - case ebb_request::EBB_PROPFIND: return String::New("PROPFIND"); - case ebb_request::EBB_PROPPATCH: return String::New("PROPPATCH"); - case ebb_request::EBB_PUT: return String::New("PUT"); - case ebb_request::EBB_TRACE: return String::New("TRACE"); - case ebb_request::EBB_UNLOCK: return String::New("UNLOCK"); + case EBB_COPY: return String::New("COPY"); + case EBB_DELETE: return String::New("DELETE"); + case EBB_GET: return String::New("GET"); + case EBB_HEAD: return String::New("HEAD"); + case EBB_LOCK: return String::New("LOCK"); + case EBB_MKCOL: return String::New("MKCOL"); + case EBB_MOVE: return String::New("MOVE"); + case EBB_OPTIONS: return String::New("OPTIONS"); + case EBB_POST: return String::New("POST"); + case EBB_PROPFIND: return String::New("PROPFIND"); + case EBB_PROPPATCH: return String::New("PROPPATCH"); + case EBB_PUT: return String::New("PUT"); + case EBB_TRACE: return String::New("TRACE"); + case EBB_UNLOCK: return String::New("UNLOCK"); default: return Null(); } } +Handle JsHttpRequestProcessor::RespondCallback + ( const Arguments& args + ) +{ + HttpRequest* request = UnwrapRequest(args.Holder()); + 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); + + oi_socket_write(&request->connection.socket, buf); + + return v8::Undefined(); +} + Handle JsHttpRequestProcessor::MakeRequestTemplate ( @@ -430,6 +449,7 @@ Handle JsHttpRequestProcessor::MakeRequestTemplate // Add accessors for each of the fields of the request. result->SetAccessor(String::NewSymbol("path"), GetPath); result->SetAccessor(String::NewSymbol("method"), GetMethod); + result->Set(String::New("respond"), FunctionTemplate::New(RespondCallback)); // Again, return the result through the current handle scope. return handle_scope.Close(result); diff --git a/js_http_request_processor.h b/js_http_request_processor.h index b4de2df525..4e1f9c9e12 100644 --- a/js_http_request_processor.h +++ b/js_http_request_processor.h @@ -67,6 +67,7 @@ class JsHttpRequestProcessor : public HttpRequestProcessor { // Callbacks that access the individual fields of request objects. static Handle GetPath (Local name, const AccessorInfo& info); static Handle GetMethod (Local name, const AccessorInfo& info); + static Handle RespondCallback (const Arguments& args); // Callbacks that access maps static Handle MapGet(Local name, const AccessorInfo& info); diff --git a/server.cc b/server.cc index 681eebee11..0523577681 100644 --- a/server.cc +++ b/server.cc @@ -53,7 +53,6 @@ void on_request_complete ) { HttpRequest *request = static_cast (req->data); - oi_socket_close(&request->connection.socket); } ebb_request * on_request