commit edd7a1077372d8df5ac3fa0656c96072d7808ccc
parent 175b2e2c9bc8e4cfdf5cb3b2d7978db966718dae
Author: Joris Vink <joris@coders.se>
Date: Wed, 8 Mar 2017 10:20:53 +0100
move static assets to use asset_serve_* in generic.
note that certain browsers change their caching behaviour when you
are connecting over TLS using self-signed certificates.
reminded by #179
Diffstat:
3 files changed, 8 insertions(+), 62 deletions(-)
diff --git a/examples/generic/conf/build.conf b/examples/generic/conf/build.conf
@@ -6,6 +6,10 @@ cflags=-Wall -Wmissing-declarations -Wshadow
cflags=-Wstrict-prototypes -Wmissing-prototypes
cflags=-Wpointer-arith -Wcast-qual -Wsign-compare
+mime_add=jpg:image/jpg
+mime_add=css:text/css; charset=utf-8
+mime_add=html:text/html; charset=utf-8
+
dev {
# These cflags are added to the shared ones when
# you build the "dev" flavor.
diff --git a/examples/generic/conf/generic.conf b/examples/generic/conf/generic.conf
@@ -25,16 +25,16 @@ domain 127.0.0.1 {
certkey cert/key.pem
accesslog kore_access.log
- static /css/style.css serve_style_css
- static / serve_index
- static /intro.jpg serve_intro
+ static /css/style.css asset_serve_style_css
+ static / asset_serve_index_html
+ static /intro.jpg asset_serve_intro_jpg
static /b64test serve_b64test
static /upload serve_file_upload
static /validator serve_validator
static /params-test serve_params_test
static /private serve_private
- static /private/test serve_private_test auth_example
+ static /private/test asset_serve_private_test_html auth_example
params post /params-test {
validate test1 v_example
diff --git a/examples/generic/src/example.c b/examples/generic/src/example.c
@@ -27,9 +27,6 @@
int example_load(int);
-int serve_style_css(struct http_request *);
-int serve_index(struct http_request *);
-int serve_intro(struct http_request *);
int serve_b64test(struct http_request *);
int serve_file_upload(struct http_request *);
int serve_validator(struct http_request *);
@@ -74,50 +71,6 @@ example_load(int state)
}
int
-serve_style_css(struct http_request *req)
-{
- char *date;
- time_t tstamp;
-
- tstamp = 0;
- if (http_request_header(req, "if-modified-since", &date)) {
- tstamp = kore_date_to_time(date);
- kore_debug("header was present with %ld", tstamp);
- }
-
- if (tstamp != 0 && tstamp <= asset_mtime_style_css) {
- http_response(req, 304, NULL, 0);
- } else {
- date = kore_time_to_date(asset_mtime_style_css);
- if (date != NULL)
- http_response_header(req, "last-modified", date);
-
- http_response_header(req, "content-type", "text/css");
- http_response(req, 200, asset_style_css, asset_len_style_css);
- }
-
- return (KORE_RESULT_OK);
-}
-
-int
-serve_index(struct http_request *req)
-{
- http_response_header(req, "content-type", "text/html");
- http_response(req, 200, asset_index_html, asset_len_index_html);
-
- return (KORE_RESULT_OK);
-}
-
-int
-serve_intro(struct http_request *req)
-{
- http_response_header(req, "content-type", "image/jpg");
- http_response(req, 200, asset_intro_jpg, asset_len_intro_jpg);
-
- return (KORE_RESULT_OK);
-}
-
-int
serve_b64test(struct http_request *req)
{
int i;
@@ -316,17 +269,6 @@ serve_private(struct http_request *req)
}
int
-serve_private_test(struct http_request *req)
-{
- http_response_header(req, "content-type", "text/html");
-
- http_response(req, 200, asset_private_test_html,
- asset_len_private_test_html);
-
- return (KORE_RESULT_OK);
-}
-
-int
v_example_func(struct http_request *req, char *data)
{
kore_log(LOG_NOTICE, "v_example_func called");