mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-18 00:15:27 +01:00
improvement to AbstractHTTPRequestHandler
This commit is contained in:
parent
4d80e24d44
commit
d30a402069
@ -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.
|
||||
|
@ -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;
|
||||
@ -68,7 +69,24 @@ void AbstractHTTPRequestHandler::handleRequest(HTTPServerRequest& request, HTTPS
|
||||
_pResponse = &response;
|
||||
if (authenticate())
|
||||
{
|
||||
run();
|
||||
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
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user