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 $<
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 $@
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
#include <map>
#include "js_http_request_processor.h"
+#include <oi_buf.h>
using namespace std;
using namespace v8;
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
(
// 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);