aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/http_static
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2019-04-25 16:50:21 -0400
committerFlorin Coras <florin.coras@gmail.com>2019-04-25 22:02:00 +0000
commitb62b549b5531fe1f274d6f0ccdc76683d945e165 (patch)
tree56a4228613d44d0b55f68090222136556a212fda /src/plugins/http_static
parent746dddc553d7ecf77880525ef875a00a77f6cb9c (diff)
Clean up redirects
Both firefox and chrome seem happy to browse a hugo-generated site Change-Id: Id216ad9c781643df42ac4fbce598eb2afa600f4d Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src/plugins/http_static')
-rw-r--r--src/plugins/http_static/static_server.c71
1 files changed, 50 insertions, 21 deletions
diff --git a/src/plugins/http_static/static_server.c b/src/plugins/http_static/static_server.c
index 970db0d6798..ac07f6f5534 100644
--- a/src/plugins/http_static/static_server.c
+++ b/src/plugins/http_static/static_server.c
@@ -646,8 +646,14 @@ find_end:
}
}
- /* Now we can construc the file to open */
- path = format (0, "%s/%s%c", hsm->www_root, request, 0);
+ /*
+ * Now we can construct the file to open
+ * Browsers are capable of sporadically including a leading '/'
+ */
+ if (request[0] == '/')
+ path = format (0, "%s%s%c", hsm->www_root, request, 0);
+ else
+ path = format (0, "%s/%s%c", hsm->www_root, request, 0);
if (0)
clib_warning ("GET '%s'", path);
@@ -688,43 +694,41 @@ find_end:
vec_delete (path, vec_len (hsm->www_root) - 1, 0);
- if (0)
- clib_warning ("redirect to '%s'", path);
tc = session_get_transport (s);
redirect = format (0, "HTTP/1.1 301 Moved Permanently\r\n"
- "Location: http://%U/%s",
+ "Location: http://%U%s\r\n"
+ "Connection: close\r\n",
format_ip46_address, &tc->lcl_ip, tc->is_ip4,
path);
+ if (0)
+ clib_warning ("redirect: %s", redirect);
+
static_send_data (hs, redirect, vec_len (redirect), 0);
- vec_free (path);
+ hs->session_state = HTTP_STATE_RESPONSE_SENT;
+ hs->path = 0;
vec_free (redirect);
+ vec_free (path);
goto close_session;
}
}
}
- hs->path = path;
- /* send 200 OK first */
-
- static_send_data (hs, (u8 *) "HTTP/1.1 200 OK\r\n", 17, 0);
- hs->session_state = HTTP_STATE_OK_SENT;
- goto postpone;
-
-static_send_response:
-
- ASSERT (hs->path);
-
/* find or read the file if we haven't done so yet. */
if (hs->data == 0)
{
BVT (clib_bihash_kv) kv;
file_data_cache_t *dp;
+ hs->path = path;
+
/* First, try the cache */
kv.key = (u64) hs->path;
if (BV (clib_bihash_search) (&hsm->name_to_data, &kv, &kv) == 0)
{
+ if (0)
+ clib_warning ("lookup '%s' returned %lld", kv.key, kv.value);
+
/* found the data.. */
dp = pool_elt_at_index (hsm->cache_pool, kv.value);
hs->data = dp->data;
@@ -738,6 +742,8 @@ static_send_response:
}
else
{
+ if (0)
+ clib_warning ("lookup '%s' failed", kv.key, kv.value);
/* Need to recycle one (or more cache) entries? */
if (hsm->cache_size > hsm->cache_limit)
{
@@ -754,16 +760,25 @@ static_send_response:
if (0)
clib_warning ("index %d in use refcnt %d",
dp - hsm->cache_pool, dp->inuse);
- continue;
+
}
+ kv.key = (u64) (dp->filename);
+ kv.value = ~0ULL;
+ if (BV (clib_bihash_add_del) (&hsm->name_to_data, &kv,
+ 0 /* is_add */ ) < 0)
+ {
+ clib_warning ("LRU delete '%s' FAILED!", dp->filename);
+ }
+ else if (0)
+ clib_warning ("LRU delete '%s' ok", dp->filename);
- BV (clib_bihash_add_del) (&hsm->name_to_data, &kv,
- 0 /* is_add */ );
lru_remove (hsm, dp);
hsm->cache_size -= vec_len (dp->data);
hsm->cache_evictions++;
vec_free (dp->filename);
vec_free (dp->data);
+ if (0)
+ clib_warning ("pool put index %d", dp - hsm->cache_pool);
pool_put (hsm->cache_pool, dp);
if (hsm->cache_size < hsm->cache_limit)
break;
@@ -793,12 +808,26 @@ static_send_response:
kv.key = (u64) vec_dup (hs->path);
kv.value = dp - hsm->cache_pool;
/* Add to the lookup table */
- BV (clib_bihash_add_del) (&hsm->name_to_data, &kv, 1 /* is_add */ );
+ if (0)
+ clib_warning ("add '%s' value %lld", kv.key, kv.value);
+
+ if (BV (clib_bihash_add_del) (&hsm->name_to_data, &kv,
+ 1 /* is_add */ ) < 0)
+ {
+ clib_warning ("BUG: add failed!");
+ }
hsm->cache_size += vec_len (dp->data);
}
hs->data_offset = 0;
}
+ /* send 200 OK first */
+ static_send_data (hs, (u8 *) "HTTP/1.1 200 OK\r\n", 17, 0);
+ hs->session_state = HTTP_STATE_OK_SENT;
+ goto postpone;
+
+static_send_response:
+
/* What kind of dog food are we serving? */
suffix = (char *) (hs->path + vec_len (hs->path) - 1);
while (*suffix != '.')