Browse Source

Move request parser data into connection struct

personal/stbuehler/wip
Stefan Bühler 14 years ago
parent
commit
36b0ae3628
  1. 1
      src/base.h
  2. 8
      src/connection.c
  3. 2
      src/connection.h
  4. 8
      src/request.c
  5. 4
      src/request.h

1
src/base.h

@ -44,6 +44,7 @@ typedef struct connection connection;
#include "plugin.h"
#include "request.h"
#include "response.h"
#include "virtualrequest.h"
#include "log.h"
#include "connection.h"

8
src/connection.c

@ -159,9 +159,10 @@ connection* connection_new(worker *wrk) {
con->options = g_slice_copy(srv->option_count * sizeof(*srv->option_def_values), srv->option_def_values);
request_init(&con->request, con->raw_in);
request_init(&con->request);
physical_init(&con->physical);
response_init(&con->response);
http_request_parser_init(&con->req_parser_ctx, &con->request, con->raw_in);
con->keep_alive_data.link = NULL;
con->keep_alive_data.timeout = 0;
@ -203,6 +204,7 @@ void connection_reset(connection *con) {
request_reset(&con->request);
physical_reset(&con->physical);
response_reset(&con->response);
http_request_parser_reset(&con->req_parser_ctx);
if (con->keep_alive_data.link) {
g_queue_delete_link(&con->wrk->keep_alive_queue, con->keep_alive_data.link);
@ -256,6 +258,7 @@ void connection_reset_keep_alive(connection *con) {
request_reset(&con->request);
physical_reset(&con->physical);
response_reset(&con->response);
http_request_parser_reset(&con->req_parser_ctx);
}
void connection_free(connection *con) {
@ -287,6 +290,7 @@ void connection_free(connection *con) {
request_clear(&con->request);
physical_clear(&con->physical);
response_clear(&con->response);
http_request_parser_clear(&con->req_parser_ctx);
if (con->keep_alive_data.link && con->wrk) {
g_queue_delete_link(&con->wrk->keep_alive_queue, con->keep_alive_data.link);
@ -341,7 +345,7 @@ void connection_state_machine(connection *con) {
if (CORE_OPTION(CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) {
CON_TRACE(con, "%s", "reading request header");
}
switch(http_request_parse(con, &con->request.parser_ctx)) {
switch(http_request_parse(con, &con->req_parser_ctx)) {
case HANDLER_FINISHED:
case HANDLER_GO_ON:
connection_set_state(con, CON_STATE_VALIDATE_REQUEST_HEADER);

2
src/connection.h

@ -82,8 +82,8 @@ struct connection {
request request;
physical physical;
response response;
http_request_ctx req_parser_ctx;
plugin *content_handler;

8
src/request.c

@ -3,7 +3,7 @@
#include "url_parser.h"
#include "utils.h"
void request_init(request *req, chunkqueue *in) {
void request_init(request *req) {
req->http_method = HTTP_METHOD_UNSET;
req->http_method_str = g_string_sized_new(0);
req->http_version = HTTP_VERSION_UNSET;
@ -18,8 +18,6 @@ void request_init(request *req, chunkqueue *in) {
req->headers = http_headers_new();
req->content_length = -1;
http_request_parser_init(&req->parser_ctx, req, in);
}
void request_reset(request *req) {
@ -37,8 +35,6 @@ void request_reset(request *req) {
http_headers_reset(req->headers);
req->content_length = -1;
http_request_parser_reset(&req->parser_ctx);
}
void request_clear(request *req) {
@ -56,8 +52,6 @@ void request_clear(request *req) {
http_headers_free(req->headers);
req->content_length = -1;
http_request_parser_clear(&req->parser_ctx);
}
/* closes connection after response */

4
src/request.h

@ -79,14 +79,12 @@ struct request {
http_headers *headers;
/* Parsed headers: */
goffset content_length;
http_request_ctx parser_ctx;
};
#include "base.h"
LI_API void request_init(request *req, chunkqueue *in);
LI_API void request_init(request *req);
LI_API void request_reset(request *req);
LI_API void request_clear(request *req);

Loading…
Cancel
Save