diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index 8175a78..56dfd46 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -158,13 +158,14 @@ static int accessHandlerCallback(void *cls, std::string httpRedirection; unsigned int contentLength = 0; bool found = true; + bool cacheEnabled = true; int httpResponseCode = MHD_HTTP_OK; std::string urlStr = string(url); /* Get searcher and reader */ std::string humanReadableBookId = ""; if (!(urlStr.size() > 5 && urlStr.substr(0, 6) == "/skin/")) { - if (!strcmp(url, "/search") || !strcmp(url, "/suggest")) { + if (!strcmp(url, "/search") || !strcmp(url, "/suggest") || !strcmp(url, "/random")) { const char* tmpGetValue = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "content"); humanReadableBookId = (tmpGetValue != NULL ? string(tmpGetValue) : ""); } else { @@ -270,6 +271,18 @@ static int accessHandlerCallback(void *cls, } } + /* Display a random article */ + else if (!strcmp(url, "/random")) { + cacheEnabled = false; + std::string randomUrl; + if (reader != NULL) { + pthread_mutex_lock(&readerLock); + randomUrl = reader->getRandomPageUrl(); + pthread_mutex_unlock(&readerLock); + httpRedirection="/" + humanReadableBookId + "/" + randomUrl; + } + } + /* Display the content of a ZIM article */ else if (reader != NULL) { pthread_mutex_lock(&readerLock); @@ -387,8 +400,16 @@ static int accessHandlerCallback(void *cls, /* Force to close the connection - cf. 100% CPU usage with v. 4.4 (in Lucid) */ MHD_add_response_header(response, MHD_HTTP_HEADER_CONNECTION, "close"); - /* Force cache */ - MHD_add_response_header(response, MHD_HTTP_HEADER_CACHE_CONTROL, "max-age=87840, must-revalidate"); + if(cacheEnabled) + { + /* Force cache */ + MHD_add_response_header(response, MHD_HTTP_HEADER_CACHE_CONTROL, "max-age=87840, must-revalidate"); + } + else + { + /* Prevent cache (for random page) */ + MHD_add_response_header(response, MHD_HTTP_HEADER_CACHE_CONTROL, "no-cache, no-store, must-revalidate"); + } /* Queue the response */ int ret = MHD_queue_response(connection, diff --git a/static/server/taskbar.css b/static/server/taskbar.css index f0b17a2..f75983d 100644 --- a/static/server/taskbar.css +++ b/static/server/taskbar.css @@ -19,6 +19,11 @@ float: left; } +#kiwixrandom { + margin: 0px; + float: left; +} + #kiwixsearchbox { margin: 0px; float: right; diff --git a/static/server/taskbar.html.part b/static/server/taskbar.html.part index 8020c3e..e29e1f9 100644 --- a/static/server/taskbar.html.part +++ b/static/server/taskbar.html.part @@ -18,6 +18,7 @@
+