Chromium Code Reviews| Index: net/filter/gzip_stream_source.h |
| diff --git a/net/filter/gzip_stream_source.h b/net/filter/gzip_stream_source.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0ddad01ab7f7f147ab28bcab7ccaa7a9212e5cd5 |
| --- /dev/null |
| +++ b/net/filter/gzip_stream_source.h |
| @@ -0,0 +1,83 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/memory/scoped_ptr.h" |
| +#include "net/filter/gzip_header.h" |
| +#include "net/filter/stream_source.h" |
| + |
| +typedef struct z_stream_s z_stream; |
|
mmenke
2016/03/04 21:15:56
I don't think we want this in the global namespace
xunjieli
2016/04/20 19:16:09
I tried this suggestion, but the code failed to co
|
| + |
| +namespace net { |
| + |
| +class BlockBuffer; |
| + |
| +class GzipStreamSource : public StreamSource { |
| + public: |
| + enum GzipStreamSourceMode { |
| + GZIP_STREAM_SOURCE_DEFLATE, |
| + GZIP_STREAM_SOURCE_GZIP, |
| + }; |
| + |
| + GzipStreamSource(scoped_ptr<StreamSource> previous); |
|
mmenke
2016/03/04 21:15:56
explicit
xunjieli
2016/04/20 19:16:09
Done.
|
| + ~GzipStreamSource() override; |
| + |
| + bool Init(GzipStreamSourceMode mode, bool gzip_fallback); |
|
mmenke
2016/03/04 21:15:56
These arguments need to be documented.
xunjieli
2016/04/20 19:16:09
Done.
|
| + |
| + private: |
| + enum GzipStreamState { |
| + GZIP_STREAM_ERROR, |
| + GZIP_STREAM_MORE_INPUT, |
| + GZIP_STREAM_MORE_OUTPUT_SPACE, |
| + }; |
| + |
| + // StreamSource implementation |
| + Error ReadInternal(IOBuffer* dest_buffer, |
| + size_t buffer_size, |
| + size_t* bytes_read) override; |
| + |
| + GzipStreamState Decompress(IOBuffer* dest_buffer, |
| + size_t buffer_size, |
| + size_t* bytes_read); |
| + |
| + GzipStreamState Passthrough(IOBuffer* dest_buffer, |
| + size_t buffer_size, |
| + size_t* bytes_read); |
| + |
| + void OnReadComplete(const OnReadCompleteCallback& callback, |
| + IOBuffer* dest_buffer, |
| + size_t dest_buffer_size, |
| + Error error, |
| + size_t bytes_read); |
| + |
| + bool InsertZlibHeader(); |
| + |
| + // Returns whether an invalid GZip header has been observed. This method |
| + // returns true as soon as an invalid GZip header is observed; it returns |
| + // false if a complete, valid header has been observed, or not enough bytes |
| + // have been seen to be sure. This method pulls its input from |buffer_|. |
| + bool IsGzipHeaderInvalid(); |
| + |
| + // Returns whether this stream looks like it could be plain text (ie, not |
| + // actually gzipped). Right now this uses an extremely simple heuristic; see |
| + // the source for details. This method checks the input in |buffer_|, but does |
| + // not drain from it. |
| + bool ShouldFallbackToPlain(); |
| + |
| + // Skips gzip footer bytes if necessary. Might drain input from |buffer_| if |
| + // there are still footer bytes to read. |
| + void SkipGzipFooterIfNeeded(); |
| + |
| + scoped_refptr<IOBuffer> pending_read_buffer_; |
| + |
| + scoped_ptr<z_stream> zlib_stream_; |
| + bool zlib_eof_; |
| + bool zlib_header_added_; |
| + |
| + GZipHeader gzip_header_; |
| + bool gzip_header_unchecked_; |
| + bool gzip_fallback_unchecked_; |
|
mmenke
2016/03/04 21:15:56
These need to be documented. Also, "unchecked" is
xunjieli
2016/04/20 19:16:09
Done.
|
| + size_t gzip_footer_bytes_left_; |
| +}; |
| + |
| +} // namespace net |