improvement to AbstractHTTPRequestHandler

This commit is contained in:
Guenter Obiltschnig 2007-04-27 15:19:33 +00:00
parent 4d80e24d44
commit d30a402069
2 changed files with 25 additions and 3 deletions

View File

@ -1,7 +1,7 @@
//
// AbstractHTTPRequestHandler.h
//
// $Id: //poco/Main/Net/include/Poco/Net/AbstractHTTPRequestHandler.h#2 $
// $Id: //poco/Main/Net/include/Poco/Net/AbstractHTTPRequestHandler.h#3 $
//
// Library: Net
// Package: HTTPServer
@ -83,6 +83,10 @@ public:
/// - call authorize();
/// - if authorize() returns true call run(),
/// else send 401 (Unauthorized) response.
///
/// If run() throws an exception and the response has not been
/// sent yet, sends a 500 (Internal Server Error) response with
/// the exception's display text.
HTTPServerRequest& request();
/// Returns the request.

View File

@ -1,7 +1,7 @@
//
// AbstractHTTPRequestHandler.cpp
//
// $Id: //poco/Main/Net/src/AbstractHTTPRequestHandler.cpp#3 $
// $Id: //poco/Main/Net/src/AbstractHTTPRequestHandler.cpp#4 $
//
// Library: Net
// Package: HTTPServer
@ -39,6 +39,7 @@
#include "Poco/Net/HTTPServerResponse.h"
#include "Poco/Net/HTMLForm.h"
#include "Poco/NumberFormatter.h"
#include "Poco/Exception.h"
using Poco::NumberFormatter;
@ -67,9 +68,26 @@ void AbstractHTTPRequestHandler::handleRequest(HTTPServerRequest& request, HTTPS
_pRequest = &request;
_pResponse = &response;
if (authenticate())
{
try
{
run();
}
catch (Poco::Exception& exc)
{
if (!response.sent())
{
sendErrorResponse(HTTPResponse::HTTP_INTERNAL_SERVER_ERROR, exc.displayText());
}
}
catch (std::exception& exc)
{
if (!response.sent())
{
sendErrorResponse(HTTPResponse::HTTP_INTERNAL_SERVER_ERROR, exc.what());
}
}
}
else
{
sendErrorResponse(HTTPResponse::HTTP_UNAUTHORIZED, "");