OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_CORE_SPDY_FRAMER_H_ | 5 #ifndef NET_SPDY_CORE_SPDY_FRAMER_H_ |
6 #define NET_SPDY_CORE_SPDY_FRAMER_H_ | 6 #define NET_SPDY_CORE_SPDY_FRAMER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <cstdint> | 11 #include <cstdint> |
12 #include <map> | 12 #include <map> |
13 #include <memory> | 13 #include <memory> |
14 #include <utility> | 14 #include <utility> |
15 | 15 |
16 #include "base/sys_byteorder.h" | 16 #include "base/sys_byteorder.h" |
17 #include "net/base/net_export.h" | |
18 #include "net/spdy/chromium/spdy_flags.h" | 17 #include "net/spdy/chromium/spdy_flags.h" |
19 #include "net/spdy/core/hpack/hpack_decoder_interface.h" | 18 #include "net/spdy/core/hpack/hpack_decoder_interface.h" |
20 #include "net/spdy/core/hpack/hpack_encoder.h" | 19 #include "net/spdy/core/hpack/hpack_encoder.h" |
21 #include "net/spdy/core/spdy_alt_svc_wire_format.h" | 20 #include "net/spdy/core/spdy_alt_svc_wire_format.h" |
22 #include "net/spdy/core/spdy_header_block.h" | 21 #include "net/spdy/core/spdy_header_block.h" |
23 #include "net/spdy/core/spdy_headers_handler_interface.h" | 22 #include "net/spdy/core/spdy_headers_handler_interface.h" |
24 #include "net/spdy/core/spdy_protocol.h" | 23 #include "net/spdy/core/spdy_protocol.h" |
25 #include "net/spdy/core/zero_copy_output_buffer.h" | 24 #include "net/spdy/core/zero_copy_output_buffer.h" |
| 25 #include "net/spdy/platform/api/spdy_export.h" |
26 #include "net/spdy/platform/api/spdy_string.h" | 26 #include "net/spdy/platform/api/spdy_string.h" |
27 #include "net/spdy/platform/api/spdy_string_piece.h" | 27 #include "net/spdy/platform/api/spdy_string_piece.h" |
28 | 28 |
29 namespace net { | 29 namespace net { |
30 | 30 |
31 class HttpProxyClientSocketPoolTest; | 31 class HttpProxyClientSocketPoolTest; |
32 class HttpNetworkLayer; | 32 class HttpNetworkLayer; |
33 class HttpNetworkTransactionTest; | 33 class HttpNetworkTransactionTest; |
34 class SpdyHttpStreamTest; | 34 class SpdyHttpStreamTest; |
35 class SpdyNetworkTransactionTest; | 35 class SpdyNetworkTransactionTest; |
(...skipping 21 matching lines...) Expand all Loading... |
57 // delivered in chunks to the visitor. | 57 // delivered in chunks to the visitor. |
58 // The following steps are followed: | 58 // The following steps are followed: |
59 // 1. OnHeaders, or OnPushPromise is called. | 59 // 1. OnHeaders, or OnPushPromise is called. |
60 // 2. OnHeaderFrameStart is called; visitor is expected to return an instance | 60 // 2. OnHeaderFrameStart is called; visitor is expected to return an instance |
61 // of SpdyHeadersHandlerInterface that will receive the header key-value | 61 // of SpdyHeadersHandlerInterface that will receive the header key-value |
62 // pairs. | 62 // pairs. |
63 // 3. OnHeaderFrameEnd is called, indicating that the full header block has | 63 // 3. OnHeaderFrameEnd is called, indicating that the full header block has |
64 // been delivered for the control frame. | 64 // been delivered for the control frame. |
65 // During step 2, if the visitor is not interested in accepting the header data, | 65 // During step 2, if the visitor is not interested in accepting the header data, |
66 // it should return a no-op implementation of SpdyHeadersHandlerInterface. | 66 // it should return a no-op implementation of SpdyHeadersHandlerInterface. |
67 class NET_EXPORT_PRIVATE SpdyFramerVisitorInterface { | 67 class SPDY_EXPORT_PRIVATE SpdyFramerVisitorInterface { |
68 public: | 68 public: |
69 virtual ~SpdyFramerVisitorInterface() {} | 69 virtual ~SpdyFramerVisitorInterface() {} |
70 | 70 |
71 // Called if an error is detected in the SpdySerializedFrame protocol. | 71 // Called if an error is detected in the SpdySerializedFrame protocol. |
72 virtual void OnError(SpdyFramer* framer) = 0; | 72 virtual void OnError(SpdyFramer* framer) = 0; |
73 | 73 |
74 // Called when the common header for a frame is received. Validating the | 74 // Called when the common header for a frame is received. Validating the |
75 // common header occurs in later processing. | 75 // common header occurs in later processing. |
76 virtual void OnCommonHeader(SpdyStreamId stream_id, | 76 virtual void OnCommonHeader(SpdyStreamId stream_id, |
77 size_t length, | 77 size_t length, |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 // no explicit indication of the end of the frame payload. | 240 // no explicit indication of the end of the frame payload. |
241 virtual void OnFramePayload(const char* data, size_t len) = 0; | 241 virtual void OnFramePayload(const char* data, size_t len) = 0; |
242 }; | 242 }; |
243 | 243 |
244 // Optionally, and in addition to SpdyFramerVisitorInterface, a class supporting | 244 // Optionally, and in addition to SpdyFramerVisitorInterface, a class supporting |
245 // SpdyFramerDebugVisitorInterface may be used in conjunction with SpdyFramer in | 245 // SpdyFramerDebugVisitorInterface may be used in conjunction with SpdyFramer in |
246 // order to extract debug/internal information about the SpdyFramer as it | 246 // order to extract debug/internal information about the SpdyFramer as it |
247 // operates. | 247 // operates. |
248 // | 248 // |
249 // Most HTTP2 implementations need not bother with this interface at all. | 249 // Most HTTP2 implementations need not bother with this interface at all. |
250 class NET_EXPORT_PRIVATE SpdyFramerDebugVisitorInterface { | 250 class SPDY_EXPORT_PRIVATE SpdyFramerDebugVisitorInterface { |
251 public: | 251 public: |
252 virtual ~SpdyFramerDebugVisitorInterface() {} | 252 virtual ~SpdyFramerDebugVisitorInterface() {} |
253 | 253 |
254 // Called after compressing a frame with a payload of | 254 // Called after compressing a frame with a payload of |
255 // a list of name-value pairs. | 255 // a list of name-value pairs. |
256 // |payload_len| is the uncompressed payload size. | 256 // |payload_len| is the uncompressed payload size. |
257 // |frame_len| is the compressed frame size. | 257 // |frame_len| is the compressed frame size. |
258 virtual void OnSendCompressedFrame(SpdyStreamId stream_id, | 258 virtual void OnSendCompressedFrame(SpdyStreamId stream_id, |
259 SpdyFrameType type, | 259 SpdyFrameType type, |
260 size_t payload_len, | 260 size_t payload_len, |
261 size_t frame_len) {} | 261 size_t frame_len) {} |
262 | 262 |
263 // Called when a frame containing a compressed payload of | 263 // Called when a frame containing a compressed payload of |
264 // name-value pairs is received. | 264 // name-value pairs is received. |
265 // |frame_len| is the compressed frame size. | 265 // |frame_len| is the compressed frame size. |
266 virtual void OnReceiveCompressedFrame(SpdyStreamId stream_id, | 266 virtual void OnReceiveCompressedFrame(SpdyStreamId stream_id, |
267 SpdyFrameType type, | 267 SpdyFrameType type, |
268 size_t frame_len) {} | 268 size_t frame_len) {} |
269 }; | 269 }; |
270 | 270 |
271 class NET_EXPORT_PRIVATE SpdyFramer { | 271 class SPDY_EXPORT_PRIVATE SpdyFramer { |
272 public: | 272 public: |
273 // HTTP2 states. | 273 // HTTP2 states. |
274 enum SpdyState { | 274 enum SpdyState { |
275 SPDY_ERROR, | 275 SPDY_ERROR, |
276 SPDY_READY_FOR_FRAME, // Framer is ready for reading the next frame. | 276 SPDY_READY_FOR_FRAME, // Framer is ready for reading the next frame. |
277 SPDY_FRAME_COMPLETE, // Framer has finished reading a frame, need to reset. | 277 SPDY_FRAME_COMPLETE, // Framer has finished reading a frame, need to reset. |
278 SPDY_READING_COMMON_HEADER, | 278 SPDY_READING_COMMON_HEADER, |
279 SPDY_CONTROL_FRAME_PAYLOAD, | 279 SPDY_CONTROL_FRAME_PAYLOAD, |
280 SPDY_READ_DATA_FRAME_PADDING_LENGTH, | 280 SPDY_READ_DATA_FRAME_PADDING_LENGTH, |
281 SPDY_CONSUME_PADDING, | 281 SPDY_CONSUME_PADDING, |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 | 386 |
387 // Given a buffer containing a serialized header block parse out a | 387 // Given a buffer containing a serialized header block parse out a |
388 // SpdyHeaderBlock, putting the results in the given header block. | 388 // SpdyHeaderBlock, putting the results in the given header block. |
389 // Returns true if successfully parsed, false otherwise. | 389 // Returns true if successfully parsed, false otherwise. |
390 bool ParseHeaderBlockInBuffer(const char* header_data, | 390 bool ParseHeaderBlockInBuffer(const char* header_data, |
391 size_t header_length, | 391 size_t header_length, |
392 SpdyHeaderBlock* block) const; | 392 SpdyHeaderBlock* block) const; |
393 | 393 |
394 // Iteratively converts a SpdyFrameWithHeaderBlockIR into an appropriate | 394 // Iteratively converts a SpdyFrameWithHeaderBlockIR into an appropriate |
395 // sequence of SpdySerializedFrames. | 395 // sequence of SpdySerializedFrames. |
396 class NET_EXPORT_PRIVATE SpdyFrameIterator { | 396 class SPDY_EXPORT_PRIVATE SpdyFrameIterator { |
397 public: | 397 public: |
398 // Creates an iterator with the provided framer. | 398 // Creates an iterator with the provided framer. |
399 // Does not take ownership of |framer|. | 399 // Does not take ownership of |framer|. |
400 // |framer| must outlive this instance. | 400 // |framer| must outlive this instance. |
401 explicit SpdyFrameIterator(SpdyFramer* framer); | 401 explicit SpdyFrameIterator(SpdyFramer* framer); |
402 virtual ~SpdyFrameIterator(); | 402 virtual ~SpdyFrameIterator(); |
403 | 403 |
404 // Serializes the next frame in the sequence to |output|. Returns the number | 404 // Serializes the next frame in the sequence to |output|. Returns the number |
405 // of bytes written to |output|. | 405 // of bytes written to |output|. |
406 virtual bool NextFrame(ZeroCopyOutputBuffer* output); | 406 virtual bool NextFrame(ZeroCopyOutputBuffer* output); |
(...skipping 23 matching lines...) Expand all Loading... |
430 bool is_first_frame_; | 430 bool is_first_frame_; |
431 bool has_next_frame_; | 431 bool has_next_frame_; |
432 | 432 |
433 // Field for debug reporting. | 433 // Field for debug reporting. |
434 size_t debug_total_size_; | 434 size_t debug_total_size_; |
435 }; | 435 }; |
436 | 436 |
437 // Iteratively converts a SpdyHeadersIR (with a possibly huge | 437 // Iteratively converts a SpdyHeadersIR (with a possibly huge |
438 // SpdyHeaderBlock) into an appropriate sequence of SpdySerializedFrames, and | 438 // SpdyHeaderBlock) into an appropriate sequence of SpdySerializedFrames, and |
439 // write to the output. | 439 // write to the output. |
440 class NET_EXPORT_PRIVATE SpdyHeaderFrameIterator : public SpdyFrameIterator { | 440 class SPDY_EXPORT_PRIVATE SpdyHeaderFrameIterator : public SpdyFrameIterator { |
441 public: | 441 public: |
442 // Does not take ownership of |framer|. Take ownership of |headers_ir|. | 442 // Does not take ownership of |framer|. Take ownership of |headers_ir|. |
443 SpdyHeaderFrameIterator(SpdyFramer* framer, | 443 SpdyHeaderFrameIterator(SpdyFramer* framer, |
444 std::unique_ptr<SpdyHeadersIR> headers_ir); | 444 std::unique_ptr<SpdyHeadersIR> headers_ir); |
445 | 445 |
446 ~SpdyHeaderFrameIterator() override; | 446 ~SpdyHeaderFrameIterator() override; |
447 | 447 |
448 private: | 448 private: |
449 SpdyFrameWithHeaderBlockIR* GetIR() const override; | 449 SpdyFrameWithHeaderBlockIR* GetIR() const override; |
450 size_t GetFrameSizeSansBlock() const override; | 450 size_t GetFrameSizeSansBlock() const override; |
451 bool SerializeGivenEncoding(const SpdyString& encoding, | 451 bool SerializeGivenEncoding(const SpdyString& encoding, |
452 ZeroCopyOutputBuffer* output) const override; | 452 ZeroCopyOutputBuffer* output) const override; |
453 | 453 |
454 const std::unique_ptr<SpdyHeadersIR> headers_ir_; | 454 const std::unique_ptr<SpdyHeadersIR> headers_ir_; |
455 }; | 455 }; |
456 | 456 |
457 // Iteratively converts a SpdyPushPromiseIR (with a possibly huge | 457 // Iteratively converts a SpdyPushPromiseIR (with a possibly huge |
458 // SpdyHeaderBlock) into an appropriate sequence of SpdySerializedFrames, and | 458 // SpdyHeaderBlock) into an appropriate sequence of SpdySerializedFrames, and |
459 // write to the output. | 459 // write to the output. |
460 class NET_EXPORT_PRIVATE SpdyPushPromiseFrameIterator | 460 class SPDY_EXPORT_PRIVATE SpdyPushPromiseFrameIterator |
461 : public SpdyFrameIterator { | 461 : public SpdyFrameIterator { |
462 public: | 462 public: |
463 // Does not take ownership of |framer|. Take ownership of |push_promise_ir|. | 463 // Does not take ownership of |framer|. Take ownership of |push_promise_ir|. |
464 SpdyPushPromiseFrameIterator( | 464 SpdyPushPromiseFrameIterator( |
465 SpdyFramer* framer, | 465 SpdyFramer* framer, |
466 std::unique_ptr<SpdyPushPromiseIR> push_promise_ir); | 466 std::unique_ptr<SpdyPushPromiseIR> push_promise_ir); |
467 | 467 |
468 ~SpdyPushPromiseFrameIterator() override; | 468 ~SpdyPushPromiseFrameIterator() override; |
469 | 469 |
470 private: | 470 private: |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
948 // rather than reading all available input. | 948 // rather than reading all available input. |
949 bool process_single_input_frame_ = false; | 949 bool process_single_input_frame_ = false; |
950 | 950 |
951 // Latched value of FLAGS_chromium_http2_flag_remove_rewritelength. | 951 // Latched value of FLAGS_chromium_http2_flag_remove_rewritelength. |
952 bool skip_rewritelength_ = false; | 952 bool skip_rewritelength_ = false; |
953 }; | 953 }; |
954 | 954 |
955 } // namespace net | 955 } // namespace net |
956 | 956 |
957 #endif // NET_SPDY_CORE_SPDY_FRAMER_H_ | 957 #endif // NET_SPDY_CORE_SPDY_FRAMER_H_ |
OLD | NEW |