Comments (8)
Wouldn't a call like
#include "oatpp-zlib.hpp" // Unimplemented module.
...
ENDPOINT("GET", "/zip", zip)
{
auto content = "huge data";
return createZippedResponse(Status::CODE_200, content);
}
Provided as a convenience function by oatpp-zlib more intuitive? Less prone to error by users.
However, having the abstraction layer to intercept and iE decompress the data sounds great.
from oatpp.
Hey!
The full support for Content-Encoding
and Accept-Encoding
headers is added.- commit 8a4fd7e .
The additional data-processing layer was introduced, so No changes should be done for user endpoints.
The API
In the AppComponents
file:
#include "oatpp-zlib/EncoderProvider.hpp"
...
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::server::ConnectionHandler>, serverConnectionHandler)([] {
OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router); // get Router component
/* Create HttpProcessor::Components */
auto components = std::make_shared<oatpp::web::server::HttpProcessor::Components>(router);
/* Add content encoders */
auto encoders = std::make_shared<oatpp::web::protocol::http::encoding::ProviderCollection>();
encoders->add(std::make_shared<oatpp::zlib::DeflateEncoderProvider>());
encoders->add(std::make_shared<oatpp::zlib::GzipEncoderProvider>());
components->contentEncodingProviders = encoders;
/* Add content decoders */
auto decoders = std::make_shared<oatpp::web::protocol::http::encoding::ProviderCollection>();
decoders->add(std::make_shared<oatpp::zlib::DeflateDecoderProvider>());
decoders->add(std::make_shared<oatpp::zlib::GzipDecoderProvider>());
components->bodyDecoder = std::make_shared<oatpp::web::protocol::http::incoming::SimpleBodyDecoder>(decoders);
/* return HttpConnectionHandler */
return std::make_shared<oatpp::web::server::HttpConnectionHandler>(components);
}());
...
Cheers,
Leonid
from oatpp.
Great work as always Leonid!
from oatpp.
Hello @jfixemer ,
Brief
Currently, in order to add support for Content-Encoding
header on the framework level (so that the user gets it almost for free), we have to add a new abstraction layer for data processing, plus the dependency on the zlib
in the main oatpp
module.
While adding an abstraction layer to make Content-Encoding
feature pluggable may be a good idea. zlib
should not go as a dependency of the main oatpp
module. Instead, it should be added as an oatpp module ex. oatpp-zlib
(as you've mentioned).
Effort
- Creating a new convenience abstraction layer in
oatpp
to makeContent-Encoding
feature pluggable is a matter of discussion and investigation. - Creating a C++ wrapper for
zlib
should be pretty simple and straightforward. It depends on the functionality that should be covered.
Workaround
Let's say that we don't have the convenience abstraction layer, but we do have the oatpp-zlib
module (or whatever convenience API over zlib).
Then the endpoint code could look something like:
#include "oatpp-zlib.hpp" // Unimplemented module.
...
/* It is a hypothetical code. NOT a real example. */
ENDPOINT("GET", "/huge-document", getHugeDocument) {
auto compressedData = oatpp::zlib::compress("my-huge-data", "gzip");
auto response = createResponse(Status::CODE_200, compressedData);
response->putHeader("Content-Encoding", "gzip");
return response;
}
So this is the current situation.
Please let me know if you have any questions.
Regards,
Leonid
from oatpp.
Thanks for the hints and feedback!
from oatpp.
so for receiving data: ...
Yes, you are correct.
Or the same but with if
s moved to decompress
method:
#include "oatpp-zlib.hpp" // Unimplemented module.
...
ENDPOINT("POST", "/data", setData,
HEADER(String, encoding, "Content-Encoding"),
BODY_STRING(String, input))
{
auto content = oatpp::zlib::decompress(imput->toLowerCase(), encoding); // hypothetical call
// TODO - process content. Ex.: map content to DTO with ObjectMapper.
return createResponse(Status::CODE_200, "OK");
}
I guess the big downside is that if I wanted to use DTO mapping to parse JSON then I have to do so explicitly after the decompression (I can't use the BODY_DTO(...))
Yes, you are right. Unfortunately, in this case, you won't be able to use BODY_DTO
.
Regards,
Leonid
from oatpp.
Thanks!
from oatpp.
Excellent!!
Much better API than the workaround.
Thanks
from oatpp.
Related Issues (20)
- Regarding oatpp::async::CoroutineWithResult HOT 9
- How to add default values to the QUERY parameters of an ENDPOINT?
- Enhance Deserializer's "Error. Unknown field"
- How can I use OATPP to handle web browser request download file. HOT 2
- Memory leak in Object mapping HOT 1
- Deserialize json when not include required field only gives error when the field is specified as null
- [Question] readBodyIntoDTO when there's a list in the body
- API question
- how to make dynamic sql use oatpp-sqlite HOT 1
- LazyStringMapTemplate::get returns Nullptr wich is not in oatpp.io Documentation
- Please add support for CMake 3.16
- Cannot test if required integer query parameter is empty
- [Question] Is it possible during compilation to write out the generated oas-3.0.0.json file?
- May memory leak
- How should I make my process send requests to the target when using OATPP HOT 4
- Stack corruption issue in ConnectionProvider.cpp
- Can not build project successfully
- Is it possible make oatpp::network::tcp::client::ConnectionProvider support bind client IP?
- specific async pattern implementation query HOT 4
- io_uring support request HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from oatpp.