| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "net/base/filter.h" | 21 #include "net/base/filter.h" |
| 22 | 22 |
| 23 typedef struct z_stream_s z_stream; | 23 typedef struct z_stream_s z_stream; |
| 24 | 24 |
| 25 namespace net { | 25 namespace net { |
| 26 | 26 |
| 27 class GZipHeader; | 27 class GZipHeader; |
| 28 | 28 |
| 29 class GZipFilter : public Filter { | 29 class GZipFilter : public Filter { |
| 30 public: | 30 public: |
| 31 explicit GZipFilter(const FilterContext& filter_context); | |
| 32 | |
| 33 virtual ~GZipFilter(); | 31 virtual ~GZipFilter(); |
| 34 | 32 |
| 35 // Initializes filter decoding mode and internal control blocks. | 33 // Initializes filter decoding mode and internal control blocks. |
| 36 // Parameter filter_type specifies the type of filter, which corresponds to | 34 // Parameter filter_type specifies the type of filter, which corresponds to |
| 37 // either gzip or deflate decoding. The function returns true if success and | 35 // either gzip or deflate decoding. The function returns true if success and |
| 38 // false otherwise. | 36 // false otherwise. |
| 39 // The filter can only be initialized once. | 37 // The filter can only be initialized once. |
| 40 bool InitDecoding(Filter::FilterType filter_type); | 38 bool InitDecoding(Filter::FilterType filter_type); |
| 41 | 39 |
| 42 // Decodes the pre-filter data and writes the output into the dest_buffer | 40 // Decodes the pre-filter data and writes the output into the dest_buffer |
| (...skipping 25 matching lines...) Expand all Loading... |
| 68 }; | 66 }; |
| 69 | 67 |
| 70 enum GZipCheckHeaderState { | 68 enum GZipCheckHeaderState { |
| 71 GZIP_CHECK_HEADER_IN_PROGRESS, | 69 GZIP_CHECK_HEADER_IN_PROGRESS, |
| 72 GZIP_GET_COMPLETE_HEADER, | 70 GZIP_GET_COMPLETE_HEADER, |
| 73 GZIP_GET_INVALID_HEADER | 71 GZIP_GET_INVALID_HEADER |
| 74 }; | 72 }; |
| 75 | 73 |
| 76 static const int kGZipFooterSize = 8; | 74 static const int kGZipFooterSize = 8; |
| 77 | 75 |
| 76 // Only to be instantiated by Filter::Factory. |
| 77 explicit GZipFilter(const FilterContext& filter_context); |
| 78 friend class Filter; |
| 79 |
| 78 // Parses and verifies the GZip header. | 80 // Parses and verifies the GZip header. |
| 79 // Upon exit, the function updates gzip_header_status_ accordingly. | 81 // Upon exit, the function updates gzip_header_status_ accordingly. |
| 80 // | 82 // |
| 81 // The function returns Filter::FILTER_OK if it gets a complete header and | 83 // The function returns Filter::FILTER_OK if it gets a complete header and |
| 82 // there are more data in the pre-filter buffer. | 84 // there are more data in the pre-filter buffer. |
| 83 // The function returns Filter::FILTER_NEED_MORE_DATA if it parses all data | 85 // The function returns Filter::FILTER_NEED_MORE_DATA if it parses all data |
| 84 // in the pre-filter buffer, either getting a complete header or a partial | 86 // in the pre-filter buffer, either getting a complete header or a partial |
| 85 // header. The caller needs to check gzip_header_status_ and call this | 87 // header. The caller needs to check gzip_header_status_ and call this |
| 86 // function again for partial header. | 88 // function again for partial header. |
| 87 // The function returns Filter::FILTER_ERROR if error occurs. | 89 // The function returns Filter::FILTER_ERROR if error occurs. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 // 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 |
| 141 // we don't get a valid gzip header. | 143 // we don't get a valid gzip header. |
| 142 bool possible_sdch_pass_through_; | 144 bool possible_sdch_pass_through_; |
| 143 | 145 |
| 144 DISALLOW_COPY_AND_ASSIGN(GZipFilter); | 146 DISALLOW_COPY_AND_ASSIGN(GZipFilter); |
| 145 }; | 147 }; |
| 146 | 148 |
| 147 } // namespace net | 149 } // namespace net |
| 148 | 150 |
| 149 #endif // NET_BASE_GZIP_FILTER_H__ | 151 #endif // NET_BASE_GZIP_FILTER_H__ |
| OLD | NEW |