OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Crashpad Authors. All rights reserved. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 #ifndef CRASHPAD_UTIL_NET_HTTP_BODY_GZIP_H_ |
| 16 #define CRASHPAD_UTIL_NET_HTTP_BODY_GZIP_H_ |
| 17 |
| 18 #include <stdint.h> |
| 19 #include <sys/types.h> |
| 20 |
| 21 #include <memory> |
| 22 |
| 23 #include "base/macros.h" |
| 24 #include "util/file/file_io.h" |
| 25 #include "util/net/http_body.h" |
| 26 |
| 27 extern "C" { |
| 28 typedef struct z_stream_s z_stream; |
| 29 } // extern "C" |
| 30 |
| 31 namespace crashpad { |
| 32 |
| 33 //! \brief An implementation of HTTPBodyStream that `gzip`-compresses another |
| 34 //! HTTPBodyStream. |
| 35 class GzipHTTPBodyStream : public HTTPBodyStream { |
| 36 public: |
| 37 explicit GzipHTTPBodyStream(std::unique_ptr<HTTPBodyStream> source); |
| 38 |
| 39 ~GzipHTTPBodyStream() override; |
| 40 |
| 41 // HTTPBodyStream: |
| 42 FileOperationResult GetBytesBuffer(uint8_t* buffer, size_t max_len) override; |
| 43 |
| 44 private: |
| 45 enum State : int { |
| 46 kUninitialized, |
| 47 kOperating, |
| 48 kInputEOF, |
| 49 kFinished, |
| 50 kError, |
| 51 }; |
| 52 |
| 53 // Calls deflateEnd() and transitions state_ to state. If deflateEnd() fails, |
| 54 // logs a message and transitions state_ to State::kError. |
| 55 void Done(State state); |
| 56 |
| 57 uint8_t input_[4096]; |
| 58 std::unique_ptr<HTTPBodyStream> source_; |
| 59 std::unique_ptr<z_stream> z_stream_; |
| 60 State state_; |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(GzipHTTPBodyStream); |
| 63 }; |
| 64 |
| 65 } // namespace crashpad |
| 66 |
| 67 #endif // CRASHPAD_UTIL_NET_HTTP_BODY_GZIP_H_ |
OLD | NEW |