kore

An easy to use, scalable and secure web application framework for writing web APIs in C.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 7bdae240cfa0f34116416b7c01f469425e2a9ea5
parent 948dafb19c7ac3264bd710dbf8ce1b2fd9e4c328
Author: Joris Vink <joris@coders.se>
Date:   Sun, 29 Nov 2015 14:19:44 +0100

Change semantics for http_request_header().

The result returned by this function no longer needs to
be freed by the caller.

Diffstat:
examples/generic/src/example.c | 2--
examples/headers/src/headers.c | 7+++----
examples/sse/src/sse.c | 2--
src/http.c | 5+----
4 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/examples/generic/src/example.c b/examples/generic/src/example.c @@ -73,8 +73,6 @@ serve_style_css(struct http_request *req) tstamp = 0; if (http_request_header(req, "if-modified-since", &date)) { tstamp = kore_date_to_time(date); - kore_mem_free(date); - kore_debug("header was present with %ld", tstamp); } diff --git a/examples/headers/src/headers.c b/examples/headers/src/headers.c @@ -11,12 +11,11 @@ page(struct http_request *req) /* * We'll lookup if the X-Custom-Header is given in the request. * If it is we'll set it as a response header as well. - * The value returned by http_request_header() must be freed. + * + * The value returned by http_request_header() should not be freed. */ - if (http_request_header(req, "x-custom-header", &custom)) { + if (http_request_header(req, "x-custom-header", &custom)) http_response_header(req, "x-custom-header", custom); - kore_mem_free(custom); - } /* Return 200 with "ok\n" to the client. */ http_response(req, 200, "ok\n", 3); diff --git a/examples/sse/src/sse.c b/examples/sse/src/sse.c @@ -177,11 +177,9 @@ check_header(struct http_request *req, const char *name, const char *value) } if (strcmp(hdr, value)) { - kore_mem_free(hdr); http_response(req, 400, NULL, 0); return (KORE_RESULT_ERROR); } - kore_mem_free(hdr); return (KORE_RESULT_OK); } diff --git a/src/http.c b/src/http.c @@ -483,14 +483,11 @@ http_response_stream(struct http_request *req, int status, void *base, int http_request_header(struct http_request *req, const char *header, char **out) { - int r; struct http_header *hdr; TAILQ_FOREACH(hdr, &(req->req_headers), list) { if (!strcasecmp(hdr->header, header)) { - r = strlen(hdr->value) + 1; - *out = kore_malloc(r); - kore_strlcpy(*out, hdr->value, r); + *out = hdr->value; return (KORE_RESULT_OK); } }