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_SPDY_FRAMER_H_ | 5 #ifndef NET_SPDY_SPDY_FRAMER_H_ |
6 #define NET_SPDY_SPDY_FRAMER_H_ | 6 #define NET_SPDY_SPDY_FRAMER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 HpackDecoder* GetHpackDecoder(); | 670 HpackDecoder* GetHpackDecoder(); |
671 | 671 |
672 size_t GetNumberRequiredContinuationFrames(size_t size); | 672 size_t GetNumberRequiredContinuationFrames(size_t size); |
673 | 673 |
674 void WritePayloadWithContinuation(SpdyFrameBuilder* builder, | 674 void WritePayloadWithContinuation(SpdyFrameBuilder* builder, |
675 const std::string& hpack_encoding, | 675 const std::string& hpack_encoding, |
676 SpdyStreamId stream_id, | 676 SpdyStreamId stream_id, |
677 SpdyFrameType type, | 677 SpdyFrameType type, |
678 int padding_payload_len); | 678 int padding_payload_len); |
679 | 679 |
680 private: | |
681 // Deliver the given control frame's uncompressed headers block to the | 680 // Deliver the given control frame's uncompressed headers block to the |
682 // visitor in chunks. Returns true if the visitor has accepted all of the | 681 // visitor in chunks. Returns true if the visitor has accepted all of the |
683 // chunks. | 682 // chunks. |
684 bool IncrementallyDeliverControlFrameHeaderData(SpdyStreamId stream_id, | 683 bool IncrementallyDeliverControlFrameHeaderData(SpdyStreamId stream_id, |
685 const char* data, | 684 const char* data, |
686 size_t len); | 685 size_t len); |
687 | 686 |
688 // Utility to copy the given data block to the current frame buffer, up | 687 // Utility to copy the given data block to the current frame buffer, up |
689 // to the given maximum number of bytes, and update the buffer | 688 // to the given maximum number of bytes, and update the buffer |
690 // data (pointer and length). Returns the number of bytes | 689 // data (pointer and length). Returns the number of bytes |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 // are part of the frame's payload, and not the frame's headers. | 737 // are part of the frame's payload, and not the frame's headers. |
739 size_t remaining_control_header_; | 738 size_t remaining_control_header_; |
740 | 739 |
741 scoped_ptr<char[]> current_frame_buffer_; | 740 scoped_ptr<char[]> current_frame_buffer_; |
742 // Number of bytes read into the current_frame_buffer_. | 741 // Number of bytes read into the current_frame_buffer_. |
743 size_t current_frame_buffer_length_; | 742 size_t current_frame_buffer_length_; |
744 | 743 |
745 // The type of the frame currently being read. | 744 // The type of the frame currently being read. |
746 SpdyFrameType current_frame_type_; | 745 SpdyFrameType current_frame_type_; |
747 | 746 |
748 // The flags field of the frame currently being read. | |
749 uint8 current_frame_flags_; | |
750 | |
751 // The total length of the frame currently being read, including frame header. | 747 // The total length of the frame currently being read, including frame header. |
752 uint32 current_frame_length_; | 748 uint32 current_frame_length_; |
753 | 749 |
754 // The stream ID field of the frame currently being read, if applicable. | 750 // The stream ID field of the frame currently being read, if applicable. |
755 SpdyStreamId current_frame_stream_id_; | 751 SpdyStreamId current_frame_stream_id_; |
756 | 752 |
| 753 // Set this to the current stream when we receive a HEADERS, PUSH_PROMISE, or |
| 754 // CONTINUATION frame without the END_HEADERS(0x4) bit set. These frames must |
| 755 // be followed by a CONTINUATION frame, or else we throw a PROTOCOL_ERROR. |
| 756 // A value of 0 indicates that we are not expecting a CONTINUATION frame. |
| 757 SpdyStreamId expect_continuation_; |
| 758 |
757 // Scratch space for handling SETTINGS frames. | 759 // Scratch space for handling SETTINGS frames. |
758 // TODO(hkhalil): Unify memory for this scratch space with | 760 // TODO(hkhalil): Unify memory for this scratch space with |
759 // current_frame_buffer_. | 761 // current_frame_buffer_. |
760 SpdySettingsScratch settings_scratch_; | 762 SpdySettingsScratch settings_scratch_; |
761 | 763 |
762 SpdyAltSvcScratch altsvc_scratch_; | 764 SpdyAltSvcScratch altsvc_scratch_; |
763 | 765 |
764 bool enable_compression_; // Controls all compression | |
765 // SPDY header compressors. | 766 // SPDY header compressors. |
766 scoped_ptr<z_stream> header_compressor_; | 767 scoped_ptr<z_stream> header_compressor_; |
767 scoped_ptr<z_stream> header_decompressor_; | 768 scoped_ptr<z_stream> header_decompressor_; |
768 | 769 |
769 scoped_ptr<HpackEncoder> hpack_encoder_; | 770 scoped_ptr<HpackEncoder> hpack_encoder_; |
770 scoped_ptr<HpackDecoder> hpack_decoder_; | 771 scoped_ptr<HpackDecoder> hpack_decoder_; |
771 | 772 |
772 SpdyFramerVisitorInterface* visitor_; | 773 SpdyFramerVisitorInterface* visitor_; |
773 SpdyFramerDebugVisitorInterface* debug_visitor_; | 774 SpdyFramerDebugVisitorInterface* debug_visitor_; |
774 | 775 |
775 std::string display_protocol_; | 776 std::string display_protocol_; |
776 | 777 |
777 // The protocol version to be spoken/understood by this framer. | 778 // The protocol version to be spoken/understood by this framer. |
778 const SpdyMajorVersion protocol_version_; | 779 const SpdyMajorVersion protocol_version_; |
779 | 780 |
| 781 // The flags field of the frame currently being read. |
| 782 uint8 current_frame_flags_; |
| 783 |
| 784 // Determines whether HPACK or gzip compression is used. |
| 785 bool enable_compression_; |
| 786 |
780 // Tracks if we've ever gotten far enough in framing to see a control frame of | 787 // Tracks if we've ever gotten far enough in framing to see a control frame of |
781 // type SYN_STREAM or SYN_REPLY. | 788 // type SYN_STREAM or SYN_REPLY. |
782 // | 789 // |
783 // If we ever get something which looks like a data frame before we've had a | 790 // If we ever get something which looks like a data frame before we've had a |
784 // SYN, we explicitly check to see if it looks like we got an HTTP response | 791 // SYN, we explicitly check to see if it looks like we got an HTTP response |
785 // to a SPDY request. This boolean lets us do that. | 792 // to a SPDY request. This boolean lets us do that. |
786 bool syn_frame_processed_; | 793 bool syn_frame_processed_; |
787 | 794 |
788 // If we ever get a data frame before a SYN frame, we check to see if it | 795 // If we ever get a data frame before a SYN frame, we check to see if it |
789 // starts with HTTP. If it does, we likely have an HTTP response. This | 796 // starts with HTTP. If it does, we likely have an HTTP response. This |
790 // isn't guaranteed though: we could have gotten a settings frame and then | 797 // isn't guaranteed though: we could have gotten a settings frame and then |
791 // corrupt data that just looks like HTTP, but deterministic checking requires | 798 // corrupt data that just looks like HTTP, but deterministic checking requires |
792 // a lot more state. | 799 // a lot more state. |
793 bool probable_http_response_; | 800 bool probable_http_response_; |
794 | 801 |
795 // Set this to the current stream when we receive a HEADERS, PUSH_PROMISE, or | |
796 // CONTINUATION frame without the END_HEADERS(0x4) bit set. These frames must | |
797 // be followed by a CONTINUATION frame, or else we throw a PROTOCOL_ERROR. | |
798 // A value of 0 indicates that we are not expecting a CONTINUATION frame. | |
799 SpdyStreamId expect_continuation_; | |
800 | |
801 // If a HEADERS frame is followed by a CONTINUATION frame, the FIN/END_STREAM | 802 // If a HEADERS frame is followed by a CONTINUATION frame, the FIN/END_STREAM |
802 // flag is still carried in the HEADERS frame. If it's set, flip this so that | 803 // flag is still carried in the HEADERS frame. If it's set, flip this so that |
803 // we know to terminate the stream when the entire header block has been | 804 // we know to terminate the stream when the entire header block has been |
804 // processed. | 805 // processed. |
805 bool end_stream_when_done_; | 806 bool end_stream_when_done_; |
806 }; | 807 }; |
807 | 808 |
808 } // namespace net | 809 } // namespace net |
809 | 810 |
810 #endif // NET_SPDY_SPDY_FRAMER_H_ | 811 #endif // NET_SPDY_SPDY_FRAMER_H_ |
OLD | NEW |