Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(476)

Side by Side Diff: net/spdy/spdy_framer.cc

Issue 786123002: Update from https://crrev.com/307330 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/spdy/spdy_framer.h ('k') | net/spdy/spdy_framer_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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(&current_frame_stream_id_); 723 successful_read = reader->ReadUInt31(&current_frame_stream_id_);
722 } 724 }
723 DCHECK(successful_read); 725 DCHECK(successful_read);
724 726
725 successful_read = reader->ReadUInt8(&current_frame_flags_); 727 successful_read = reader->ReadUInt8(&current_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 SpdyConstants::SerializeFrameType(protocol_version(), DATA);
747 SpdyConstants::SerializeFrameType(protocol_version(), DATA) :
748 control_frame_type_field != 0;
749 748
750 if (is_control_frame) { 749 if (is_control_frame) {
751 current_frame_length_ = length_field + GetControlFrameHeaderSize(); 750 current_frame_length_ = length_field + GetControlFrameHeaderSize();
752 } else { 751 } else {
753 current_frame_length_ = length_field + GetDataFrameMinimumSize(); 752 current_frame_length_ = length_field + GetDataFrameMinimumSize();
754 } 753 }
755 754
756 successful_read = reader->ReadUInt8(&current_frame_flags_); 755 successful_read = reader->ReadUInt8(&current_frame_flags_);
757 DCHECK(successful_read); 756 DCHECK(successful_read);
758 757
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 CHANGE_STATE(SPDY_AUTO_RESET); 830 CHANGE_STATE(SPDY_AUTO_RESET);
832 } 831 }
833 } 832 }
834 } else { 833 } else {
835 ProcessControlFrameHeader(control_frame_type_field); 834 ProcessControlFrameHeader(control_frame_type_field);
836 } 835 }
837 836
838 return original_len - len; 837 return original_len - len;
839 } 838 }
840 839
841 void SpdyFramer::ProcessControlFrameHeader(uint16 control_frame_type_field) { 840 void SpdyFramer::ProcessControlFrameHeader(int control_frame_type_field) {
842 DCHECK_EQ(SPDY_NO_ERROR, error_code_); 841 DCHECK_EQ(SPDY_NO_ERROR, error_code_);
843 DCHECK_LE(GetControlFrameHeaderSize(), current_frame_buffer_length_); 842 DCHECK_LE(GetControlFrameHeaderSize(), current_frame_buffer_length_);
844 843
845 // TODO(mlavan): Either remove credential frames from the code entirely, 844 // TODO(mlavan): Either remove credential frames from the code entirely,
846 // or add them to parsing + serialization methods for SPDY3. 845 // or add them to parsing + serialization methods for SPDY3.
847 // Early detection of deprecated frames that we ignore. 846 // Early detection of deprecated frames that we ignore.
848 if (protocol_version() <= SPDY3) { 847 if (protocol_version() <= SPDY3) {
849 if (control_frame_type_field == CREDENTIAL) { 848 if (control_frame_type_field == CREDENTIAL) {
850 current_frame_type_ = CREDENTIAL; 849 current_frame_type_ = CREDENTIAL;
851 DCHECK_EQ(SPDY3, protocol_version()); 850 DCHECK_EQ(SPDY3, protocol_version());
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 total_length += length_of_name_size + it->first.size() + 1183 total_length += length_of_name_size + it->first.size() +
1185 length_of_value_size + it->second.size(); 1184 length_of_value_size + it->second.size();
1186 } 1185 }
1187 return total_length; 1186 return total_length;
1188 } 1187 }
1189 1188
1190 void SpdyFramer::WriteHeaderBlock(SpdyFrameBuilder* frame, 1189 void SpdyFramer::WriteHeaderBlock(SpdyFrameBuilder* frame,
1191 const SpdyMajorVersion spdy_version, 1190 const SpdyMajorVersion spdy_version,
1192 const SpdyHeaderBlock* headers) { 1191 const SpdyHeaderBlock* headers) {
1193 if (spdy_version < SPDY3) { 1192 if (spdy_version < SPDY3) {
1194 frame->WriteUInt16(headers->size()); 1193 frame->WriteUInt16(static_cast<uint16>(headers->size()));
1195 } else { 1194 } else {
1196 frame->WriteUInt32(headers->size()); 1195 frame->WriteUInt32(headers->size());
1197 } 1196 }
1198 SpdyHeaderBlock::const_iterator it; 1197 SpdyHeaderBlock::const_iterator it;
1199 for (it = headers->begin(); it != headers->end(); ++it) { 1198 for (it = headers->begin(); it != headers->end(); ++it) {
1200 if (spdy_version < SPDY3) { 1199 if (spdy_version < SPDY3) {
1201 frame->WriteString(it->first); 1200 frame->WriteString(it->first);
1202 frame->WriteString(it->second); 1201 frame->WriteString(it->second);
1203 } else { 1202 } else {
1204 frame->WriteStringPiece32(it->first); 1203 frame->WriteStringPiece32(it->first);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 } 1262 }
1264 1263
1265 // WriteLengthZ writes |n| as a |length|-byte, big-endian number to |out|. 1264 // WriteLengthZ writes |n| as a |length|-byte, big-endian number to |out|.
1266 static void WriteLengthZ(size_t n, 1265 static void WriteLengthZ(size_t n,
1267 unsigned length, 1266 unsigned length,
1268 ZDataClass clas, 1267 ZDataClass clas,
1269 z_stream* out) { 1268 z_stream* out) {
1270 char buf[4]; 1269 char buf[4];
1271 DCHECK_LE(length, sizeof(buf)); 1270 DCHECK_LE(length, sizeof(buf));
1272 for (unsigned i = 1; i <= length; i++) { 1271 for (unsigned i = 1; i <= length; i++) {
1273 buf[length - i] = n; 1272 buf[length - i] = static_cast<char>(n);
1274 n >>= 8; 1273 n >>= 8;
1275 } 1274 }
1276 WriteZ(base::StringPiece(buf, length), clas, out); 1275 WriteZ(base::StringPiece(buf, length), clas, out);
1277 } 1276 }
1278 1277
1279 // WriteHeaderBlockToZ serialises |headers| to the deflate context |z| in a 1278 // WriteHeaderBlockToZ serialises |headers| to the deflate context |z| in a
1280 // manner that resists the length of the compressed data from compromising 1279 // manner that resists the length of the compressed data from compromising
1281 // cookie data. 1280 // cookie data.
1282 void SpdyFramer::WriteHeaderBlockToZ(const SpdyHeaderBlock* headers, 1281 void SpdyFramer::WriteHeaderBlockToZ(const SpdyHeaderBlock* headers,
1283 z_stream* z) const { 1282 z_stream* z) const {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1482 if (protocol_version() > SPDY3 && 1481 if (protocol_version() > SPDY3 &&
1483 current_frame_flags_ & HEADERS_FLAG_PADDED) { 1482 current_frame_flags_ & HEADERS_FLAG_PADDED) {
1484 uint8 pad_payload_len = 0; 1483 uint8 pad_payload_len = 0;
1485 DCHECK_EQ(remaining_padding_payload_length_, 0u); 1484 DCHECK_EQ(remaining_padding_payload_length_, 0u);
1486 successful_read = reader.ReadUInt8(&pad_payload_len); 1485 successful_read = reader.ReadUInt8(&pad_payload_len);
1487 DCHECK(successful_read); 1486 DCHECK(successful_read);
1488 remaining_padding_payload_length_ = pad_payload_len; 1487 remaining_padding_payload_length_ = pad_payload_len;
1489 } 1488 }
1490 const bool has_priority = 1489 const bool has_priority =
1491 (current_frame_flags_ & HEADERS_FLAG_PRIORITY) != 0; 1490 (current_frame_flags_ & HEADERS_FLAG_PRIORITY) != 0;
1492 uint32 priority = 0; 1491 SpdyPriority priority = 0;
1493 if (protocol_version() > SPDY3 && has_priority) { 1492 if (protocol_version() > SPDY3 && has_priority) {
1494 // TODO(jgraettinger): Process dependency rather than ignoring it. 1493 // TODO(jgraettinger): Process dependency rather than ignoring it.
1495 reader.Seek(kPriorityDependencyPayloadSize); 1494 reader.Seek(kPriorityDependencyPayloadSize);
1496 uint8 weight = 0; 1495 uint8 weight = 0;
1497 successful_read = reader.ReadUInt8(&weight); 1496 successful_read = reader.ReadUInt8(&weight);
1498 if (successful_read) { 1497 if (successful_read) {
1499 priority = MapWeightToPriority(weight); 1498 priority = MapWeightToPriority(weight);
1500 } 1499 }
1501 } 1500 }
1502 DCHECK(reader.IsDoneReading()); 1501 DCHECK(reader.IsDoneReading());
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after
2464 return builder.take(); 2463 return builder.take();
2465 } 2464 }
2466 2465
2467 SpdySerializedFrame* SpdyFramer::SerializeRstStream( 2466 SpdySerializedFrame* SpdyFramer::SerializeRstStream(
2468 const SpdyRstStreamIR& rst_stream) const { 2467 const SpdyRstStreamIR& rst_stream) const {
2469 // TODO(jgraettinger): For now, Chromium will support parsing RST_STREAM 2468 // TODO(jgraettinger): For now, Chromium will support parsing RST_STREAM
2470 // payloads, but will not emit them. SPDY4 is used for draft HTTP/2, 2469 // 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 2470 // which doesn't currently include RST_STREAM payloads. GFE flags have been
2472 // commented but left in place to simplify future patching. 2471 // commented but left in place to simplify future patching.
2473 // Compute the output buffer size, taking opaque data into account. 2472 // Compute the output buffer size, taking opaque data into account.
2474 uint16 expected_length = GetRstStreamMinimumSize(); 2473 size_t expected_length = GetRstStreamMinimumSize();
2475 if (protocol_version() > SPDY3) { 2474 if (protocol_version() > SPDY3) {
2476 expected_length += rst_stream.description().size(); 2475 expected_length += rst_stream.description().size();
2477 } 2476 }
2478 SpdyFrameBuilder builder(expected_length, protocol_version()); 2477 SpdyFrameBuilder builder(expected_length, protocol_version());
2479 2478
2480 // Serialize the RST_STREAM frame. 2479 // Serialize the RST_STREAM frame.
2481 if (protocol_version() <= SPDY3) { 2480 if (protocol_version() <= SPDY3) {
2482 builder.WriteControlFrameHeader(*this, RST_STREAM, 0); 2481 builder.WriteControlFrameHeader(*this, RST_STREAM, 0);
2483 builder.WriteUInt32(rst_stream.stream_id()); 2482 builder.WriteUInt32(rst_stream.stream_id());
2484 } else { 2483 } else {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2529 return builder.take(); 2528 return builder.take();
2530 } 2529 }
2531 2530
2532 if (protocol_version() <= SPDY3) { 2531 if (protocol_version() <= SPDY3) {
2533 builder.WriteUInt32(values->size()); 2532 builder.WriteUInt32(values->size());
2534 } 2533 }
2535 DCHECK_EQ(GetSettingsMinimumSize(), builder.length()); 2534 DCHECK_EQ(GetSettingsMinimumSize(), builder.length());
2536 for (SpdySettingsIR::ValueMap::const_iterator it = values->begin(); 2535 for (SpdySettingsIR::ValueMap::const_iterator it = values->begin();
2537 it != values->end(); 2536 it != values->end();
2538 ++it) { 2537 ++it) {
2538 int setting_id =
2539 SpdyConstants::SerializeSettingId(protocol_version(), it->first);
2540 DCHECK_GE(setting_id, 0);
2539 if (protocol_version() <= SPDY3) { 2541 if (protocol_version() <= SPDY3) {
2540 uint8 setting_flags = 0; 2542 uint8 setting_flags = 0;
2541 if (it->second.persist_value) { 2543 if (it->second.persist_value) {
2542 setting_flags |= SETTINGS_FLAG_PLEASE_PERSIST; 2544 setting_flags |= SETTINGS_FLAG_PLEASE_PERSIST;
2543 } 2545 }
2544 if (it->second.persisted) { 2546 if (it->second.persisted) {
2545 setting_flags |= SETTINGS_FLAG_PERSISTED; 2547 setting_flags |= SETTINGS_FLAG_PERSISTED;
2546 } 2548 }
2547 SettingsFlagsAndId flags_and_id( 2549 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()); 2550 uint32 id_and_flags_wire = flags_and_id.GetWireFormat(protocol_version());
2551 builder.WriteBytes(&id_and_flags_wire, 4); 2551 builder.WriteBytes(&id_and_flags_wire, 4);
2552 } else { 2552 } else {
2553 builder.WriteUInt16(SpdyConstants::SerializeSettingId(protocol_version(), 2553 builder.WriteUInt16(static_cast<uint16>(setting_id));
2554 it->first));
2555 } 2554 }
2556 builder.WriteUInt32(it->second.value); 2555 builder.WriteUInt32(it->second.value);
2557 } 2556 }
2558 DCHECK_EQ(size, builder.length()); 2557 DCHECK_EQ(size, builder.length());
2559 return builder.take(); 2558 return builder.take();
2560 } 2559 }
2561 2560
2562 SpdySerializedFrame* SpdyFramer::SerializePing(const SpdyPingIR& ping) const { 2561 SpdySerializedFrame* SpdyFramer::SerializePing(const SpdyPingIR& ping) const {
2563 SpdyFrameBuilder builder(GetPingSize(), protocol_version()); 2562 SpdyFrameBuilder builder(GetPingSize(), protocol_version());
2564 if (protocol_version() <= SPDY3) { 2563 if (protocol_version() <= SPDY3) {
2565 builder.WriteControlFrameHeader(*this, PING, kNoFlags); 2564 builder.WriteControlFrameHeader(*this, PING, kNoFlags);
2566 builder.WriteUInt32(static_cast<uint32>(ping.id())); 2565 builder.WriteUInt32(static_cast<uint32>(ping.id()));
2567 } else { 2566 } else {
2568 uint8 flags = 0; 2567 uint8 flags = 0;
2569 if (ping.is_ack()) { 2568 if (ping.is_ack()) {
2570 flags |= PING_FLAG_ACK; 2569 flags |= PING_FLAG_ACK;
2571 } 2570 }
2572 builder.BeginNewFrame(*this, PING, flags, 0); 2571 builder.BeginNewFrame(*this, PING, flags, 0);
2573 builder.WriteUInt64(ping.id()); 2572 builder.WriteUInt64(ping.id());
2574 } 2573 }
2575 DCHECK_EQ(GetPingSize(), builder.length()); 2574 DCHECK_EQ(GetPingSize(), builder.length());
2576 return builder.take(); 2575 return builder.take();
2577 } 2576 }
2578 2577
2579 SpdySerializedFrame* SpdyFramer::SerializeGoAway( 2578 SpdySerializedFrame* SpdyFramer::SerializeGoAway(
2580 const SpdyGoAwayIR& goaway) const { 2579 const SpdyGoAwayIR& goaway) const {
2581 2580
2582 // Compute the output buffer size, take opaque data into account. 2581 // Compute the output buffer size, take opaque data into account.
2583 uint16 expected_length = GetGoAwayMinimumSize(); 2582 size_t expected_length = GetGoAwayMinimumSize();
2584 if (protocol_version() > SPDY3) { 2583 if (protocol_version() > SPDY3) {
2585 expected_length += goaway.description().size(); 2584 expected_length += goaway.description().size();
2586 } 2585 }
2587 SpdyFrameBuilder builder(expected_length, protocol_version()); 2586 SpdyFrameBuilder builder(expected_length, protocol_version());
2588 2587
2589 // Serialize the GOAWAY frame. 2588 // Serialize the GOAWAY frame.
2590 if (protocol_version() <= SPDY3) { 2589 if (protocol_version() <= SPDY3) {
2591 builder.WriteControlFrameHeader(*this, GOAWAY, kNoFlags); 2590 builder.WriteControlFrameHeader(*this, GOAWAY, kNoFlags);
2592 } else { 2591 } else {
2593 builder.BeginNewFrame(*this, GOAWAY, 0, 0); 2592 builder.BeginNewFrame(*this, GOAWAY, 0, 0);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2632 2631
2633 // The size of this frame, including padding (if there is any) 2632 // The size of this frame, including padding (if there is any)
2634 // and variable-length name-value block. 2633 // and variable-length name-value block.
2635 size_t size = GetHeadersMinimumSize(); 2634 size_t size = GetHeadersMinimumSize();
2636 2635
2637 if (protocol_version() > SPDY3 && headers.padded()) { 2636 if (protocol_version() > SPDY3 && headers.padded()) {
2638 size += kPadLengthFieldSize; 2637 size += kPadLengthFieldSize;
2639 size += headers.padding_payload_len(); 2638 size += headers.padding_payload_len();
2640 } 2639 }
2641 2640
2642 uint32 priority = headers.priority(); 2641 SpdyPriority priority = static_cast<SpdyPriority>(headers.priority());
2643 if (headers.has_priority()) { 2642 if (headers.has_priority()) {
2644 if (priority > GetLowestPriority()) { 2643 if (headers.priority() > GetLowestPriority()) {
2645 DLOG(DFATAL) << "Priority out-of-bounds."; 2644 DLOG(DFATAL) << "Priority out-of-bounds.";
2646 priority = GetLowestPriority(); 2645 priority = GetLowestPriority();
2647 } 2646 }
2648 size += 5; 2647 size += 5;
2649 } 2648 }
2650 2649
2651 string hpack_encoding; 2650 string hpack_encoding;
2652 if (protocol_version() > SPDY3) { 2651 if (protocol_version() > SPDY3) {
2653 if (enable_compression_) { 2652 if (enable_compression_) {
2654 GetHpackEncoder()->EncodeHeaderSet( 2653 GetHpackEncoder()->EncodeHeaderSet(
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
2847 SpdyFrame* SpdyFramer::SerializeAltSvc(const SpdyAltSvcIR& altsvc) { 2846 SpdyFrame* SpdyFramer::SerializeAltSvc(const SpdyAltSvcIR& altsvc) {
2848 DCHECK_LT(SPDY3, protocol_version()); 2847 DCHECK_LT(SPDY3, protocol_version());
2849 size_t size = GetAltSvcMinimumSize(); 2848 size_t size = GetAltSvcMinimumSize();
2850 size += altsvc.protocol_id().length(); 2849 size += altsvc.protocol_id().length();
2851 size += altsvc.host().length(); 2850 size += altsvc.host().length();
2852 size += altsvc.origin().length(); 2851 size += altsvc.origin().length();
2853 2852
2854 SpdyFrameBuilder builder(size, protocol_version()); 2853 SpdyFrameBuilder builder(size, protocol_version());
2855 builder.BeginNewFrame(*this, ALTSVC, kNoFlags, altsvc.stream_id()); 2854 builder.BeginNewFrame(*this, ALTSVC, kNoFlags, altsvc.stream_id());
2856 2855
2856 // TODO(bnc): http://crbug.com/438263
2857 // Update the binary format here to the new text-based payload format.
2857 builder.WriteUInt32(altsvc.max_age()); 2858 builder.WriteUInt32(altsvc.max_age());
2858 builder.WriteUInt16(altsvc.port()); 2859 builder.WriteUInt16(altsvc.port());
2859 builder.WriteUInt8(0); // Reserved. 2860 builder.WriteUInt8(0); // Reserved.
2860 builder.WriteUInt8(altsvc.protocol_id().length()); 2861 builder.WriteUInt8(static_cast<uint8>(altsvc.protocol_id().length()));
2861 builder.WriteBytes(altsvc.protocol_id().data(), 2862 builder.WriteBytes(altsvc.protocol_id().data(),
2862 altsvc.protocol_id().length()); 2863 altsvc.protocol_id().length());
2863 builder.WriteUInt8(altsvc.host().length()); 2864 builder.WriteUInt8(static_cast<uint8>(altsvc.host().length()));
2864 builder.WriteBytes(altsvc.host().data(), altsvc.host().length()); 2865 builder.WriteBytes(altsvc.host().data(), altsvc.host().length());
2865 builder.WriteBytes(altsvc.origin().data(), altsvc.origin().length()); 2866 builder.WriteBytes(altsvc.origin().data(), altsvc.origin().length());
2866 DCHECK_LT(GetAltSvcMinimumSize(), builder.length()); 2867 DCHECK_LT(GetAltSvcMinimumSize(), builder.length());
2867 return builder.take(); 2868 return builder.take();
2868 } 2869 }
2869 2870
2870 SpdyFrame* SpdyFramer::SerializePriority(const SpdyPriorityIR& priority) { 2871 SpdyFrame* SpdyFramer::SerializePriority(const SpdyPriorityIR& priority) {
2871 DCHECK_LT(SPDY3, protocol_version()); 2872 DCHECK_LT(SPDY3, protocol_version());
2872 size_t size = GetPrioritySize(); 2873 size_t size = GetPrioritySize();
2873 2874
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
3200 } 3201 }
3201 } 3202 }
3202 return read_successfully; 3203 return read_successfully;
3203 } 3204 }
3204 3205
3205 void SpdyFramer::SerializeNameValueBlockWithoutCompression( 3206 void SpdyFramer::SerializeNameValueBlockWithoutCompression(
3206 SpdyFrameBuilder* builder, 3207 SpdyFrameBuilder* builder,
3207 const SpdyNameValueBlock& name_value_block) const { 3208 const SpdyNameValueBlock& name_value_block) const {
3208 // Serialize number of headers. 3209 // Serialize number of headers.
3209 if (protocol_version() <= SPDY2) { 3210 if (protocol_version() <= SPDY2) {
3210 builder->WriteUInt16(name_value_block.size()); 3211 builder->WriteUInt16(static_cast<uint16>(name_value_block.size()));
3211 } else { 3212 } else {
3212 builder->WriteUInt32(name_value_block.size()); 3213 builder->WriteUInt32(name_value_block.size());
3213 } 3214 }
3214 3215
3215 // Serialize each header. 3216 // Serialize each header.
3216 for (SpdyHeaderBlock::const_iterator it = name_value_block.begin(); 3217 for (SpdyHeaderBlock::const_iterator it = name_value_block.begin();
3217 it != name_value_block.end(); 3218 it != name_value_block.end();
3218 ++it) { 3219 ++it) {
3219 if (protocol_version() <= SPDY2) { 3220 if (protocol_version() <= SPDY2) {
3220 builder->WriteString(it->first); 3221 builder->WriteString(it->first);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
3290 builder->Seek(compressed_size); 3291 builder->Seek(compressed_size);
3291 builder->RewriteLength(*this); 3292 builder->RewriteLength(*this);
3292 3293
3293 pre_compress_bytes.Add(uncompressed_len); 3294 pre_compress_bytes.Add(uncompressed_len);
3294 post_compress_bytes.Add(compressed_size); 3295 post_compress_bytes.Add(compressed_size);
3295 3296
3296 compressed_frames.Increment(); 3297 compressed_frames.Increment();
3297 } 3298 }
3298 3299
3299 } // namespace net 3300 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_framer.h ('k') | net/spdy/spdy_framer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698