aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-05-20 19:25:16 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2016-05-20 19:27:21 +0200
commite68a315bcf2bd681466c27026fea73598071bda6 (patch)
tree57fb5e32babf8757b00524f9c522c59491501621
parentc044f0961a1c276a13791e7559027505c5292073 (diff)
fix one-page-application redirect
Change-Id: I80c4dbda86cd1bc2847dea5b1dea304f41c551e6 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/afb-hsrv.c17
-rw-r--r--src/afb-hsrv.h2
-rw-r--r--src/main.c4
3 files changed, 18 insertions, 5 deletions
diff --git a/src/afb-hsrv.c b/src/afb-hsrv.c
index 46e61a01..886820d6 100644
--- a/src/afb-hsrv.c
+++ b/src/afb-hsrv.c
@@ -302,6 +302,19 @@ static struct hsrv_handler *new_handler(
return head;
}
+static int handle_alias_relax(struct afb_hreq *hreq, void *data)
+{
+ struct hsrv_alias *da = data;
+
+ if (hreq->method != afb_method_get)
+ return 0;
+
+ if (!afb_hreq_valid_tail(hreq))
+ return 0;
+
+ return afb_hreq_reply_file_if_exist(hreq, da->dirfd, &hreq->tail[1]);
+}
+
static int handle_alias(struct afb_hreq *hreq, void *data)
{
struct hsrv_alias *da = data;
@@ -335,7 +348,7 @@ int afb_hsrv_add_handler(
return 1;
}
-int afb_hsrv_add_alias(struct afb_hsrv *hsrv, const char *prefix, const char *alias, int priority)
+int afb_hsrv_add_alias(struct afb_hsrv *hsrv, const char *prefix, const char *alias, int priority, int relax)
{
struct hsrv_alias *da;
int dirfd;
@@ -351,7 +364,7 @@ int afb_hsrv_add_alias(struct afb_hsrv *hsrv, const char *prefix, const char *al
da->directory = alias;
da->lendir = strlen(da->directory);
da->dirfd = dirfd;
- if (afb_hsrv_add_handler(hsrv, prefix, handle_alias, da, priority))
+ if (afb_hsrv_add_handler(hsrv, prefix, relax ? handle_alias_relax : handle_alias, da, priority))
return 1;
free(da);
}
diff --git a/src/afb-hsrv.h b/src/afb-hsrv.h
index cd9ba019..913de80c 100644
--- a/src/afb-hsrv.h
+++ b/src/afb-hsrv.h
@@ -27,6 +27,6 @@ extern void afb_hsrv_put(struct afb_hsrv *hsrv);
extern void afb_hsrv_stop(struct afb_hsrv *hsrv);
extern int afb_hsrv_start(struct afb_hsrv *hsrv, uint16_t port, unsigned int connection_timeout);
extern int afb_hsrv_set_cache_timeout(struct afb_hsrv *hsrv, int duration);
-extern int afb_hsrv_add_alias(struct afb_hsrv *hsrv, const char *prefix, const char *alias, int priority);
+extern int afb_hsrv_add_alias(struct afb_hsrv *hsrv, const char *prefix, const char *alias, int priority, int relax);
extern int afb_hsrv_add_handler(struct afb_hsrv *hsrv, const char *prefix, int (*handler) (struct afb_hreq *, void *), void *data, int priority);
diff --git a/src/main.c b/src/main.c
index 44580c89..156a77d2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -479,10 +479,10 @@ static int init_http_server(struct afb_hsrv *hsrv, struct afb_config * config)
return 0;
for (idx = 0; idx < config->aliascount; idx++)
- if (!afb_hsrv_add_alias (hsrv, config->aliasdir[idx].url, config->aliasdir[idx].path, 0))
+ if (!afb_hsrv_add_alias (hsrv, config->aliasdir[idx].url, config->aliasdir[idx].path, 0, 0))
return 0;
- if (!afb_hsrv_add_alias(hsrv, "", config->rootdir, -10))
+ if (!afb_hsrv_add_alias(hsrv, "", config->rootdir, -10, 1))
return 0;
if (!afb_hsrv_add_handler(hsrv, config->rootbase, afb_hswitch_one_page_api_redirect, NULL, -20))