| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // GZipFilter applies gzip and deflate content encoding/decoding to a data | 5 // GZipFilter applies gzip and deflate content encoding/decoding to a data |
| 6 // stream. As specified by HTTP 1.1, with gzip encoding the content is | 6 // stream. As specified by HTTP 1.1, with gzip encoding the content is |
| 7 // wrapped with a gzip header, and with deflate encoding the content is in | 7 // wrapped with a gzip header, and with deflate encoding the content is in |
| 8 // a raw, headerless DEFLATE stream. | 8 // a raw, headerless DEFLATE stream. |
| 9 // | 9 // |
| 10 // Internally GZipFilter uses zlib inflate to do decoding. | 10 // Internally GZipFilter uses zlib inflate to do decoding. |
| 11 // | 11 // |
| 12 // GZipFilter is a subclass of Filter. See the latter's header file filter.h | 12 // GZipFilter is a subclass of Filter. See the latter's header file filter.h |
| 13 // for sample usage. | 13 // for sample usage. |
| 14 | 14 |
| 15 #ifndef NET_FILTER_GZIP_FILTER_H_ | 15 #ifndef NET_FILTER_GZIP_FILTER_H_ |
| 16 #define NET_FILTER_GZIP_FILTER_H_ | 16 #define NET_FILTER_GZIP_FILTER_H_ |
| 17 | 17 |
| 18 #include <memory> |
| 19 |
| 18 #include "base/macros.h" | 20 #include "base/macros.h" |
| 19 #include "base/memory/scoped_ptr.h" | |
| 20 #include "net/filter/filter.h" | 21 #include "net/filter/filter.h" |
| 21 | 22 |
| 22 typedef struct z_stream_s z_stream; | 23 typedef struct z_stream_s z_stream; |
| 23 | 24 |
| 24 namespace net { | 25 namespace net { |
| 25 | 26 |
| 26 class GZipHeader; | 27 class GZipHeader; |
| 27 | 28 |
| 28 class GZipFilter : public Filter { | 29 class GZipFilter : public Filter { |
| 29 public: | 30 public: |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 // This variable is initialized by InitDecoding and updated only by | 109 // This variable is initialized by InitDecoding and updated only by |
| 109 // ReadFilteredData. | 110 // ReadFilteredData. |
| 110 DecodingStatus decoding_status_; | 111 DecodingStatus decoding_status_; |
| 111 | 112 |
| 112 // Indicates the type of content decoding the GZipFilter is performing. | 113 // Indicates the type of content decoding the GZipFilter is performing. |
| 113 // This variable is set only once by InitDecoding. | 114 // This variable is set only once by InitDecoding. |
| 114 DecodingMode decoding_mode_; | 115 DecodingMode decoding_mode_; |
| 115 | 116 |
| 116 // Used to parse the gzip header in gzip stream. | 117 // Used to parse the gzip header in gzip stream. |
| 117 // It is used when the decoding_mode_ is DECODE_MODE_GZIP. | 118 // It is used when the decoding_mode_ is DECODE_MODE_GZIP. |
| 118 scoped_ptr<GZipHeader> gzip_header_; | 119 std::unique_ptr<GZipHeader> gzip_header_; |
| 119 | 120 |
| 120 // Tracks the progress of parsing gzip header. | 121 // Tracks the progress of parsing gzip header. |
| 121 // This variable is maintained by gzip_header_. | 122 // This variable is maintained by gzip_header_. |
| 122 GZipCheckHeaderState gzip_header_status_; | 123 GZipCheckHeaderState gzip_header_status_; |
| 123 | 124 |
| 124 // A flag used by InsertZlibHeader to record whether we've successfully added | 125 // A flag used by InsertZlibHeader to record whether we've successfully added |
| 125 // a zlib header to this stream. | 126 // a zlib header to this stream. |
| 126 bool zlib_header_added_; | 127 bool zlib_header_added_; |
| 127 | 128 |
| 128 // Tracks how many bytes of gzip footer have been received. | 129 // Tracks how many bytes of gzip footer have been received. |
| 129 int gzip_footer_bytes_; | 130 int gzip_footer_bytes_; |
| 130 | 131 |
| 131 // The control block of zlib which actually does the decoding. | 132 // The control block of zlib which actually does the decoding. |
| 132 // This data structure is initialized by InitDecoding and updated only by | 133 // This data structure is initialized by InitDecoding and updated only by |
| 133 // DoInflate, with InsertZlibHeader being the exception as a workaround. | 134 // DoInflate, with InsertZlibHeader being the exception as a workaround. |
| 134 scoped_ptr<z_stream> zlib_stream_; | 135 std::unique_ptr<z_stream> zlib_stream_; |
| 135 | 136 |
| 136 // For robustness, when we see the solo sdch filter, we chain in a gzip filter | 137 // For robustness, when we see the solo sdch filter, we chain in a gzip filter |
| 137 // in front of it, with this flag to indicate that the gzip decoding might not | 138 // in front of it, with this flag to indicate that the gzip decoding might not |
| 138 // be needed. This handles a strange case where "Content-Encoding: sdch,gzip" | 139 // be needed. This handles a strange case where "Content-Encoding: sdch,gzip" |
| 139 // is reduced by an errant proxy to "Content-Encoding: sdch", while the | 140 // is reduced by an errant proxy to "Content-Encoding: sdch", while the |
| 140 // content is indeed really gzipped result of sdch :-/. | 141 // content is indeed really gzipped result of sdch :-/. |
| 141 // If this flag is set, then we will revert to being a pass through filter if | 142 // If this flag is set, then we will revert to being a pass through filter if |
| 142 // we don't get a valid gzip header. | 143 // we don't get a valid gzip header. |
| 143 bool possible_sdch_pass_through_; | 144 bool possible_sdch_pass_through_; |
| 144 | 145 |
| 145 DISALLOW_COPY_AND_ASSIGN(GZipFilter); | 146 DISALLOW_COPY_AND_ASSIGN(GZipFilter); |
| 146 }; | 147 }; |
| 147 | 148 |
| 148 } // namespace net | 149 } // namespace net |
| 149 | 150 |
| 150 #endif // NET_FILTER_GZIP_FILTER_H__ | 151 #endif // NET_FILTER_GZIP_FILTER_H__ |
| OLD | NEW |