Fix request and parser, added simple request test.

personal/stbuehler/wip
Stefan Bühler 14 years ago
parent a1414bce60
commit cbf88bb3ee
  1. 2
      src/chunk.h
  2. 4
      src/http_request_parser.h
  3. 5
      src/http_request_parser.rl
  4. 1
      src/request.c
  5. 27
      src/tests.c
  6. 1
      src/wscript

@ -15,6 +15,8 @@ typedef struct chunkqueue chunkqueue;
struct chunkiter;
typedef struct chunkiter chunkiter;
#define CONST_STR_LEN(x) x, x ? sizeof(x) - 1 : 0
#include "base.h"
/* Open a file only once, so it shouldn't get lost;

@ -15,4 +15,8 @@ struct http_request_ctx {
request *request;
};
LI_API void http_request_parser_init(http_request_ctx *ctx, request *req, chunkqueue *cq);
LI_API handler_t http_request_parse(server *srv, connection *con, http_request_ctx *ctx);
#endif

@ -37,7 +37,7 @@
HEX = [a-fA-F0-9];
Separators = [()<>@,;:\\\"/\[\]?={}] | SP | HT;
Token = OCTET - Separators - CTL;
Token = (OCTET - Separators - CTL)+;
# original definition
# Comment = "(" ( CText | Quoted_Pair | Comment )* ")";
@ -83,9 +83,10 @@ static int http_request_parser_is_finished(http_request_ctx *ctx) {
return ctx->chunk_ctx.cs >= http_request_parser_first_final;
}
void http_request_parser_init(http_request_ctx *ctx, chunkqueue *cq) {
void http_request_parser_init(http_request_ctx *ctx, request *req, chunkqueue *cq) {
%% write init;
chunk_parser_init(&ctx->chunk_ctx, cq);
ctx->request = req;
}
handler_t http_request_parse(server *srv, connection *con, http_request_ctx *ctx) {

@ -3,6 +3,7 @@
request* request_new() {
request *req = g_slice_new0(request);
return req;
}
void request_free(request *req) {

@ -1,9 +1,34 @@
#include "base.h"
#include "log.h"
#include "http_request_parser.h"
int request_test() {
chunkqueue *cq;
request *req;
http_request_ctx ctx;
handler_t res;
cq = chunkqueue_new();
req = request_new();
http_request_parser_init(&ctx, req, cq);
chunkqueue_append_mem(cq, CONST_STR_LEN(
"GET / HTTP/1.1\r\n"
"\r\n"
));
res = http_request_parse(NULL, NULL, &ctx);
if (res != HANDLER_GO_ON) {
ERROR("Parser return %i", res);
return -1;
}
return 0;
}
int main() {
return 0;
return request_test();
}

@ -16,6 +16,7 @@ common_source='''
http_request_parser.rl
log.c
options.c
request.c
sys-files.c
sys-socket.c
'''

Loading…
Cancel
Save