From be87195164729c5739bde819af7b771a6f88caee Mon Sep 17 00:00:00 2001 From: =?utf8?q?Luk=C3=A1=C5=A1=20Je=C5=BEek?= Date: Fri, 19 Mar 2021 13:59:01 +0100 Subject: [PATCH] WIP --- daemon/http.c | 12 +++++++++++- daemon/http.h | 2 ++ daemon/worker.c | 3 +++ lib/resolve.h | 2 ++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/daemon/http.c b/daemon/http.c index 39fdcc80c..a28b0438a 100644 --- a/daemon/http.c +++ b/daemon/http.c @@ -321,6 +321,8 @@ static void http_status_reinit(struct http_ctx *ctx, int stream_id) free(ctx->content_type); ctx->content_type = NULL; } + ctx->headers = NULL; + ctx->headers_pool = NULL; } static void http_status_reinit_error(struct http_ctx *ctx, int stream_id) @@ -484,6 +486,10 @@ static int begin_headers_callback(nghttp2_session *h2, const nghttp2_frame *fram } else { ctx->current_stream = set_error_status(ctx, stream_id, 200, NULL); } + + + ctx->headers_pool = mm_ctx_mempool2(MM_DEFAULT_BLKSIZE); + ctx->headers = mm_calloc(&ctx->headers_pool, num_of_headers, sizeof(char*)); return 0; } @@ -511,6 +517,9 @@ static int header_callback(nghttp2_session *h2, const nghttp2_frame *frame, return 0; } + + // TODO: alloc and store headers to ctx->headers array + if (!strcasecmp(":path", (const char *)name)) { int rc = check_uri(ctx, stream_id, (const char *)value); if (rc < 0) { @@ -755,7 +764,8 @@ struct http_ctx* http_new(struct session *session, http_send_callback send_cb) ctx->uri_path = NULL; ctx->content_type = NULL; array_init(ctx->stream_status); - + ctx->headers_pool = NULL; + ctx->headers = NULL; nghttp2_session_server_new(&ctx->h2, callbacks, ctx); nghttp2_submit_settings(ctx->h2, NGHTTP2_FLAG_NONE, diff --git a/daemon/http.h b/daemon/http.h index a82e3a738..47e4ff2ac 100644 --- a/daemon/http.h +++ b/daemon/http.h @@ -54,6 +54,8 @@ struct http_ctx { ssize_t buf_size; array_t(struct http_stream_status*) stream_status; struct http_stream_status *current_stream; + knot_mm_t *headers_pool; + char **headers; }; #if ENABLE_DOH2 diff --git a/daemon/worker.c b/daemon/worker.c index b13bb3911..c135dff71 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -386,8 +386,10 @@ static struct request_ctx *request_create(struct worker_ctx *worker, req->qsource.stream_id = -1; #if ENABLE_DOH2 if (req->qsource.flags.http) { + req->pool_headers = http_ctx->headers_pool; struct http_ctx *http_ctx = session_http_get_server_ctx(session); req->qsource.stream_id = queue_head(http_ctx->streams); + req->qsource.headers = http_ctx->headers; } #endif /* We need to store a copy of peer address. */ @@ -469,6 +471,7 @@ static void request_free(struct request_ctx *ctx) pool_release(worker, ctx->req.pool.ctx); /* @note The 'task' is invalidated from now on. */ worker->stats.rconcurrent -= 1; + // TODO: release pool_headers } static struct qr_task *qr_task_create(struct request_ctx *ctx) diff --git a/lib/resolve.h b/lib/resolve.h index 8f2a3383a..57be4f2e7 100644 --- a/lib/resolve.h +++ b/lib/resolve.h @@ -210,6 +210,7 @@ struct kr_request { struct kr_request_qsource_flags flags; /**< See definition above. */ size_t size; /**< query packet size */ int32_t stream_id; /**< HTTP/2 stream ID for DoH requests */ + char **headers; } qsource; struct { unsigned rtt; /**< Current upstream RTT */ @@ -237,6 +238,7 @@ struct kr_request { trace_callback_f trace_finish; /**< Request finish tracepoint */ int vars_ref; /**< Reference to per-request variable table. LUA_NOREF if not set. */ knot_mm_t pool; + knot_mm_t pool_headers; unsigned int uid; /**< for logging purposes only */ struct { addr_info_f is_tls_capable; -- 2.47.2