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 cefeaf7992ea0bfa1cb525c921b1645e1864913f
parent 0c4dbad2fb18b8cbcba5e7eea18f0181759afe37
Author: Joris Vink <joris@coders.se>
Date:   Fri, 15 May 2015 19:12:18 +0200

HTTP layer improvements.

Add HTTP_REQUEST_NO_CONTENT_LENGTH which can be set by
a handler before calling http_response() to avoid Kore
from setting the content-length altogether.

If we are on a SPDY connection do not close the stream
if we do not pass data to http_response().

Diffstat:
includes/http.h | 1+
src/http.c | 7+++++--
2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/includes/http.h b/includes/http.h @@ -167,6 +167,7 @@ struct http_file { #define HTTP_REQUEST_PGSQL_QUEUE 0x10 #define HTTP_REQUEST_EXPECT_BODY 0x20 #define HTTP_REQUEST_RETAIN_EXTRA 0x40 +#define HTTP_REQUEST_NO_CONTENT_LENGTH 0x80 struct kore_task; diff --git a/src/http.c b/src/http.c @@ -1209,7 +1209,9 @@ http_response_spdy(struct http_request *req, struct connection *c, if (d != NULL) net_send_queue(c, d, len, s, NETBUF_LAST_CHAIN); - } else { + } + + if (req->method == HTTP_METHOD_HEAD) { spdy_frame_send(c, SPDY_DATA_FRAME, FLAG_FIN, 0, s, 0); spdy_stream_close(c, s, SPDY_KEEP_NETBUFS); } @@ -1266,7 +1268,8 @@ http_response_normal(struct http_request *req, struct connection *c, } } - if (status != 204 && status >= 200) + if (status != 204 && status >= 200 && + !(req->flags & HTTP_REQUEST_NO_CONTENT_LENGTH)) kore_buf_appendf(header_buf, "content-length: %d\r\n", len); kore_buf_append(header_buf, "\r\n", 2);