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 #include "net/spdy/spdy_framer.h" | 5 #include "net/spdy/spdy_framer.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/metrics/stats_counters.h" | 9 #include "base/metrics/stats_counters.h" |
10 #include "base/third_party/valgrind/memcheck.h" | 10 #include "base/third_party/valgrind/memcheck.h" |
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
682 } | 682 } |
683 | 683 |
684 // Using a scoped_ptr here since we may need to create a new SpdyFrameReader | 684 // Using a scoped_ptr here since we may need to create a new SpdyFrameReader |
685 // when processing DATA frames below. | 685 // when processing DATA frames below. |
686 scoped_ptr<SpdyFrameReader> reader( | 686 scoped_ptr<SpdyFrameReader> reader( |
687 new SpdyFrameReader(current_frame_buffer_.get(), | 687 new SpdyFrameReader(current_frame_buffer_.get(), |
688 current_frame_buffer_length_)); | 688 current_frame_buffer_length_)); |
689 | 689 |
690 bool is_control_frame = false; | 690 bool is_control_frame = false; |
691 | 691 |
692 uint16 control_frame_type_field = | 692 int control_frame_type_field = |
693 SpdyConstants::DataFrameType(protocol_version()); | 693 SpdyConstants::DataFrameType(protocol_version()); |
694 // ProcessControlFrameHeader() will set current_frame_type_ to the | 694 // ProcessControlFrameHeader() will set current_frame_type_ to the |
695 // correct value if this is a valid control frame. | 695 // correct value if this is a valid control frame. |
696 current_frame_type_ = DATA; | 696 current_frame_type_ = DATA; |
697 if (protocol_version() <= SPDY3) { | 697 if (protocol_version() <= SPDY3) { |
698 uint16 version = 0; | 698 uint16 version = 0; |
699 bool successful_read = reader->ReadUInt16(&version); | 699 bool successful_read = reader->ReadUInt16(&version); |
700 DCHECK(successful_read); | 700 DCHECK(successful_read); |
701 is_control_frame = (version & kControlFlagMask) != 0; | 701 is_control_frame = (version & kControlFlagMask) != 0; |
702 version &= ~kControlFlagMask; // Only valid for control frames. | 702 version &= ~kControlFlagMask; // Only valid for control frames. |
703 if (is_control_frame) { | 703 if (is_control_frame) { |
704 // We check version before we check validity: version can never be | 704 // We check version before we check validity: version can never be |
705 // 'invalid', it can only be unsupported. | 705 // 'invalid', it can only be unsupported. |
706 if (version < SpdyConstants::SerializeMajorVersion(SPDY_MIN_VERSION) || | 706 if (version < SpdyConstants::SerializeMajorVersion(SPDY_MIN_VERSION) || |
707 version > SpdyConstants::SerializeMajorVersion(SPDY_MAX_VERSION) || | 707 version > SpdyConstants::SerializeMajorVersion(SPDY_MAX_VERSION) || |
708 SpdyConstants::ParseMajorVersion(version) != protocol_version()) { | 708 SpdyConstants::ParseMajorVersion(version) != protocol_version()) { |
709 // Version does not match the version the framer was initialized with. | 709 // Version does not match the version the framer was initialized with. |
710 DVLOG(1) << "Unsupported SPDY version " | 710 DVLOG(1) << "Unsupported SPDY version " |
711 << version | 711 << version |
712 << " (expected " << protocol_version() << ")"; | 712 << " (expected " << protocol_version() << ")"; |
713 set_error(SPDY_UNSUPPORTED_VERSION); | 713 set_error(SPDY_UNSUPPORTED_VERSION); |
714 return 0; | 714 return 0; |
715 } | 715 } |
716 // We check control_frame_type_field's validity in | 716 // We check control_frame_type_field's validity in |
717 // ProcessControlFrameHeader(). | 717 // ProcessControlFrameHeader(). |
718 successful_read = reader->ReadUInt16(&control_frame_type_field); | 718 uint16 control_frame_type_field_uint16; |
719 successful_read = reader->ReadUInt16(&control_frame_type_field_uint16); | |
720 control_frame_type_field = control_frame_type_field_uint16; | |
719 } else { | 721 } else { |
720 reader->Rewind(); | 722 reader->Rewind(); |
721 successful_read = reader->ReadUInt31(¤t_frame_stream_id_); | 723 successful_read = reader->ReadUInt31(¤t_frame_stream_id_); |
722 } | 724 } |
723 DCHECK(successful_read); | 725 DCHECK(successful_read); |
724 | 726 |
725 successful_read = reader->ReadUInt8(¤t_frame_flags_); | 727 successful_read = reader->ReadUInt8(¤t_frame_flags_); |
726 DCHECK(successful_read); | 728 DCHECK(successful_read); |
727 | 729 |
728 uint32 length_field = 0; | 730 uint32 length_field = 0; |
729 successful_read = reader->ReadUInt24(&length_field); | 731 successful_read = reader->ReadUInt24(&length_field); |
730 DCHECK(successful_read); | 732 DCHECK(successful_read); |
731 remaining_data_length_ = length_field; | 733 remaining_data_length_ = length_field; |
732 current_frame_length_ = remaining_data_length_ + reader->GetBytesConsumed(); | 734 current_frame_length_ = remaining_data_length_ + reader->GetBytesConsumed(); |
733 } else { | 735 } else { |
734 uint32 length_field = 0; | 736 uint32 length_field = 0; |
735 bool successful_read = reader->ReadUInt24(&length_field); | 737 bool successful_read = reader->ReadUInt24(&length_field); |
736 DCHECK(successful_read); | 738 DCHECK(successful_read); |
737 | 739 |
738 uint8 control_frame_type_field_uint8 = | 740 uint8 control_frame_type_field_uint8; |
739 SpdyConstants::DataFrameType(protocol_version()); | |
740 successful_read = reader->ReadUInt8(&control_frame_type_field_uint8); | 741 successful_read = reader->ReadUInt8(&control_frame_type_field_uint8); |
741 DCHECK(successful_read); | 742 DCHECK(successful_read); |
742 // We check control_frame_type_field's validity in | 743 // We check control_frame_type_field's validity in |
743 // ProcessControlFrameHeader(). | 744 // ProcessControlFrameHeader(). |
744 control_frame_type_field = control_frame_type_field_uint8; | 745 control_frame_type_field = control_frame_type_field_uint8; |
745 is_control_frame = (protocol_version() > SPDY3) ? | 746 is_control_frame = control_frame_type_field != |
746 control_frame_type_field != | 747 ((protocol_version() > SPDY3) ? |
Bence
2014/12/05 17:22:01
From line 697, we know that protocol() > SPDY3. T
Peter Kasting
2014/12/05 19:21:27
Done.
| |
747 SpdyConstants::SerializeFrameType(protocol_version(), DATA) : | 748 SpdyConstants::SerializeFrameType(protocol_version(), DATA) : 0); |
748 control_frame_type_field != 0; | |
749 | 749 |
750 if (is_control_frame) { | 750 if (is_control_frame) { |
751 current_frame_length_ = length_field + GetControlFrameHeaderSize(); | 751 current_frame_length_ = length_field + GetControlFrameHeaderSize(); |
752 } else { | 752 } else { |
753 current_frame_length_ = length_field + GetDataFrameMinimumSize(); | 753 current_frame_length_ = length_field + GetDataFrameMinimumSize(); |
754 } | 754 } |
755 | 755 |
756 successful_read = reader->ReadUInt8(¤t_frame_flags_); | 756 successful_read = reader->ReadUInt8(¤t_frame_flags_); |
757 DCHECK(successful_read); | 757 DCHECK(successful_read); |
758 | 758 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
831 CHANGE_STATE(SPDY_AUTO_RESET); | 831 CHANGE_STATE(SPDY_AUTO_RESET); |
832 } | 832 } |
833 } | 833 } |
834 } else { | 834 } else { |
835 ProcessControlFrameHeader(control_frame_type_field); | 835 ProcessControlFrameHeader(control_frame_type_field); |
836 } | 836 } |
837 | 837 |
838 return original_len - len; | 838 return original_len - len; |
839 } | 839 } |
840 | 840 |
841 void SpdyFramer::ProcessControlFrameHeader(uint16 control_frame_type_field) { | 841 void SpdyFramer::ProcessControlFrameHeader(int control_frame_type_field) { |
842 DCHECK_EQ(SPDY_NO_ERROR, error_code_); | 842 DCHECK_EQ(SPDY_NO_ERROR, error_code_); |
843 DCHECK_LE(GetControlFrameHeaderSize(), current_frame_buffer_length_); | 843 DCHECK_LE(GetControlFrameHeaderSize(), current_frame_buffer_length_); |
844 | 844 |
845 // TODO(mlavan): Either remove credential frames from the code entirely, | 845 // TODO(mlavan): Either remove credential frames from the code entirely, |
846 // or add them to parsing + serialization methods for SPDY3. | 846 // or add them to parsing + serialization methods for SPDY3. |
847 // Early detection of deprecated frames that we ignore. | 847 // Early detection of deprecated frames that we ignore. |
848 if (protocol_version() <= SPDY3) { | 848 if (protocol_version() <= SPDY3) { |
849 if (control_frame_type_field == CREDENTIAL) { | 849 if (control_frame_type_field == CREDENTIAL) { |
850 current_frame_type_ = CREDENTIAL; | 850 current_frame_type_ = CREDENTIAL; |
851 DCHECK_EQ(SPDY3, protocol_version()); | 851 DCHECK_EQ(SPDY3, protocol_version()); |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1184 total_length += length_of_name_size + it->first.size() + | 1184 total_length += length_of_name_size + it->first.size() + |
1185 length_of_value_size + it->second.size(); | 1185 length_of_value_size + it->second.size(); |
1186 } | 1186 } |
1187 return total_length; | 1187 return total_length; |
1188 } | 1188 } |
1189 | 1189 |
1190 void SpdyFramer::WriteHeaderBlock(SpdyFrameBuilder* frame, | 1190 void SpdyFramer::WriteHeaderBlock(SpdyFrameBuilder* frame, |
1191 const SpdyMajorVersion spdy_version, | 1191 const SpdyMajorVersion spdy_version, |
1192 const SpdyHeaderBlock* headers) { | 1192 const SpdyHeaderBlock* headers) { |
1193 if (spdy_version < SPDY3) { | 1193 if (spdy_version < SPDY3) { |
1194 frame->WriteUInt16(headers->size()); | 1194 frame->WriteUInt16(static_cast<uint16>(headers->size())); |
1195 } else { | 1195 } else { |
1196 frame->WriteUInt32(headers->size()); | 1196 frame->WriteUInt32(headers->size()); |
1197 } | 1197 } |
1198 SpdyHeaderBlock::const_iterator it; | 1198 SpdyHeaderBlock::const_iterator it; |
1199 for (it = headers->begin(); it != headers->end(); ++it) { | 1199 for (it = headers->begin(); it != headers->end(); ++it) { |
1200 if (spdy_version < SPDY3) { | 1200 if (spdy_version < SPDY3) { |
1201 frame->WriteString(it->first); | 1201 frame->WriteString(it->first); |
1202 frame->WriteString(it->second); | 1202 frame->WriteString(it->second); |
1203 } else { | 1203 } else { |
1204 frame->WriteStringPiece32(it->first); | 1204 frame->WriteStringPiece32(it->first); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1263 } | 1263 } |
1264 | 1264 |
1265 // WriteLengthZ writes |n| as a |length|-byte, big-endian number to |out|. | 1265 // WriteLengthZ writes |n| as a |length|-byte, big-endian number to |out|. |
1266 static void WriteLengthZ(size_t n, | 1266 static void WriteLengthZ(size_t n, |
1267 unsigned length, | 1267 unsigned length, |
1268 ZDataClass clas, | 1268 ZDataClass clas, |
1269 z_stream* out) { | 1269 z_stream* out) { |
1270 char buf[4]; | 1270 char buf[4]; |
1271 DCHECK_LE(length, sizeof(buf)); | 1271 DCHECK_LE(length, sizeof(buf)); |
1272 for (unsigned i = 1; i <= length; i++) { | 1272 for (unsigned i = 1; i <= length; i++) { |
1273 buf[length - i] = n; | 1273 buf[length - i] = static_cast<char>(n); |
1274 n >>= 8; | 1274 n >>= 8; |
1275 } | 1275 } |
1276 WriteZ(base::StringPiece(buf, length), clas, out); | 1276 WriteZ(base::StringPiece(buf, length), clas, out); |
1277 } | 1277 } |
1278 | 1278 |
1279 // WriteHeaderBlockToZ serialises |headers| to the deflate context |z| in a | 1279 // WriteHeaderBlockToZ serialises |headers| to the deflate context |z| in a |
1280 // manner that resists the length of the compressed data from compromising | 1280 // manner that resists the length of the compressed data from compromising |
1281 // cookie data. | 1281 // cookie data. |
1282 void SpdyFramer::WriteHeaderBlockToZ(const SpdyHeaderBlock* headers, | 1282 void SpdyFramer::WriteHeaderBlockToZ(const SpdyHeaderBlock* headers, |
1283 z_stream* z) const { | 1283 z_stream* z) const { |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1482 if (protocol_version() > SPDY3 && | 1482 if (protocol_version() > SPDY3 && |
1483 current_frame_flags_ & HEADERS_FLAG_PADDED) { | 1483 current_frame_flags_ & HEADERS_FLAG_PADDED) { |
1484 uint8 pad_payload_len = 0; | 1484 uint8 pad_payload_len = 0; |
1485 DCHECK_EQ(remaining_padding_payload_length_, 0u); | 1485 DCHECK_EQ(remaining_padding_payload_length_, 0u); |
1486 successful_read = reader.ReadUInt8(&pad_payload_len); | 1486 successful_read = reader.ReadUInt8(&pad_payload_len); |
1487 DCHECK(successful_read); | 1487 DCHECK(successful_read); |
1488 remaining_padding_payload_length_ = pad_payload_len; | 1488 remaining_padding_payload_length_ = pad_payload_len; |
1489 } | 1489 } |
1490 const bool has_priority = | 1490 const bool has_priority = |
1491 (current_frame_flags_ & HEADERS_FLAG_PRIORITY) != 0; | 1491 (current_frame_flags_ & HEADERS_FLAG_PRIORITY) != 0; |
1492 uint32 priority = 0; | 1492 SpdyPriority priority = 0; |
1493 if (protocol_version() > SPDY3 && has_priority) { | 1493 if (protocol_version() > SPDY3 && has_priority) { |
1494 // TODO(jgraettinger): Process dependency rather than ignoring it. | 1494 // TODO(jgraettinger): Process dependency rather than ignoring it. |
1495 reader.Seek(kPriorityDependencyPayloadSize); | 1495 reader.Seek(kPriorityDependencyPayloadSize); |
1496 uint8 weight = 0; | 1496 uint8 weight = 0; |
1497 successful_read = reader.ReadUInt8(&weight); | 1497 successful_read = reader.ReadUInt8(&weight); |
1498 if (successful_read) { | 1498 if (successful_read) { |
1499 priority = MapWeightToPriority(weight); | 1499 priority = MapWeightToPriority(weight); |
1500 } | 1500 } |
1501 } | 1501 } |
1502 DCHECK(reader.IsDoneReading()); | 1502 DCHECK(reader.IsDoneReading()); |
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2464 return builder.take(); | 2464 return builder.take(); |
2465 } | 2465 } |
2466 | 2466 |
2467 SpdySerializedFrame* SpdyFramer::SerializeRstStream( | 2467 SpdySerializedFrame* SpdyFramer::SerializeRstStream( |
2468 const SpdyRstStreamIR& rst_stream) const { | 2468 const SpdyRstStreamIR& rst_stream) const { |
2469 // TODO(jgraettinger): For now, Chromium will support parsing RST_STREAM | 2469 // TODO(jgraettinger): For now, Chromium will support parsing RST_STREAM |
2470 // payloads, but will not emit them. SPDY4 is used for draft HTTP/2, | 2470 // payloads, but will not emit them. SPDY4 is used for draft HTTP/2, |
2471 // which doesn't currently include RST_STREAM payloads. GFE flags have been | 2471 // which doesn't currently include RST_STREAM payloads. GFE flags have been |
2472 // commented but left in place to simplify future patching. | 2472 // commented but left in place to simplify future patching. |
2473 // Compute the output buffer size, taking opaque data into account. | 2473 // Compute the output buffer size, taking opaque data into account. |
2474 uint16 expected_length = GetRstStreamMinimumSize(); | 2474 size_t expected_length = GetRstStreamMinimumSize(); |
2475 if (protocol_version() > SPDY3) { | 2475 if (protocol_version() > SPDY3) { |
2476 expected_length += rst_stream.description().size(); | 2476 expected_length += rst_stream.description().size(); |
2477 } | 2477 } |
2478 SpdyFrameBuilder builder(expected_length, protocol_version()); | 2478 SpdyFrameBuilder builder(expected_length, protocol_version()); |
2479 | 2479 |
2480 // Serialize the RST_STREAM frame. | 2480 // Serialize the RST_STREAM frame. |
2481 if (protocol_version() <= SPDY3) { | 2481 if (protocol_version() <= SPDY3) { |
2482 builder.WriteControlFrameHeader(*this, RST_STREAM, 0); | 2482 builder.WriteControlFrameHeader(*this, RST_STREAM, 0); |
2483 builder.WriteUInt32(rst_stream.stream_id()); | 2483 builder.WriteUInt32(rst_stream.stream_id()); |
2484 } else { | 2484 } else { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2529 return builder.take(); | 2529 return builder.take(); |
2530 } | 2530 } |
2531 | 2531 |
2532 if (protocol_version() <= SPDY3) { | 2532 if (protocol_version() <= SPDY3) { |
2533 builder.WriteUInt32(values->size()); | 2533 builder.WriteUInt32(values->size()); |
2534 } | 2534 } |
2535 DCHECK_EQ(GetSettingsMinimumSize(), builder.length()); | 2535 DCHECK_EQ(GetSettingsMinimumSize(), builder.length()); |
2536 for (SpdySettingsIR::ValueMap::const_iterator it = values->begin(); | 2536 for (SpdySettingsIR::ValueMap::const_iterator it = values->begin(); |
2537 it != values->end(); | 2537 it != values->end(); |
2538 ++it) { | 2538 ++it) { |
2539 int setting_id = | |
2540 SpdyConstants::SerializeSettingId(protocol_version(), it->first); | |
2541 DCHECK_GE(setting_id, 0); | |
2539 if (protocol_version() <= SPDY3) { | 2542 if (protocol_version() <= SPDY3) { |
2540 uint8 setting_flags = 0; | 2543 uint8 setting_flags = 0; |
2541 if (it->second.persist_value) { | 2544 if (it->second.persist_value) { |
2542 setting_flags |= SETTINGS_FLAG_PLEASE_PERSIST; | 2545 setting_flags |= SETTINGS_FLAG_PLEASE_PERSIST; |
2543 } | 2546 } |
2544 if (it->second.persisted) { | 2547 if (it->second.persisted) { |
2545 setting_flags |= SETTINGS_FLAG_PERSISTED; | 2548 setting_flags |= SETTINGS_FLAG_PERSISTED; |
2546 } | 2549 } |
2547 SettingsFlagsAndId flags_and_id( | 2550 SettingsFlagsAndId flags_and_id(setting_flags, setting_id); |
2548 setting_flags, | |
2549 SpdyConstants::SerializeSettingId(protocol_version(), it->first)); | |
2550 uint32 id_and_flags_wire = flags_and_id.GetWireFormat(protocol_version()); | 2551 uint32 id_and_flags_wire = flags_and_id.GetWireFormat(protocol_version()); |
2551 builder.WriteBytes(&id_and_flags_wire, 4); | 2552 builder.WriteBytes(&id_and_flags_wire, 4); |
2552 } else { | 2553 } else { |
2553 builder.WriteUInt16(SpdyConstants::SerializeSettingId(protocol_version(), | 2554 builder.WriteUInt16(static_cast<uint16>(setting_id)); |
2554 it->first)); | |
2555 } | 2555 } |
2556 builder.WriteUInt32(it->second.value); | 2556 builder.WriteUInt32(it->second.value); |
2557 } | 2557 } |
2558 DCHECK_EQ(size, builder.length()); | 2558 DCHECK_EQ(size, builder.length()); |
2559 return builder.take(); | 2559 return builder.take(); |
2560 } | 2560 } |
2561 | 2561 |
2562 SpdySerializedFrame* SpdyFramer::SerializePing(const SpdyPingIR& ping) const { | 2562 SpdySerializedFrame* SpdyFramer::SerializePing(const SpdyPingIR& ping) const { |
2563 SpdyFrameBuilder builder(GetPingSize(), protocol_version()); | 2563 SpdyFrameBuilder builder(GetPingSize(), protocol_version()); |
2564 if (protocol_version() <= SPDY3) { | 2564 if (protocol_version() <= SPDY3) { |
2565 builder.WriteControlFrameHeader(*this, PING, kNoFlags); | 2565 builder.WriteControlFrameHeader(*this, PING, kNoFlags); |
2566 builder.WriteUInt32(static_cast<uint32>(ping.id())); | 2566 builder.WriteUInt32(static_cast<uint32>(ping.id())); |
2567 } else { | 2567 } else { |
2568 uint8 flags = 0; | 2568 uint8 flags = 0; |
2569 if (ping.is_ack()) { | 2569 if (ping.is_ack()) { |
2570 flags |= PING_FLAG_ACK; | 2570 flags |= PING_FLAG_ACK; |
2571 } | 2571 } |
2572 builder.BeginNewFrame(*this, PING, flags, 0); | 2572 builder.BeginNewFrame(*this, PING, flags, 0); |
2573 builder.WriteUInt64(ping.id()); | 2573 builder.WriteUInt64(ping.id()); |
2574 } | 2574 } |
2575 DCHECK_EQ(GetPingSize(), builder.length()); | 2575 DCHECK_EQ(GetPingSize(), builder.length()); |
2576 return builder.take(); | 2576 return builder.take(); |
2577 } | 2577 } |
2578 | 2578 |
2579 SpdySerializedFrame* SpdyFramer::SerializeGoAway( | 2579 SpdySerializedFrame* SpdyFramer::SerializeGoAway( |
2580 const SpdyGoAwayIR& goaway) const { | 2580 const SpdyGoAwayIR& goaway) const { |
2581 | 2581 |
2582 // Compute the output buffer size, take opaque data into account. | 2582 // Compute the output buffer size, take opaque data into account. |
2583 uint16 expected_length = GetGoAwayMinimumSize(); | 2583 size_t expected_length = GetGoAwayMinimumSize(); |
2584 if (protocol_version() > SPDY3) { | 2584 if (protocol_version() > SPDY3) { |
2585 expected_length += goaway.description().size(); | 2585 expected_length += goaway.description().size(); |
2586 } | 2586 } |
2587 SpdyFrameBuilder builder(expected_length, protocol_version()); | 2587 SpdyFrameBuilder builder(expected_length, protocol_version()); |
2588 | 2588 |
2589 // Serialize the GOAWAY frame. | 2589 // Serialize the GOAWAY frame. |
2590 if (protocol_version() <= SPDY3) { | 2590 if (protocol_version() <= SPDY3) { |
2591 builder.WriteControlFrameHeader(*this, GOAWAY, kNoFlags); | 2591 builder.WriteControlFrameHeader(*this, GOAWAY, kNoFlags); |
2592 } else { | 2592 } else { |
2593 builder.BeginNewFrame(*this, GOAWAY, 0, 0); | 2593 builder.BeginNewFrame(*this, GOAWAY, 0, 0); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2632 | 2632 |
2633 // The size of this frame, including padding (if there is any) | 2633 // The size of this frame, including padding (if there is any) |
2634 // and variable-length name-value block. | 2634 // and variable-length name-value block. |
2635 size_t size = GetHeadersMinimumSize(); | 2635 size_t size = GetHeadersMinimumSize(); |
2636 | 2636 |
2637 if (protocol_version() > SPDY3 && headers.padded()) { | 2637 if (protocol_version() > SPDY3 && headers.padded()) { |
2638 size += kPadLengthFieldSize; | 2638 size += kPadLengthFieldSize; |
2639 size += headers.padding_payload_len(); | 2639 size += headers.padding_payload_len(); |
2640 } | 2640 } |
2641 | 2641 |
2642 uint32 priority = headers.priority(); | 2642 SpdyPriority priority = static_cast<SpdyPriority>(headers.priority()); |
2643 if (headers.has_priority()) { | 2643 if (headers.has_priority()) { |
2644 if (priority > GetLowestPriority()) { | 2644 if (headers.priority() > GetLowestPriority()) { |
2645 DLOG(DFATAL) << "Priority out-of-bounds."; | 2645 DLOG(DFATAL) << "Priority out-of-bounds."; |
2646 priority = GetLowestPriority(); | 2646 priority = GetLowestPriority(); |
2647 } | 2647 } |
2648 size += 5; | 2648 size += 5; |
2649 } | 2649 } |
2650 | 2650 |
2651 string hpack_encoding; | 2651 string hpack_encoding; |
2652 if (protocol_version() > SPDY3) { | 2652 if (protocol_version() > SPDY3) { |
2653 if (enable_compression_) { | 2653 if (enable_compression_) { |
2654 GetHpackEncoder()->EncodeHeaderSet( | 2654 GetHpackEncoder()->EncodeHeaderSet( |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2847 SpdyFrame* SpdyFramer::SerializeAltSvc(const SpdyAltSvcIR& altsvc) { | 2847 SpdyFrame* SpdyFramer::SerializeAltSvc(const SpdyAltSvcIR& altsvc) { |
2848 DCHECK_LT(SPDY3, protocol_version()); | 2848 DCHECK_LT(SPDY3, protocol_version()); |
2849 size_t size = GetAltSvcMinimumSize(); | 2849 size_t size = GetAltSvcMinimumSize(); |
2850 size += altsvc.protocol_id().length(); | 2850 size += altsvc.protocol_id().length(); |
2851 size += altsvc.host().length(); | 2851 size += altsvc.host().length(); |
2852 size += altsvc.origin().length(); | 2852 size += altsvc.origin().length(); |
2853 | 2853 |
2854 SpdyFrameBuilder builder(size, protocol_version()); | 2854 SpdyFrameBuilder builder(size, protocol_version()); |
2855 builder.BeginNewFrame(*this, ALTSVC, kNoFlags, altsvc.stream_id()); | 2855 builder.BeginNewFrame(*this, ALTSVC, kNoFlags, altsvc.stream_id()); |
2856 | 2856 |
2857 // TODO(bnc): http://crbug.com/438263 | |
2858 // Update the binary format here to the new text-based payload format. | |
2857 builder.WriteUInt32(altsvc.max_age()); | 2859 builder.WriteUInt32(altsvc.max_age()); |
2858 builder.WriteUInt16(altsvc.port()); | 2860 builder.WriteUInt16(altsvc.port()); |
2859 builder.WriteUInt8(0); // Reserved. | 2861 builder.WriteUInt8(0); // Reserved. |
2860 builder.WriteUInt8(altsvc.protocol_id().length()); | 2862 builder.WriteUInt8(static_cast<uint8>(altsvc.protocol_id().length())); |
2861 builder.WriteBytes(altsvc.protocol_id().data(), | 2863 builder.WriteBytes(altsvc.protocol_id().data(), |
2862 altsvc.protocol_id().length()); | 2864 altsvc.protocol_id().length()); |
2863 builder.WriteUInt8(altsvc.host().length()); | 2865 builder.WriteUInt8(static_cast<uint8>(altsvc.host().length())); |
2864 builder.WriteBytes(altsvc.host().data(), altsvc.host().length()); | 2866 builder.WriteBytes(altsvc.host().data(), altsvc.host().length()); |
2865 builder.WriteBytes(altsvc.origin().data(), altsvc.origin().length()); | 2867 builder.WriteBytes(altsvc.origin().data(), altsvc.origin().length()); |
2866 DCHECK_LT(GetAltSvcMinimumSize(), builder.length()); | 2868 DCHECK_LT(GetAltSvcMinimumSize(), builder.length()); |
2867 return builder.take(); | 2869 return builder.take(); |
2868 } | 2870 } |
2869 | 2871 |
2870 SpdyFrame* SpdyFramer::SerializePriority(const SpdyPriorityIR& priority) { | 2872 SpdyFrame* SpdyFramer::SerializePriority(const SpdyPriorityIR& priority) { |
2871 DCHECK_LT(SPDY3, protocol_version()); | 2873 DCHECK_LT(SPDY3, protocol_version()); |
2872 size_t size = GetPrioritySize(); | 2874 size_t size = GetPrioritySize(); |
2873 | 2875 |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3200 } | 3202 } |
3201 } | 3203 } |
3202 return read_successfully; | 3204 return read_successfully; |
3203 } | 3205 } |
3204 | 3206 |
3205 void SpdyFramer::SerializeNameValueBlockWithoutCompression( | 3207 void SpdyFramer::SerializeNameValueBlockWithoutCompression( |
3206 SpdyFrameBuilder* builder, | 3208 SpdyFrameBuilder* builder, |
3207 const SpdyNameValueBlock& name_value_block) const { | 3209 const SpdyNameValueBlock& name_value_block) const { |
3208 // Serialize number of headers. | 3210 // Serialize number of headers. |
3209 if (protocol_version() <= SPDY2) { | 3211 if (protocol_version() <= SPDY2) { |
3210 builder->WriteUInt16(name_value_block.size()); | 3212 builder->WriteUInt16(static_cast<uint16>(name_value_block.size())); |
3211 } else { | 3213 } else { |
3212 builder->WriteUInt32(name_value_block.size()); | 3214 builder->WriteUInt32(name_value_block.size()); |
3213 } | 3215 } |
3214 | 3216 |
3215 // Serialize each header. | 3217 // Serialize each header. |
3216 for (SpdyHeaderBlock::const_iterator it = name_value_block.begin(); | 3218 for (SpdyHeaderBlock::const_iterator it = name_value_block.begin(); |
3217 it != name_value_block.end(); | 3219 it != name_value_block.end(); |
3218 ++it) { | 3220 ++it) { |
3219 if (protocol_version() <= SPDY2) { | 3221 if (protocol_version() <= SPDY2) { |
3220 builder->WriteString(it->first); | 3222 builder->WriteString(it->first); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3290 builder->Seek(compressed_size); | 3292 builder->Seek(compressed_size); |
3291 builder->RewriteLength(*this); | 3293 builder->RewriteLength(*this); |
3292 | 3294 |
3293 pre_compress_bytes.Add(uncompressed_len); | 3295 pre_compress_bytes.Add(uncompressed_len); |
3294 post_compress_bytes.Add(compressed_size); | 3296 post_compress_bytes.Add(compressed_size); |
3295 | 3297 |
3296 compressed_frames.Increment(); | 3298 compressed_frames.Increment(); |
3297 } | 3299 } |
3298 | 3300 |
3299 } // namespace net | 3301 } // namespace net |
OLD | NEW |