| 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 #ifndef NET_SPDY_SPDY_HEADERS_BLOCK_PARSER_H_ | 5 #ifndef NET_SPDY_SPDY_HEADERS_BLOCK_PARSER_H_ |
| 6 #define NET_SPDY_SPDY_HEADERS_BLOCK_PARSER_H_ | 6 #define NET_SPDY_SPDY_HEADERS_BLOCK_PARSER_H_ |
| 7 | 7 |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
| 11 #include "net/base/net_export.h" | 11 #include "net/base/net_export.h" |
| 12 #include "net/spdy/spdy_prefixed_buffer_reader.h" | 12 #include "net/spdy/spdy_prefixed_buffer_reader.h" |
| 13 #include "net/spdy/spdy_protocol.h" | 13 #include "net/spdy/spdy_protocol.h" |
| 14 | 14 |
| 15 namespace net { | 15 namespace net { |
| 16 | 16 |
| 17 // A handler class for SPDY headers. | 17 // A handler class for SPDY headers. |
| 18 class SpdyHeadersHandlerInterface { | 18 class SpdyHeadersHandlerInterface { |
| 19 public: | 19 public: |
| 20 virtual ~SpdyHeadersHandlerInterface() {} | 20 virtual ~SpdyHeadersHandlerInterface() {} |
| 21 | 21 |
| 22 // A callback method which notifies when the parser starts handling a new | 22 // A callback method which notifies when the parser starts handling a new |
| 23 // SPDY headers block, this method also notifies on the number of headers in | 23 // SPDY headers block, this method also notifies on the number of headers in |
| 24 // the block. | 24 // the block. |
| 25 virtual void OnHeaderBlock(SpdyStreamId stream_id, | 25 virtual void OnHeaderBlock(uint32_t num_of_headers) = 0; |
| 26 uint32_t num_of_headers) = 0; | |
| 27 | 26 |
| 28 // A callback method which notifies on a SPDY header key value pair. | 27 // A callback method which notifies on a SPDY header key value pair. |
| 29 virtual void OnHeader(SpdyStreamId stream_id, | 28 virtual void OnHeader(base::StringPiece key, base::StringPiece value) = 0; |
| 30 base::StringPiece key, | |
| 31 base::StringPiece value) = 0; | |
| 32 | 29 |
| 33 // A callback method which notifies when the parser finishes handling a SPDY | 30 // A callback method which notifies when the parser finishes handling a SPDY |
| 34 // headers block. Also notifies on the total number of bytes in this block. | 31 // headers block. Also notifies on the total number of bytes in this block. |
| 35 virtual void OnHeaderBlockEnd(SpdyStreamId stream_id, | 32 virtual void OnHeaderBlockEnd(size_t header_bytes_parsed) = 0; |
| 36 size_t header_bytes_parsed) = 0; | |
| 37 }; | 33 }; |
| 38 | 34 |
| 39 namespace test { | 35 namespace test { |
| 40 | 36 |
| 41 class SpdyHeadersBlockParserPeer; | 37 class SpdyHeadersBlockParserPeer; |
| 42 | 38 |
| 43 } // namespace test | 39 } // namespace test |
| 44 | 40 |
| 45 // This class handles SPDY headers block bytes and parses out key-value pairs | 41 // This class handles SPDY headers block bytes and parses out key-value pairs |
| 46 // as they arrive. This class is not thread-safe, and assumes that all headers | 42 // as they arrive. This class is not thread-safe, and assumes that all headers |
| (...skipping 21 matching lines...) Expand all Loading... |
| 68 OK, | 64 OK, |
| 69 // Set when parsing failed due to insufficient data. | 65 // Set when parsing failed due to insufficient data. |
| 70 // This error is recoverable, by passing in new data. | 66 // This error is recoverable, by passing in new data. |
| 71 NEED_MORE_DATA, | 67 NEED_MORE_DATA, |
| 72 // Set when a complete block has been read, but unprocessed data remains. | 68 // Set when a complete block has been read, but unprocessed data remains. |
| 73 TOO_MUCH_DATA, | 69 TOO_MUCH_DATA, |
| 74 // Set when a block exceeds |MaxNumberOfHeadersForVersion| headers. | 70 // Set when a block exceeds |MaxNumberOfHeadersForVersion| headers. |
| 75 HEADER_BLOCK_TOO_LARGE, | 71 HEADER_BLOCK_TOO_LARGE, |
| 76 // Set when a header key or value exceeds |kMaximumFieldLength|. | 72 // Set when a header key or value exceeds |kMaximumFieldLength|. |
| 77 HEADER_FIELD_TOO_LARGE, | 73 HEADER_FIELD_TOO_LARGE, |
| 74 // Set when the parser is given an unexpected stream ID. |
| 75 UNEXPECTED_STREAM_ID, |
| 78 }; | 76 }; |
| 79 ParserError get_error() const { return error_; } | 77 ParserError get_error() const { return error_; } |
| 80 | 78 |
| 81 SpdyMajorVersion spdy_version() const { return spdy_version_; } | 79 SpdyMajorVersion spdy_version() const { return spdy_version_; } |
| 82 | 80 |
| 83 // Returns the size in bytes of a length field in a SPDY header. | 81 // Returns the size in bytes of a length field in a SPDY header. |
| 84 static size_t LengthFieldSizeForVersion(SpdyMajorVersion spdy_version); | 82 static size_t LengthFieldSizeForVersion(SpdyMajorVersion spdy_version); |
| 85 | 83 |
| 86 // Returns the maximal number of headers in a SPDY headers block. | 84 // Returns the maximal number of headers in a SPDY headers block. |
| 87 static size_t MaxNumberOfHeadersForVersion(SpdyMajorVersion spdy_version); | 85 static size_t MaxNumberOfHeadersForVersion(SpdyMajorVersion spdy_version); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 SpdyStreamId stream_id_; | 138 SpdyStreamId stream_id_; |
| 141 | 139 |
| 142 ParserError error_; | 140 ParserError error_; |
| 143 | 141 |
| 144 const SpdyMajorVersion spdy_version_; | 142 const SpdyMajorVersion spdy_version_; |
| 145 }; | 143 }; |
| 146 | 144 |
| 147 } // namespace net | 145 } // namespace net |
| 148 | 146 |
| 149 #endif // NET_SPDY_SPDY_HEADERS_BLOCK_PARSER_H_ | 147 #endif // NET_SPDY_SPDY_HEADERS_BLOCK_PARSER_H_ |
| OLD | NEW |