mirror of
https://github.com/pocoproject/poco.git
synced 2025-07-04 09:37:11 +02:00
improvement to AbstractHTTPRequestHandler
This commit is contained in:
parent
4d80e24d44
commit
d30a402069
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// AbstractHTTPRequestHandler.h
|
// AbstractHTTPRequestHandler.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/Main/Net/include/Poco/Net/AbstractHTTPRequestHandler.h#2 $
|
// $Id: //poco/Main/Net/include/Poco/Net/AbstractHTTPRequestHandler.h#3 $
|
||||||
//
|
//
|
||||||
// Library: Net
|
// Library: Net
|
||||||
// Package: HTTPServer
|
// Package: HTTPServer
|
||||||
@ -83,6 +83,10 @@ public:
|
|||||||
/// - call authorize();
|
/// - call authorize();
|
||||||
/// - if authorize() returns true call run(),
|
/// - if authorize() returns true call run(),
|
||||||
/// else send 401 (Unauthorized) response.
|
/// 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();
|
HTTPServerRequest& request();
|
||||||
/// Returns the request.
|
/// Returns the request.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// AbstractHTTPRequestHandler.cpp
|
// AbstractHTTPRequestHandler.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/Main/Net/src/AbstractHTTPRequestHandler.cpp#3 $
|
// $Id: //poco/Main/Net/src/AbstractHTTPRequestHandler.cpp#4 $
|
||||||
//
|
//
|
||||||
// Library: Net
|
// Library: Net
|
||||||
// Package: HTTPServer
|
// Package: HTTPServer
|
||||||
@ -39,6 +39,7 @@
|
|||||||
#include "Poco/Net/HTTPServerResponse.h"
|
#include "Poco/Net/HTTPServerResponse.h"
|
||||||
#include "Poco/Net/HTMLForm.h"
|
#include "Poco/Net/HTMLForm.h"
|
||||||
#include "Poco/NumberFormatter.h"
|
#include "Poco/NumberFormatter.h"
|
||||||
|
#include "Poco/Exception.h"
|
||||||
|
|
||||||
|
|
||||||
using Poco::NumberFormatter;
|
using Poco::NumberFormatter;
|
||||||
@ -67,9 +68,26 @@ void AbstractHTTPRequestHandler::handleRequest(HTTPServerRequest& request, HTTPS
|
|||||||
_pRequest = &request;
|
_pRequest = &request;
|
||||||
_pResponse = &response;
|
_pResponse = &response;
|
||||||
if (authenticate())
|
if (authenticate())
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
run();
|
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
|
else
|
||||||
{
|
{
|
||||||
sendErrorResponse(HTTPResponse::HTTP_UNAUTHORIZED, "");
|
sendErrorResponse(HTTPResponse::HTTP_UNAUTHORIZED, "");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user