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 4ecfd81e6ec62cdf3e44341aaaa5589acd80f5c9
parent a39040ba9b3351aa682c906a7dc668caf2192582
Author: Joris Vink <joris@coders.se>
Date:   Wed,  1 May 2013 16:51:34 +0200

allow us to pass content-type to http_response()

Diffstat:
example.conf | 2+-
includes/http.h | 2+-
src/http.c | 10+++++++---
3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/example.conf b/example.conf @@ -8,5 +8,5 @@ load ../betrippin/betrippin.module # Declare page handlers below. # handler path module_callback -static /css/style.css betrippin_serve_style_css +static /css/main.css betrippin_serve_style_css static / betrippin_serve_index diff --git a/includes/http.h b/includes/http.h @@ -32,7 +32,7 @@ void http_init(void); void http_process(void); void http_request_free(struct http_request *); int http_response(struct http_request *, int, - u_int8_t *, u_int32_t); + u_int8_t *, u_int32_t, char *); int http_new_request(struct connection *, struct spdy_stream *, char *, char *, char *); diff --git a/src/http.c b/src/http.c @@ -77,7 +77,8 @@ http_request_free(struct http_request *req) } int -http_response(struct http_request *req, int status, u_int8_t *d, u_int32_t len) +http_response(struct http_request *req, int status, u_int8_t *d, + u_int32_t len, char *content_type) { u_int32_t hlen; u_int8_t *htext; @@ -91,7 +92,10 @@ http_response(struct http_request *req, int status, u_int8_t *d, u_int32_t len) hblock = spdy_header_block_create(SPDY_HBLOCK_NORMAL); spdy_header_block_add(hblock, ":status", sbuf); spdy_header_block_add(hblock, ":version", "HTTP/1.1"); - spdy_header_block_add(hblock, "content-type", "text/plain"); + if (content_type != NULL) { + spdy_header_block_add(hblock, + "content-type", content_type); + } htext = spdy_header_block_release(req->owner, hblock, &hlen); if (htext == NULL) return (KORE_RESULT_ERROR); @@ -155,5 +159,5 @@ http_generic_404(struct http_request *req) kore_log("http_generic_404(%s, %s, %s)", req->host, req->method, req->path); - return (http_response(req, 404, NULL, 0)); + return (http_response(req, 404, NULL, 0, NULL)); }