-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCompressionHandler.cpp
More file actions
30 lines (25 loc) · 956 Bytes
/
CompressionHandler.cpp
File metadata and controls
30 lines (25 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "CompressionHandler.h"
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <sstream>
namespace Team15 {
namespace server {
RequestHandler::Status CompressionHandler::Init(const std::string& uri_preix,NginxConfig config) {
// don't need to do much
return RequestHandler::Status::OK;
}
RequestHandler::Status CompressionHandler::HandleRequest(const Request& request, Response* response) {
std::stringstream ss, comp;
ss << response->body();
boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
in.push(boost::iostreams::gzip_compressor());
in.push(ss);
boost::iostreams::copy(in,comp);
response->SetBody(comp.str());
response->AddHeader("Content-Encoding","gzip");
response->AddHeader("Content-Length",std::to_string(comp.str().size()));
return RequestHandler::Status::OK;
}
}
}