kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 966ed3d20db357ccf1b712492efafdb6282d8c7d
parent 0413de6a8fc05cb4694c1bcbd094d46ed0c12dc9
Author: Joris Vink <joris@coders.se>
Date:   Tue,  5 Aug 2014 14:26:31 +0200

Rename the two functions used to read/set headers.

Rename http_request_header_get() to http_request_header().
Rename http_response_header_add() to http_response_header().

Diffstat:
examples/generic/src/example.c | 24++++++++++++------------
examples/headers/src/headers.c | 6+++---
includes/http.h | 4++--
src/auth.c | 6+++---
src/http.c | 15+++++++--------
5 files changed, 27 insertions(+), 28 deletions(-)

diff --git a/examples/generic/src/example.c b/examples/generic/src/example.c @@ -72,7 +72,7 @@ serve_style_css(struct http_request *req) time_t tstamp; tstamp = 0; - if (http_request_header_get(req, "if-modified-since", &date)) { + if (http_request_header(req, "if-modified-since", &date)) { tstamp = kore_date_to_time(date); kore_mem_free(date); @@ -84,9 +84,9 @@ serve_style_css(struct http_request *req) } else { date = kore_time_to_date(asset_mtime_style_css); if (date != NULL) - http_response_header_add(req, "last-modified", date); + http_response_header(req, "last-modified", date); - http_response_header_add(req, "content-type", "text/css"); + http_response_header(req, "content-type", "text/css"); http_response(req, 200, asset_style_css, asset_len_style_css); } @@ -96,7 +96,7 @@ serve_style_css(struct http_request *req) int serve_index(struct http_request *req) { - http_response_header_add(req, "content-type", "text/html"); + http_response_header(req, "content-type", "text/html"); http_response(req, 200, asset_index_html, asset_len_index_html); return (KORE_RESULT_OK); @@ -105,7 +105,7 @@ serve_index(struct http_request *req) int serve_intro(struct http_request *req) { - http_response_header_add(req, "content-type", "image/jpg"); + http_response_header(req, "content-type", "image/jpg"); http_response(req, 200, asset_intro_jpg, asset_len_intro_jpg); return (KORE_RESULT_OK); @@ -125,7 +125,7 @@ serve_b64test(struct http_request *req) data = kore_buf_release(res, &len); - http_response_header_add(req, "content-type", "text/plain"); + http_response_header(req, "content-type", "text/plain"); http_response(req, 200, data, len); kore_mem_free(data); @@ -173,7 +173,7 @@ serve_file_upload(struct http_request *req) d = kore_buf_release(b, &len); - http_response_header_add(req, "content-type", "text/html"); + http_response_header(req, "content-type", "text/html"); http_response(req, 200, d, len); kore_mem_free(d); @@ -281,7 +281,7 @@ serve_params_test(struct http_request *req) else kore_log(LOG_NOTICE, "No id set"); - http_response_header_add(req, "content-type", "text/html"); + http_response_header(req, "content-type", "text/html"); d = kore_buf_release(b, &len); http_response(req, 200, d, len); kore_mem_free(d); @@ -300,7 +300,7 @@ serve_params_test(struct http_request *req) } } - http_response_header_add(req, "content-type", "text/html"); + http_response_header(req, "content-type", "text/html"); d = kore_buf_release(b, &len); http_response(req, 200, d, len); kore_mem_free(d); @@ -311,8 +311,8 @@ serve_params_test(struct http_request *req) int serve_private(struct http_request *req) { - http_response_header_add(req, "content-type", "text/html"); - http_response_header_add(req, "set-cookie", "session_id=test123"); + http_response_header(req, "content-type", "text/html"); + http_response_header(req, "set-cookie", "session_id=test123"); http_response(req, 200, asset_private_html, asset_len_private_html); return (KORE_RESULT_OK); @@ -321,7 +321,7 @@ serve_private(struct http_request *req) int serve_private_test(struct http_request *req) { - http_response_header_add(req, "content-type", "text/html"); + http_response_header(req, "content-type", "text/html"); http_response(req, 200, asset_private_test_html, asset_len_private_test_html); diff --git a/examples/headers/src/headers.c b/examples/headers/src/headers.c @@ -12,13 +12,13 @@ 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_get() must be freed. + * The value returned by http_request_header() must be freed. * * NOTE: All custom headers you set must be in lower case due to * the SPDYv3 specification requiring this. */ - if (http_request_header_get(req, "x-custom-header", &custom)) { - http_response_header_add(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); } diff --git a/includes/http.h b/includes/http.h @@ -201,9 +201,9 @@ char *http_post_data_text(struct http_request *); void http_process_request(struct http_request *, int); u_int8_t *http_post_data_bytes(struct http_request *, u_int32_t *); void http_response(struct http_request *, int, void *, u_int32_t); -int http_request_header_get(struct http_request *, +int http_request_header(struct http_request *, const char *, char **); -void http_response_header_add(struct http_request *, +void http_response_header(struct http_request *, const char *, const char *); int http_request_new(struct connection *, struct spdy_stream *, const char *, const char *, const char *, const char *, diff --git a/src/auth.c b/src/auth.c @@ -92,7 +92,7 @@ kore_auth(struct http_request *req, struct kore_auth *auth) return (KORE_RESULT_ERROR); } - http_response_header_add(req, "location", auth->redirect); + http_response_header(req, "location", auth->redirect); http_response(req, 302, NULL, 0); return (KORE_RESULT_ERROR); @@ -105,7 +105,7 @@ kore_auth_cookie(struct http_request *req, struct kore_auth *auth) size_t len, slen; char *value, *c, *cookie, *cookies[HTTP_MAX_COOKIES]; - if (!http_request_header_get(req, "cookie", &cookie)) + if (!http_request_header(req, "cookie", &cookie)) return (KORE_RESULT_ERROR); slen = strlen(auth->value); @@ -142,7 +142,7 @@ kore_auth_header(struct http_request *req, struct kore_auth *auth) int r; char *header; - if (!http_request_header_get(req, auth->value, &header)) + if (!http_request_header(req, auth->value, &header)) return (KORE_RESULT_ERROR); r = kore_validator_check(req, auth->validator, header); diff --git a/src/http.c b/src/http.c @@ -142,7 +142,7 @@ http_request_new(struct connection *c, struct spdy_stream *s, const char *host, TAILQ_INIT(&(req->files)); if (s != NULL) { - if (!http_request_header_get(req, "user-agent", &(req->agent))) + if (!http_request_header(req, "user-agent", &(req->agent))) req->agent = kore_strdup("unknown"); } @@ -283,12 +283,12 @@ http_process_request(struct http_request *req, int retry_only) } void -http_response_header_add(struct http_request *req, +http_response_header(struct http_request *req, const char *header, const char *value) { struct http_header *hdr; - kore_debug("http_response_header_add(%p, %s, %s)", req, header, value); + kore_debug("http_response_header(%p, %s, %s)", req, header, value); hdr = kore_pool_get(&http_header_pool); hdr->header = kore_strdup(header); @@ -393,8 +393,7 @@ http_response(struct http_request *req, int status, void *d, u_int32_t l) } int -http_request_header_get(struct http_request *req, const char *header, - char **out) +http_request_header(struct http_request *req, const char *header, char **out) { int r; struct http_header *hdr; @@ -520,7 +519,7 @@ http_header_recv(struct netbuf *nb) } if (req->method == HTTP_METHOD_POST) { - if (!http_request_header_get(req, "content-length", &p)) { + if (!http_request_header(req, "content-length", &p)) { kore_debug("POST but no content-length"); req->flags |= HTTP_REQUEST_DELETE; http_error_response(req->owner, NULL, 411); @@ -745,7 +744,7 @@ http_populate_multipart_form(struct http_request *req, int *v) if (req->method != HTTP_METHOD_POST) return (KORE_RESULT_ERROR); - if (!http_request_header_get(req, "content-type", &type)) + if (!http_request_header(req, "content-type", &type)) return (KORE_RESULT_ERROR); h = kore_split_string(type, ";", args, 3); @@ -1101,7 +1100,7 @@ http_response_normal(struct http_request *req, struct connection *c, connection_close = 0; if (connection_close == 0 && req != NULL) { - if (http_request_header_get(req, "connection", &conn)) { + if (http_request_header(req, "connection", &conn)) { if ((*conn == 'c' || *conn == 'C') && !strcasecmp(conn, "close")) connection_close = 1;