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 "base/basictypes.h" | 18 #include "base/basictypes.h" |
19 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
20 #include "net/filter/filter.h" | 20 #include "net/filter/filter.h" |
21 | 21 |
22 typedef struct z_stream_s z_stream; | 22 typedef struct z_stream_s z_stream; |
23 | 23 |
24 namespace net { | 24 namespace net { |
25 | 25 |
26 class GZipHeader; | 26 class GZipHeader; |
27 | 27 |
28 class GZipFilter : public Filter { | 28 class GZipFilter : public Filter { |
29 public: | 29 public: |
30 virtual ~GZipFilter(); | 30 ~GZipFilter() override; |
31 | 31 |
32 // Initializes filter decoding mode and internal control blocks. | 32 // Initializes filter decoding mode and internal control blocks. |
33 // Parameter filter_type specifies the type of filter, which corresponds to | 33 // Parameter filter_type specifies the type of filter, which corresponds to |
34 // either gzip or deflate decoding. The function returns true if success and | 34 // either gzip or deflate decoding. The function returns true if success and |
35 // false otherwise. | 35 // false otherwise. |
36 // The filter can only be initialized once. | 36 // The filter can only be initialized once. |
37 bool InitDecoding(Filter::FilterType filter_type); | 37 bool InitDecoding(Filter::FilterType filter_type); |
38 | 38 |
39 // Decodes the pre-filter data and writes the output into the dest_buffer | 39 // Decodes the pre-filter data and writes the output into the dest_buffer |
40 // passed in. | 40 // passed in. |
41 // The function returns FilterStatus. See filter.h for its description. | 41 // The function returns FilterStatus. See filter.h for its description. |
42 // | 42 // |
43 // Upon entry, *dest_len is the total size (in number of chars) of the | 43 // Upon entry, *dest_len is the total size (in number of chars) of the |
44 // destination buffer. Upon exit, *dest_len is the actual number of chars | 44 // destination buffer. Upon exit, *dest_len is the actual number of chars |
45 // written into the destination buffer. | 45 // written into the destination buffer. |
46 // | 46 // |
47 // This function will fail if there is no pre-filter data in the | 47 // This function will fail if there is no pre-filter data in the |
48 // stream_buffer_. On the other hand, *dest_len can be 0 upon successful | 48 // stream_buffer_. On the other hand, *dest_len can be 0 upon successful |
49 // return. For example, the internal zlib may process some pre-filter data | 49 // return. For example, the internal zlib may process some pre-filter data |
50 // but not produce output yet. | 50 // but not produce output yet. |
51 virtual FilterStatus ReadFilteredData(char* dest_buffer, | 51 FilterStatus ReadFilteredData(char* dest_buffer, int* dest_len) override; |
52 int* dest_len) override; | |
53 | 52 |
54 private: | 53 private: |
55 enum DecodingStatus { | 54 enum DecodingStatus { |
56 DECODING_UNINITIALIZED, | 55 DECODING_UNINITIALIZED, |
57 DECODING_IN_PROGRESS, | 56 DECODING_IN_PROGRESS, |
58 DECODING_DONE, | 57 DECODING_DONE, |
59 DECODING_ERROR | 58 DECODING_ERROR |
60 }; | 59 }; |
61 | 60 |
62 enum DecodingMode { | 61 enum DecodingMode { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // If this flag is set, then we will revert to being a pass through filter if | 141 // If this flag is set, then we will revert to being a pass through filter if |
143 // we don't get a valid gzip header. | 142 // we don't get a valid gzip header. |
144 bool possible_sdch_pass_through_; | 143 bool possible_sdch_pass_through_; |
145 | 144 |
146 DISALLOW_COPY_AND_ASSIGN(GZipFilter); | 145 DISALLOW_COPY_AND_ASSIGN(GZipFilter); |
147 }; | 146 }; |
148 | 147 |
149 } // namespace net | 148 } // namespace net |
150 | 149 |
151 #endif // NET_FILTER_GZIP_FILTER_H__ | 150 #endif // NET_FILTER_GZIP_FILTER_H__ |
OLD | NEW |