Coder Social home page Coder Social logo

oatpp / oatpp-zlib Goto Github PK

View Code? Open in Web Editor NEW
5.0 6.0 6.0 63 KB

Module oatpp-zlib provides functionality for compressing/decompressing content with deflate and gzip. Supports both "Simple" and "Async" oatpp APIs.

Home Page: https://oatpp.io/

License: Apache License 2.0

CMake 28.72% C++ 69.43% Shell 1.85%
oatpp cpp zlib gzip deflate

oatpp-zlib's Introduction

oatpp-zlib Build Status

Module oatpp-zlib provides functionality for compressing/decompressing content with deflate and gzip.
Supports both "Simple" and "Async" oatpp APIs.

See more:

How To Build

Requires

  • ZLib installed.

Install ZLib

sudo apt-get install zlib1g-dev

Install oatpp-zlib

Clone this repository. In the root of the repository run:

mkdir build && cd build
cmake ..
make install

APIs

Automatically Compress Served Content

Configure server::ConnectionHandler in AppComponent.hpp.

#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>());

  /* Set content encoders */
  components->contentEncodingProviders = encoders;

  /* return HttpConnectionHandler */
  return std::make_shared<oatpp::web::server::HttpConnectionHandler>(components);
  
}());

...

Now served content will be automatically compressed and streamed to the client if the client sets Accept-Encoding header appropriately.

Automatically Decompress Uploaded Content

Configure server::ConnectionHandler in AppComponent.hpp.

#include "oatpp-zlib/EncoderProvider.hpp"
#include "oatpp/web/protocol/http/incoming/SimpleBodyDecoder.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 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>());

  /* Set Body Decoder */
  components->bodyDecoder = std::make_shared<oatpp::web::protocol::http::incoming::SimpleBodyDecoder>(decoders);

  /* return HttpConnectionHandler */
  return std::make_shared<oatpp::web::server::HttpConnectionHandler>(components);
  
}());

...

Now uploaded content will be automatically decompressed if the client sets Content-Encoding header properly.

oatpp-zlib's People

Contributors

lganzzzo avatar sileht avatar yikenan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

oatpp-zlib's Issues

Windows Install `oatpp-zlib`

By @AlexandreHURDYK

I think I've successfully managed to compile oatpp-zlib for windows. Here's the procedure :

You will need the following files :

  • zlib.h
  • zconf.h
  • zlib.lib
  • oatpp must be compiled and installed on your computer.

Steps :

  • Create a folder containing all your zlib components.

  • Open a console in administrator mode. This is very important, otherwise you won't be able to compile anything.

  • Clone the repo : $ git clone https://github.com/oatpp/oatpp-zlib.git

  • Enter the directory : $ cd oatpp-zlib

  • Create the build directory : $ mkdir build

  • Go inside that directory : $ cd build

  • Execute the following command :

    $ cmake .. -DZLIB_INCLUDE_DIR=PATH\TO\zlib\INCLUDES -DZLIB_LIBRARY=PATH\TO\zlib.lib
    

    Mind the -DZLIB_LIBRARY argument ! You need to literally make it point to your zlib.lib file (ex : C:/path/to/zlib/zlib.lib).
    Otherwise, you will get compilation errors.

    Another compilation error I personally encountered is due to a missing "unistd.h" library. The thing is, unistd.h is a Linux library
    and you're not supposed to be able to use it on windows (though some compilers seem to have a built in version of unistd.h for
    windows). If you get compilation errors related to unistd.h, you may have to edit zconf.h :
    --> Find the following three lines (I've personally found them starting from line 434 in the zconf.h file) :

    #if 1 
    #  define Z_HAVE_UNISTD_H
    #endif

    --> Comment them. This should prevent unistd from being used. I recommend saving your precedent version of zconf.h before
    doing something like this.

  • FINAL STEP : perform the following command depending which kind of application you want to run :
    --> For a debug application : $ cmake --build . --target INSTALL
    --> For a release application : $ cmake --build . --target INSTALL --config Release

If at this point you get mismatch errors, it means your oatpp installation directory doesn't match the compilation mode of your library : you will need to re-compile oatpp with a compilation mode matching the one you chose for the oatpp-zlib module (debug for debug, release for release).
Small reminder about how to compile oatpp :

$ git clone https://github.com/oatpp/oatpp.git
$ cd oatpp\
$ MD build
$ cd build\

$ cmake ..
//For a debug app :
$ cmake --build . --target INSTALL 
//For a release app :
$ cmake --build . --target INSTALL --config Release

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.