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 <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 <string> | |
15 #include <utility> | 14 #include <utility> |
16 | 15 |
17 #include "base/sys_byteorder.h" | 16 #include "base/sys_byteorder.h" |
18 #include "net/base/net_export.h" | 17 #include "net/base/net_export.h" |
19 #include "net/spdy/hpack/hpack_decoder_interface.h" | 18 #include "net/spdy/hpack/hpack_decoder_interface.h" |
20 #include "net/spdy/hpack/hpack_encoder.h" | 19 #include "net/spdy/hpack/hpack_encoder.h" |
| 20 #include "net/spdy/platform/api/spdy_string.h" |
21 #include "net/spdy/platform/api/spdy_string_piece.h" | 21 #include "net/spdy/platform/api/spdy_string_piece.h" |
22 #include "net/spdy/spdy_alt_svc_wire_format.h" | 22 #include "net/spdy/spdy_alt_svc_wire_format.h" |
23 #include "net/spdy/spdy_flags.h" | 23 #include "net/spdy/spdy_flags.h" |
24 #include "net/spdy/spdy_header_block.h" | 24 #include "net/spdy/spdy_header_block.h" |
25 #include "net/spdy/spdy_headers_handler_interface.h" | 25 #include "net/spdy/spdy_headers_handler_interface.h" |
26 #include "net/spdy/spdy_protocol.h" | 26 #include "net/spdy/spdy_protocol.h" |
27 #include "net/spdy/zero_copy_output_buffer.h" | 27 #include "net/spdy/zero_copy_output_buffer.h" |
28 | 28 |
29 namespace net { | 29 namespace net { |
30 | 30 |
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 // Always passed exactly 1 setting's worth of data. | 696 // Always passed exactly 1 setting's worth of data. |
697 bool ProcessSetting(const char* data); | 697 bool ProcessSetting(const char* data); |
698 | 698 |
699 // Get (and lazily initialize) the HPACK state. | 699 // Get (and lazily initialize) the HPACK state. |
700 HpackEncoder* GetHpackEncoder(); | 700 HpackEncoder* GetHpackEncoder(); |
701 HpackDecoderInterface* GetHpackDecoder(); | 701 HpackDecoderInterface* GetHpackDecoder(); |
702 | 702 |
703 size_t GetNumberRequiredContinuationFrames(size_t size); | 703 size_t GetNumberRequiredContinuationFrames(size_t size); |
704 | 704 |
705 bool WritePayloadWithContinuation(SpdyFrameBuilder* builder, | 705 bool WritePayloadWithContinuation(SpdyFrameBuilder* builder, |
706 const std::string& hpack_encoding, | 706 const SpdyString& hpack_encoding, |
707 SpdyStreamId stream_id, | 707 SpdyStreamId stream_id, |
708 SpdyFrameType type, | 708 SpdyFrameType type, |
709 int padding_payload_len); | 709 int padding_payload_len); |
710 | 710 |
711 // Utility to copy the given data block to the current frame buffer, up | 711 // Utility to copy the given data block to the current frame buffer, up |
712 // to the given maximum number of bytes, and update the buffer | 712 // to the given maximum number of bytes, and update the buffer |
713 // data (pointer and length). Returns the number of bytes | 713 // data (pointer and length). Returns the number of bytes |
714 // read, and: | 714 // read, and: |
715 // *data is advanced the number of bytes read. | 715 // *data is advanced the number of bytes read. |
716 // *len is reduced by the number of bytes read. | 716 // *len is reduced by the number of bytes read. |
717 size_t UpdateCurrentFrameBuffer(const char** data, size_t* len, | 717 size_t UpdateCurrentFrameBuffer(const char** data, size_t* len, |
718 size_t max_bytes); | 718 size_t max_bytes); |
719 | 719 |
720 // Serializes a HEADERS frame from the given SpdyHeadersIR and encoded header | 720 // Serializes a HEADERS frame from the given SpdyHeadersIR and encoded header |
721 // block. Does not need or use the SpdyHeaderBlock inside SpdyHeadersIR. | 721 // block. Does not need or use the SpdyHeaderBlock inside SpdyHeadersIR. |
722 SpdySerializedFrame SerializeHeadersGivenEncoding( | 722 SpdySerializedFrame SerializeHeadersGivenEncoding( |
723 const SpdyHeadersIR& headers, | 723 const SpdyHeadersIR& headers, |
724 const std::string& encoding) const; | 724 const SpdyString& encoding) const; |
725 | 725 |
726 // Calculates the number of bytes required to serialize a SpdyHeadersIR, not | 726 // Calculates the number of bytes required to serialize a SpdyHeadersIR, not |
727 // including the bytes to be used for the encoded header set. | 727 // including the bytes to be used for the encoded header set. |
728 size_t GetHeaderFrameSizeSansBlock(const SpdyHeadersIR& header_ir) const; | 728 size_t GetHeaderFrameSizeSansBlock(const SpdyHeadersIR& header_ir) const; |
729 | 729 |
730 // Serializes the flags octet for a given SpdyHeadersIR. | 730 // Serializes the flags octet for a given SpdyHeadersIR. |
731 uint8_t SerializeHeaderFrameFlags(const SpdyHeadersIR& header_ir) const; | 731 uint8_t SerializeHeaderFrameFlags(const SpdyHeadersIR& header_ir) const; |
732 | 732 |
733 // Set the error code and moves the framer into the error state. | 733 // Set the error code and moves the framer into the error state. |
734 void set_error(SpdyFramerError error); | 734 void set_error(SpdyFramerError error); |
735 | 735 |
736 // Helper functions to prepare the input for SpdyFrameBuilder. | 736 // Helper functions to prepare the input for SpdyFrameBuilder. |
737 void SerializeDataBuilderHelper(const SpdyDataIR& data_ir, | 737 void SerializeDataBuilderHelper(const SpdyDataIR& data_ir, |
738 uint8_t* flags, | 738 uint8_t* flags, |
739 int* num_padding_fields, | 739 int* num_padding_fields, |
740 size_t* size_with_padding) const; | 740 size_t* size_with_padding) const; |
741 void SerializeDataFrameHeaderWithPaddingLengthFieldBuilderHelper( | 741 void SerializeDataFrameHeaderWithPaddingLengthFieldBuilderHelper( |
742 const SpdyDataIR& data_ir, | 742 const SpdyDataIR& data_ir, |
743 uint8_t* flags, | 743 uint8_t* flags, |
744 size_t* frame_size, | 744 size_t* frame_size, |
745 size_t* num_padding_fields) const; | 745 size_t* num_padding_fields) const; |
746 void SerializeSettingsBuilderHelper(const SpdySettingsIR& settings, | 746 void SerializeSettingsBuilderHelper(const SpdySettingsIR& settings, |
747 uint8_t* flags, | 747 uint8_t* flags, |
748 const SettingsMap* values, | 748 const SettingsMap* values, |
749 size_t* size) const; | 749 size_t* size) const; |
750 void SerializeAltSvcBuilderHelper(const SpdyAltSvcIR& altsvc_ir, | 750 void SerializeAltSvcBuilderHelper(const SpdyAltSvcIR& altsvc_ir, |
751 std::string* value, | 751 SpdyString* value, |
752 size_t* size) const; | 752 size_t* size) const; |
753 void SerializeHeadersBuilderHelper(const SpdyHeadersIR& headers, | 753 void SerializeHeadersBuilderHelper(const SpdyHeadersIR& headers, |
754 uint8_t* flags, | 754 uint8_t* flags, |
755 size_t* size, | 755 size_t* size, |
756 std::string* hpack_encoding, | 756 SpdyString* hpack_encoding, |
757 int* weight, | 757 int* weight, |
758 size_t* length_field); | 758 size_t* length_field); |
759 void SerializePushPromiseBuilderHelper(const SpdyPushPromiseIR& push_promise, | 759 void SerializePushPromiseBuilderHelper(const SpdyPushPromiseIR& push_promise, |
760 uint8_t* flags, | 760 uint8_t* flags, |
761 std::string* hpack_encoding, | 761 SpdyString* hpack_encoding, |
762 size_t* size); | 762 size_t* size); |
763 | 763 |
764 // The size of the control frame buffer. | 764 // The size of the control frame buffer. |
765 // Since this is only used for control frame headers, the maximum control | 765 // Since this is only used for control frame headers, the maximum control |
766 // frame header size is sufficient; all remaining control | 766 // frame header size is sufficient; all remaining control |
767 // frame data is streamed to the visitor. | 767 // frame data is streamed to the visitor. |
768 static const size_t kControlFrameBufferSize; | 768 static const size_t kControlFrameBufferSize; |
769 | 769 |
770 // The maximum size of the control frames that we send, including the size of | 770 // The maximum size of the control frames that we send, including the size of |
771 // the header. This limit is arbitrary. We can enforce it here or at the | 771 // the header. This limit is arbitrary. We can enforce it here or at the |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
861 // rather than reading all available input. | 861 // rather than reading all available input. |
862 bool process_single_input_frame_ = false; | 862 bool process_single_input_frame_ = false; |
863 | 863 |
864 // Latched value of FLAGS_chromium_http2_flag_remove_rewritelength. | 864 // Latched value of FLAGS_chromium_http2_flag_remove_rewritelength. |
865 bool skip_rewritelength_ = false; | 865 bool skip_rewritelength_ = false; |
866 }; | 866 }; |
867 | 867 |
868 } // namespace net | 868 } // namespace net |
869 | 869 |
870 #endif // NET_SPDY_SPDY_FRAMER_H_ | 870 #endif // NET_SPDY_SPDY_FRAMER_H_ |
OLD | NEW |