Browse Source

request.respond works

v0.7.4-release
Ryan 16 years ago
parent
commit
cc1a61c1e7
  1. 9
      Makefile
  2. 7
      count-hosts.js
  3. 2
      deps/ebb
  4. 2
      deps/oi
  5. 48
      js_http_request_processor.cc
  6. 1
      js_http_request_processor.h
  7. 1
      server.cc

9
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

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

2
deps/ebb

@ -1 +1 @@
Subproject commit 646065359957956c9a0a611aa91ee79fb4928e6d
Subproject commit a919b9a4ef5d1f293bb1039357fb5acf103a09ad

2
deps/oi

@ -1 +1 @@
Subproject commit 988d97948634359cf2a6740dd5228c69a27015ae
Subproject commit 4a27352d40d9524dcd221ae612de5abc133bf616

48
js_http_request_processor.cc

@ -33,6 +33,7 @@
#include <map>
#include "js_http_request_processor.h"
#include <oi_buf.h>
using namespace std;
using namespace v8;
@ -398,25 +399,43 @@ Handle<Value> 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<Value> JsHttpRequestProcessor::RespondCallback
( const Arguments& args
)
{
HttpRequest* request = UnwrapRequest(args.Holder());
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);
oi_socket_write(&request->connection.socket, buf);
return v8::Undefined();
}
Handle<ObjectTemplate> JsHttpRequestProcessor::MakeRequestTemplate
(
@ -430,6 +449,7 @@ Handle<ObjectTemplate> 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);

1
js_http_request_processor.h

@ -67,6 +67,7 @@ class JsHttpRequestProcessor : public HttpRequestProcessor {
// Callbacks that access the individual fields of request objects.
static Handle<Value> GetPath (Local<String> name, const AccessorInfo& info);
static Handle<Value> GetMethod (Local<String> name, const AccessorInfo& info);
static Handle<Value> RespondCallback (const Arguments& args);
// Callbacks that access maps
static Handle<Value> MapGet(Local<String> name, const AccessorInfo& info);

1
server.cc

@ -53,7 +53,6 @@ void on_request_complete
)
{
HttpRequest *request = static_cast<HttpRequest*> (req->data);
oi_socket_close(&request->connection.socket);
}
ebb_request * on_request

Loading…
Cancel
Save