From 8c4f6de533ac4a399385239ebfd538514a6fb643 Mon Sep 17 00:00:00 2001 From: Christos Tsantilas Date: Fri, 28 Jan 2011 20:35:12 +0200 Subject: [PATCH] Try to return a template error page. Also return 404 error code --- src/mgr/Inquirer.cc | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/mgr/Inquirer.cc b/src/mgr/Inquirer.cc index 1c8b5bbc1f..8b9c54b8aa 100644 --- a/src/mgr/Inquirer.cc +++ b/src/mgr/Inquirer.cc @@ -10,6 +10,7 @@ #include "comm/Write.h" #include "CommCalls.h" #include "HttpReply.h" +#include "HttpRequest.h" #include "ipc/Coordinator.h" #include "mgr/ActionWriter.h" #include "mgr/Command.h" @@ -18,6 +19,7 @@ #include "mgr/Request.h" #include "mgr/Response.h" #include "SquidTime.h" +#include "errorpage.h" #include #include @@ -82,11 +84,23 @@ Mgr::Inquirer::start() debugs(16, 5, HERE); Must(fd >= 0); Must(aggrAction != NULL); - - std::auto_ptr reply(new HttpReply); - reply->setHeaders(strands.empty() ? HTTP_BAD_REQUEST : HTTP_OK, NULL, "text/plain", -1, squid_curtime, squid_curtime); - reply->header.putStr(HDR_CONNECTION, "close"); // until we chunk response - std::auto_ptr replyBuf(reply->pack()); + + std::auto_ptr replyBuf; + if (strands.empty()) { + LOCAL_ARRAY(char, url, MAX_URL); + snprintf(url, MAX_URL, "%s", aggrAction->command().params.httpUri.termedBuf()); + HttpRequest *req = HttpRequest::CreateFromUrl(url); + ErrorState *err = errorCon(ERR_INVALID_URL, HTTP_NOT_FOUND, req); + std::auto_ptr reply(err->BuildHttpReply()); + replyBuf.reset(reply->pack()); + errorStateFree(err); + } + else { + std::auto_ptr reply(new HttpReply); + reply->setHeaders(HTTP_OK, NULL, "text/plain", -1, squid_curtime, squid_curtime); + reply->header.putStr(HDR_CONNECTION, "close"); // until we chunk response + replyBuf.reset(reply->pack()); + } writer = asyncCall(16, 5, "Mgr::Inquirer::noteWroteHeader", CommCbMemFunT(this, &Inquirer::noteWroteHeader)); Comm::Write(fd, replyBuf.get(), writer); -- 2.47.2