Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

header check for gzip files

krunal13133b95f2051ab9
diff --git a/src/http_server.cpp b/src/http_server.cpp
index 71304aca..5e45c86d 100644
--- a/src/http_server.cpp
+++ b/src/http_server.cpp
@@ -635,44 +635,45 @@ int HttpServer::async_req_cb(void *ctx, int is_end_stream) {
if(can_process_async || is_end_stream) {
// For async streaming requests, handler should be invoked for every aggregated chunk
// For a non streaming request, buffer body and invoke only at the end
- if(!zstream_initialized) {
+ if(!zstream_initialized &&
+ (31 == (int)request->body[0] && -117 == (int)request->body[1])) { //gzip header
if (inflateInit2(&zs, 16 + MAX_WBITS) != Z_OK)
throw (std::runtime_error("inflateInit failed while decompressing."));
zstream_initialized = true;
}
- std::string outbuffer;
- outbuffer.resize(10 * request->body.size());
-
- zs.next_in = (Bytef *) request->body.c_str();
- zs.avail_in = request->body.size();
- std::size_t size_uncompressed = 0;
- int ret = 0;
- do
- {
- zs.avail_out = static_cast<unsigned int>(outbuffer.size());
- zs.next_out = reinterpret_cast<Bytef*>(&outbuffer[0] + size_uncompressed);
- ret = inflate(&zs, Z_FINISH);
- if (ret != Z_STREAM_END && ret != Z_OK && ret != Z_BUF_ERROR)
- {
- std::string error_msg = zs.msg;
+ if(zstream_initialized) {
+ std::string outbuffer;
+ outbuffer.resize(10 * request->body.size());
+
+ zs.next_in = (Bytef *) request->body.c_str();
+ zs.avail_in = request->body.size();
+ std::size_t size_uncompressed = 0;
+ int ret = 0;
+ do {
+ zs.avail_out = static_cast<unsigned int>(outbuffer.size());
+ zs.next_out = reinterpret_cast<Bytef *>(&outbuffer[0] + size_uncompressed);
+ ret = inflate(&zs, Z_FINISH);
+ if (ret != Z_STREAM_END && ret != Z_OK && ret != Z_BUF_ERROR) {
+ std::string error_msg = zs.msg;
+ inflateEnd(&zs);
+ throw std::runtime_error(error_msg);
+ }
+
+ size_uncompressed += (outbuffer.size() - zs.avail_out);
+ } while (zs.avail_out == 0);
+
+ if (ret == Z_STREAM_END) {
inflateEnd(&zs);
- throw std::runtime_error(error_msg);
+ zstream_initialized = false;
}
- size_uncompressed += (outbuffer.size() - zs.avail_out);
- } while (zs.avail_out == 0);
+ outbuffer.resize(size_uncompressed);
- if(ret == Z_STREAM_END) {
- inflateEnd(&zs);
- zstream_initialized = false;
+ request->body = outbuffer;
+ request->chunk_len = outbuffer.size();
}
- outbuffer.resize(size_uncompressed);
-
- request->body = outbuffer;
- request->chunk_len = outbuffer.size();
-
if(request->first_chunk_aggregate) {
request->first_chunk_aggregate = false;
}