mirror of
https://github.com/oatpp/oatpp.git
synced 2025-03-19 18:10:23 +08:00
commit
fd6b1585c0
@ -91,6 +91,8 @@ add_library(oatpp
|
||||
oatpp/core/macro/component.hpp
|
||||
oatpp/core/parser/Caret.cpp
|
||||
oatpp/core/parser/Caret.hpp
|
||||
oatpp/core/parser/ParsingError.cpp
|
||||
oatpp/core/parser/ParsingError.hpp
|
||||
oatpp/core/utils/ConversionUtils.cpp
|
||||
oatpp/core/utils/ConversionUtils.hpp
|
||||
oatpp/encoding/Base64.cpp
|
||||
@ -175,6 +177,7 @@ add_library(oatpp
|
||||
oatpp/web/server/HttpConnectionHandler.hpp
|
||||
oatpp/web/server/HttpProcessor.cpp
|
||||
oatpp/web/server/HttpProcessor.hpp
|
||||
oatpp/web/server/HttpRequestHandler.hpp
|
||||
oatpp/web/server/HttpRouter.cpp
|
||||
oatpp/web/server/HttpRouter.hpp
|
||||
oatpp/web/server/api/ApiController.cpp
|
||||
@ -188,9 +191,7 @@ add_library(oatpp
|
||||
oatpp/web/url/mapping/Pattern.cpp
|
||||
oatpp/web/url/mapping/Pattern.hpp
|
||||
oatpp/web/url/mapping/Router.hpp
|
||||
oatpp/core/parser/ParsingError.cpp
|
||||
oatpp/core/parser/ParsingError.hpp
|
||||
oatpp/web/server/HttpRequestHandler.hpp)
|
||||
)
|
||||
|
||||
set_target_properties(oatpp PROPERTIES
|
||||
CXX_STANDARD 11
|
||||
|
@ -31,19 +31,19 @@
|
||||
namespace oatpp { namespace web { namespace protocol { namespace http { namespace outgoing {
|
||||
|
||||
std::shared_ptr<Response>
|
||||
ResponseFactory::createShared(const Status& status, const oatpp::String& text) {
|
||||
ResponseFactory::createResponse(const Status& status, const oatpp::String& text) {
|
||||
return Response::createShared(status, BufferBody::createShared(text));
|
||||
}
|
||||
|
||||
std::shared_ptr<Response>
|
||||
ResponseFactory::createShared(const Status& status, const std::shared_ptr<oatpp::data::stream::ChunkedBuffer>& chunkedBuffer) {
|
||||
ResponseFactory::createResponse(const Status& status, const std::shared_ptr<oatpp::data::stream::ChunkedBuffer>& chunkedBuffer) {
|
||||
return Response::createShared(status, ChunkedBufferBody::createShared(chunkedBuffer));
|
||||
}
|
||||
|
||||
std::shared_ptr<Response>
|
||||
ResponseFactory::createShared(const Status& status,
|
||||
const oatpp::data::mapping::type::AbstractObjectWrapper& dto,
|
||||
oatpp::data::mapping::ObjectMapper* objectMapper) {
|
||||
ResponseFactory::createResponse(const Status& status,
|
||||
const oatpp::data::mapping::type::AbstractObjectWrapper& dto,
|
||||
oatpp::data::mapping::ObjectMapper* objectMapper) {
|
||||
return Response::createShared(status, DtoBody::createShared(dto, objectMapper));
|
||||
}
|
||||
|
||||
|
@ -43,28 +43,28 @@ public:
|
||||
* Create &id:oatpp::web::protocol::http::outgoing::Response; with &id:oatpp::web::protocol::http::outgoing::BufferBody;.
|
||||
* @param status - &id:oatpp::web::protocol::http::Status;.
|
||||
* @param text - &id:oatpp::String;.
|
||||
* @return - &id:oatpp::web::protocol::http::outgoing::Response;.
|
||||
* @return - `std::shared_ptr` to &id:oatpp::web::protocol::http::outgoing::Response;.
|
||||
*/
|
||||
static std::shared_ptr<Response> createShared(const Status& status, const oatpp::String& text);
|
||||
static std::shared_ptr<Response> createResponse(const Status& status, const oatpp::String& text);
|
||||
|
||||
/**
|
||||
* Create &id:oatpp::web::protocol::http::outgoing::Response; with &id:oatpp::web::protocol::http::outgoing::ChunkedBufferBody;.
|
||||
* @param status - &id:oatpp::web::protocol::http::Status;.
|
||||
* @param chunkedBuffer - &id:oatpp::data::stream::ChunkedBuffer;.
|
||||
* @return - &id:oatpp::web::protocol::http::outgoing::Response;.
|
||||
* @return - `std::shared_ptr` to &id:oatpp::web::protocol::http::outgoing::Response;.
|
||||
*/
|
||||
static std::shared_ptr<Response> createShared(const Status& status, const std::shared_ptr<oatpp::data::stream::ChunkedBuffer>& chunkedBuffer);
|
||||
static std::shared_ptr<Response> createResponse(const Status& status, const std::shared_ptr<oatpp::data::stream::ChunkedBuffer>& chunkedBuffer);
|
||||
|
||||
/**
|
||||
* Create &id:oatpp::web::protocol::http::outgoing::Response; with &id:oatpp::web::protocol::http::outgoing::DtoBody;.
|
||||
* @param status - &id:oatpp::web::protocol::http::Status;.
|
||||
* @param dto - see [Data Transfer Object (DTO)](https://oatpp.io/docs/components/dto/).
|
||||
* @param objectMapper - &id:oatpp::data::mapping::ObjectMapper;.
|
||||
* @return - &id:oatpp::web::protocol::http::outgoing::Response;.
|
||||
* @return - `std::shared_ptr` to &id:oatpp::web::protocol::http::outgoing::Response;.
|
||||
*/
|
||||
static std::shared_ptr<Response> createShared(const Status& status,
|
||||
const oatpp::data::mapping::type::AbstractObjectWrapper& dto,
|
||||
oatpp::data::mapping::ObjectMapper* objectMapper);
|
||||
static std::shared_ptr<Response> createResponse(const Status& status,
|
||||
const oatpp::data::mapping::type::AbstractObjectWrapper& dto,
|
||||
oatpp::data::mapping::ObjectMapper* objectMapper);
|
||||
|
||||
};
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
#ifndef oatpp_web_server_HttpRequestHandler_hpp
|
||||
#define oatpp_web_server_HttpRequestHandler_hpp
|
||||
|
||||
#include "oatpp/web/protocol/http/outgoing/ResponseFactory.hpp"
|
||||
#include "oatpp/web/protocol/http/outgoing/Response.hpp"
|
||||
#include "oatpp/web/protocol/http/incoming/Request.hpp"
|
||||
|
||||
@ -35,8 +36,47 @@ namespace oatpp { namespace web { namespace server {
|
||||
*/
|
||||
class HttpRequestHandler {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Convenience typedef for &id:oatpp::web::protocol::http::Status;.
|
||||
*/
|
||||
typedef oatpp::web::protocol::http::Status Status;
|
||||
|
||||
/**
|
||||
* Convenience typedef for &id:oatpp::web::protocol::http::Header;.
|
||||
*/
|
||||
typedef oatpp::web::protocol::http::Header Header;
|
||||
|
||||
/**
|
||||
* Convenience typedef for &id:oatpp::web::protocol::http::Headers;.
|
||||
*/
|
||||
typedef oatpp::web::protocol::http::Headers Headers;
|
||||
|
||||
/**
|
||||
* Convenience typedef for &id:oatpp::web::protocol::http::QueryParams;.
|
||||
*/
|
||||
typedef oatpp::web::protocol::http::QueryParams QueryParams;
|
||||
|
||||
/**
|
||||
* Convenience typedef for &id:oatpp::web::protocol::http::incoming::Request;.
|
||||
*/
|
||||
typedef oatpp::web::protocol::http::incoming::Request IncomingRequest;
|
||||
|
||||
/**
|
||||
* Convenience typedef for &id:oatpp::web::protocol::http::outgoing::Response;.
|
||||
*/
|
||||
typedef oatpp::web::protocol::http::outgoing::Response OutgoingResponse;
|
||||
|
||||
/**
|
||||
* Convenience typedef for &id:oatpp::web::protocol::http::outgoing::ResponseFactory;.
|
||||
*/
|
||||
typedef oatpp::web::protocol::http::outgoing::ResponseFactory ResponseFactory;
|
||||
|
||||
/**
|
||||
* Convenience typedef for &id:oatpp::web::protocol::http::HttpError;.
|
||||
*/
|
||||
typedef oatpp::web::protocol::http::HttpError HttpError;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
@ -45,7 +85,9 @@ public:
|
||||
* @param request - incoming http request. &id:oatpp::web::protocol::http::incoming::Request;.
|
||||
* @return - outgoing http response. &id:oatpp::web::protocol::http::outgoing::Response;.
|
||||
*/
|
||||
virtual std::shared_ptr<OutgoingResponse> handle(const std::shared_ptr<IncomingRequest>& request) = 0;
|
||||
virtual std::shared_ptr<OutgoingResponse> handle(const std::shared_ptr<IncomingRequest>& request) {
|
||||
throw HttpError(Status::CODE_501, "Endpoint not implemented.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle incoming http request in Asynchronous manner. <br>
|
||||
@ -54,7 +96,9 @@ public:
|
||||
* @return - &id:oatpp::async::CoroutineStarterForResult; of &id:oatpp::web::protocol::http::outgoing::Response;.
|
||||
*/
|
||||
virtual oatpp::async::CoroutineStarterForResult<const std::shared_ptr<OutgoingResponse>&>
|
||||
handleAsync(const std::shared_ptr<IncomingRequest>& request) = 0;
|
||||
handleAsync(const std::shared_ptr<IncomingRequest>& request) {
|
||||
throw HttpError(Status::CODE_501, "Asynchronous endpoint not implemented.");
|
||||
}
|
||||
};
|
||||
|
||||
}}}
|
||||
|
@ -66,23 +66,23 @@ const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& ApiController::getDef
|
||||
|
||||
std::shared_ptr<ApiController::OutgoingResponse> ApiController::createResponse(const Status& status,
|
||||
const oatpp::String& str) const {
|
||||
return OutgoingResponseFactory::createShared(status, str);
|
||||
return ResponseFactory::createResponse(status, str);
|
||||
}
|
||||
|
||||
std::shared_ptr<ApiController::OutgoingResponse> ApiController::createResponse(const Status& status,
|
||||
const std::shared_ptr<oatpp::data::stream::ChunkedBuffer>& chunkedBuffer) const {
|
||||
return OutgoingResponseFactory::createShared(status, chunkedBuffer);
|
||||
return ResponseFactory::createResponse(status, chunkedBuffer);
|
||||
}
|
||||
|
||||
std::shared_ptr<ApiController::OutgoingResponse> ApiController::createDtoResponse(const Status& status,
|
||||
const oatpp::data::mapping::type::AbstractObjectWrapper& dto,
|
||||
const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper) const {
|
||||
return OutgoingResponseFactory::createShared(status, dto, objectMapper.get());
|
||||
return ResponseFactory::createResponse(status, dto, objectMapper.get());
|
||||
}
|
||||
|
||||
std::shared_ptr<ApiController::OutgoingResponse> ApiController::createDtoResponse(const Status& status,
|
||||
const oatpp::data::mapping::type::AbstractObjectWrapper& dto) const {
|
||||
return OutgoingResponseFactory::createShared(status, dto, m_defaultObjectMapper.get());
|
||||
return ResponseFactory::createResponse(status, dto, m_defaultObjectMapper.get());
|
||||
}
|
||||
|
||||
}}}}
|
||||
|
@ -56,7 +56,7 @@ public:
|
||||
/**
|
||||
* Convenience typedef for &id:oatpp::web::protocol::http::outgoing::ResponseFactory;.
|
||||
*/
|
||||
typedef oatpp::web::protocol::http::outgoing::ResponseFactory OutgoingResponseFactory;
|
||||
typedef oatpp::web::protocol::http::outgoing::ResponseFactory ResponseFactory;
|
||||
|
||||
/**
|
||||
* Convenience typedef for &id:oatpp::web::protocol::http::incoming::Request;.
|
||||
|
Loading…
x
Reference in New Issue
Block a user