summaryrefslogtreecommitdiffstats
path: root/src/plugins/http_static
diff options
context:
space:
mode:
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 != '.')
0'>340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510