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

Unified Diff: net/spdy/spdy_framer.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months 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 side-by-side diff with in-line comments
Download patch
Index: net/spdy/spdy_framer.cc
diff --git a/net/spdy/spdy_framer.cc b/net/spdy/spdy_framer.cc
index a20d1ead1f83b1c433bddd0ce9ffe2b2a29db05b..dfb76441f8cb572dfad62d88c782c2b62b9e5914 100644
--- a/net/spdy/spdy_framer.cc
+++ b/net/spdy/spdy_framer.cc
@@ -32,9 +32,10 @@ uLong CalculateDictionaryId(const char* dictionary,
struct DictionaryIds {
DictionaryIds()
- : v2_dictionary_id(CalculateDictionaryId(kV2Dictionary, kV2DictionarySize)),
- v3_dictionary_id(CalculateDictionaryId(kV3Dictionary, kV3DictionarySize))
- {}
+ : v2_dictionary_id(
+ CalculateDictionaryId(kV2Dictionary, kV2DictionarySize)),
+ v3_dictionary_id(
+ CalculateDictionaryId(kV3Dictionary, kV3DictionarySize)) {}
const uLong v2_dictionary_id;
const uLong v3_dictionary_id;
};
@@ -56,28 +57,27 @@ const size_t SpdyFramer::kHeaderDataChunkMaxSize = 1024;
const size_t SpdyFramer::kControlFrameBufferSize = 18;
#ifdef DEBUG_SPDY_STATE_CHANGES
-#define CHANGE_STATE(newstate) \
- do { \
- DVLOG(1) << "Changing state from: " \
- << StateToString(state_) \
- << " to " << StateToString(newstate) << "\n"; \
- DCHECK(state_ != SPDY_ERROR); \
- DCHECK_EQ(previous_state_, state_); \
- previous_state_ = state_; \
- state_ = newstate; \
+#define CHANGE_STATE(newstate) \
+ do { \
+ DVLOG(1) << "Changing state from: " << StateToString(state_) << " to " \
+ << StateToString(newstate) << "\n"; \
+ DCHECK(state_ != SPDY_ERROR); \
+ DCHECK_EQ(previous_state_, state_); \
+ previous_state_ = state_; \
+ state_ = newstate; \
} while (false)
#else
-#define CHANGE_STATE(newstate) \
- do { \
- DCHECK(state_ != SPDY_ERROR); \
- DCHECK_EQ(previous_state_, state_); \
- previous_state_ = state_; \
- state_ = newstate; \
+#define CHANGE_STATE(newstate) \
+ do { \
+ DCHECK(state_ != SPDY_ERROR); \
+ DCHECK_EQ(previous_state_, state_); \
+ previous_state_ = state_; \
+ state_ = newstate; \
} while (false)
#endif
-SettingsFlagsAndId SettingsFlagsAndId::FromWireFormat(
- SpdyMajorVersion version, uint32 wire) {
+SettingsFlagsAndId SettingsFlagsAndId::FromWireFormat(SpdyMajorVersion version,
+ uint32 wire) {
if (version < SPDY3) {
ConvertFlagsAndIdForSpdy2(&wire);
}
@@ -89,8 +89,7 @@ SettingsFlagsAndId::SettingsFlagsAndId(uint8 flags, uint32 id)
LOG_IF(DFATAL, id > (1u << 24)) << "SPDY setting ID too large: " << id;
}
-uint32 SettingsFlagsAndId::GetWireFormat(SpdyMajorVersion version)
- const {
+uint32 SettingsFlagsAndId::GetWireFormat(SpdyMajorVersion version) const {
uint32 wire = htonl(id_ & 0x00ffffff) | htonl(flags_ << 24);
if (version < SPDY3) {
ConvertFlagsAndIdForSpdy2(&wire);
@@ -104,9 +103,9 @@ uint32 SettingsFlagsAndId::GetWireFormat(SpdyMajorVersion version)
// This method is also bidirectional (can be used to translate SPDY 2 to SPDY 3
// as well as vice versa).
void SettingsFlagsAndId::ConvertFlagsAndIdForSpdy2(uint32* val) {
- uint8* wire_array = reinterpret_cast<uint8*>(val);
- std::swap(wire_array[0], wire_array[3]);
- std::swap(wire_array[1], wire_array[2]);
+ uint8* wire_array = reinterpret_cast<uint8*>(val);
+ std::swap(wire_array[0], wire_array[3]);
+ std::swap(wire_array[1], wire_array[2]);
}
bool SpdyFramerVisitorInterface::OnGoAwayFrameData(const char* goaway_data,
@@ -258,7 +257,7 @@ size_t SpdyFramer::GetGoAwayMinimumSize() const {
return size;
}
-size_t SpdyFramer::GetHeadersMinimumSize() const {
+size_t SpdyFramer::GetHeadersMinimumSize() const {
// Size, in bytes, of a HEADERS frame not including the variable-length
// name-value block.
size_t size = GetControlFrameHeaderSize();
@@ -303,7 +302,7 @@ size_t SpdyFramer::GetPushPromiseMinimumSize() const {
return GetControlFrameHeaderSize() + 4;
}
-size_t SpdyFramer::GetContinuationMinimumSize() const {
+size_t SpdyFramer::GetContinuationMinimumSize() const {
// Size, in bytes, of a CONTINUATION frame not including the variable-length
// headers fragments.
return GetControlFrameHeaderSize();
@@ -585,10 +584,9 @@ size_t SpdyFramer::ProcessInput(const char* data, size_t len) {
goto bottom;
}
} while (state_ != previous_state_);
- bottom:
+bottom:
DCHECK(len == 0 || state_ == SPDY_ERROR);
- if (current_frame_buffer_length_ == 0 &&
- remaining_data_length_ == 0 &&
+ if (current_frame_buffer_length_ == 0 && remaining_data_length_ == 0 &&
remaining_control_header_ == 0) {
DCHECK(state_ == SPDY_RESET || state_ == SPDY_ERROR)
<< "State: " << StateToString(state_);
@@ -618,9 +616,8 @@ size_t SpdyFramer::ProcessCommonHeader(const char* data, size_t len) {
// Using a scoped_ptr here since we may need to create a new SpdyFrameReader
// when processing DATA frames below.
- scoped_ptr<SpdyFrameReader> reader(
- new SpdyFrameReader(current_frame_buffer_.get(),
- current_frame_buffer_length_));
+ scoped_ptr<SpdyFrameReader> reader(new SpdyFrameReader(
+ current_frame_buffer_.get(), current_frame_buffer_length_));
uint16 version = 0;
bool is_control_frame = false;
@@ -641,9 +638,8 @@ size_t SpdyFramer::ProcessCommonHeader(const char* data, size_t len) {
version > SpdyConstants::SerializeMajorVersion(SPDY_MAX_VERSION) ||
SpdyConstants::ParseMajorVersion(version) != protocol_version()) {
// Version does not match the version the framer was initialized with.
- DVLOG(1) << "Unsupported SPDY version "
- << version
- << " (expected " << protocol_version() << ")";
+ DVLOG(1) << "Unsupported SPDY version " << version << " (expected "
+ << protocol_version() << ")";
set_error(SPDY_UNSUPPORTED_VERSION);
return 0;
} else {
@@ -697,8 +693,9 @@ size_t SpdyFramer::ProcessCommonHeader(const char* data, size_t len) {
// Before we accept a DATA frame, we need to make sure we're not in the
// middle of processing a header block.
- const bool is_continuation_frame = (control_frame_type_field ==
- SpdyConstants::SerializeFrameType(protocol_version(), CONTINUATION));
+ const bool is_continuation_frame =
+ (control_frame_type_field ==
+ SpdyConstants::SerializeFrameType(protocol_version(), CONTINUATION));
if ((expect_continuation_ != 0) != is_continuation_frame) {
if (expect_continuation_ != 0) {
DLOG(ERROR) << "The framer was expecting to receive a CONTINUATION "
@@ -743,7 +740,7 @@ size_t SpdyFramer::ProcessCommonHeader(const char* data, size_t len) {
uint8 valid_data_flags = 0;
if (protocol_version() > SPDY3) {
valid_data_flags = DATA_FLAG_FIN | DATA_FLAG_END_SEGMENT |
- DATA_FLAG_PAD_LOW | DATA_FLAG_PAD_HIGH;
+ DATA_FLAG_PAD_LOW | DATA_FLAG_PAD_HIGH;
} else {
valid_data_flags = DATA_FLAG_FIN;
}
@@ -759,8 +756,7 @@ size_t SpdyFramer::ProcessCommonHeader(const char* data, size_t len) {
} else {
// Empty data frame.
if (current_frame_flags_ & DATA_FLAG_FIN) {
- visitor_->OnStreamFrameData(
- current_frame_stream_id_, NULL, 0, true);
+ visitor_->OnStreamFrameData(current_frame_stream_id_, NULL, 0, true);
}
CHANGE_STATE(SPDY_AUTO_RESET);
}
@@ -835,22 +831,22 @@ void SpdyFramer::ProcessControlFrameHeader(uint16 control_frame_type_field) {
set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS);
}
break;
- case SETTINGS:
- {
+ case SETTINGS: {
// Make sure that we have an integral number of 8-byte key/value pairs,
// plus a 4-byte length field in SPDY3 and below.
size_t values_prefix_size = (protocol_version() <= SPDY3 ? 4 : 0);
// Size of each key/value pair in bytes.
size_t setting_size = (protocol_version() <= SPDY3 ? 8 : 5);
if (current_frame_length_ < GetSettingsMinimumSize() ||
- (current_frame_length_ - GetControlFrameHeaderSize())
- % setting_size != values_prefix_size) {
+ (current_frame_length_ - GetControlFrameHeaderSize()) %
+ setting_size !=
+ values_prefix_size) {
DLOG(WARNING) << "Invalid length for SETTINGS frame: "
<< current_frame_length_;
set_error(SPDY_INVALID_CONTROL_FRAME);
} else if (protocol_version() <= SPDY3 &&
current_frame_flags_ &
- ~SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS) {
+ ~SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS) {
set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS);
} else if (protocol_version() > SPDY3 &&
current_frame_flags_ & ~SETTINGS_FLAG_ACK) {
@@ -870,41 +866,39 @@ void SpdyFramer::ProcessControlFrameHeader(uint16 control_frame_type_field) {
set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS);
}
break;
- case GOAWAY:
- {
- // For SPDY version < 4, there are only mandatory fields and the header
- // has a fixed length. For SPDY version >= 4, optional opaque data may
- // be appended to the GOAWAY frame, thus there is only a minimal length
- // restriction.
- if ((current_frame_length_ != GetGoAwayMinimumSize() &&
- protocol_version() <= SPDY3) ||
- (current_frame_length_ < GetGoAwayMinimumSize() &&
- protocol_version() > SPDY3)) {
- set_error(SPDY_INVALID_CONTROL_FRAME);
- } else if (current_frame_flags_ != 0) {
- set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS);
- }
- break;
- }
- case HEADERS:
- {
- size_t min_size = GetHeadersMinimumSize();
- if (protocol_version() > SPDY3 &&
- (current_frame_flags_ & HEADERS_FLAG_PRIORITY)) {
- min_size += 4;
- }
- if (current_frame_length_ < min_size) {
- set_error(SPDY_INVALID_CONTROL_FRAME);
- } else if (protocol_version() <= SPDY3 &&
- current_frame_flags_ & ~CONTROL_FLAG_FIN) {
- set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS);
- } else if (protocol_version() > SPDY3 && current_frame_flags_ &
- ~(CONTROL_FLAG_FIN | HEADERS_FLAG_PRIORITY |
- HEADERS_FLAG_END_HEADERS)) {
- set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS);
- }
+ case GOAWAY: {
+ // For SPDY version < 4, there are only mandatory fields and the header
+ // has a fixed length. For SPDY version >= 4, optional opaque data may
+ // be appended to the GOAWAY frame, thus there is only a minimal length
+ // restriction.
+ if ((current_frame_length_ != GetGoAwayMinimumSize() &&
+ protocol_version() <= SPDY3) ||
+ (current_frame_length_ < GetGoAwayMinimumSize() &&
+ protocol_version() > SPDY3)) {
+ set_error(SPDY_INVALID_CONTROL_FRAME);
+ } else if (current_frame_flags_ != 0) {
+ set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS);
}
break;
+ }
+ case HEADERS: {
+ size_t min_size = GetHeadersMinimumSize();
+ if (protocol_version() > SPDY3 &&
+ (current_frame_flags_ & HEADERS_FLAG_PRIORITY)) {
+ min_size += 4;
+ }
+ if (current_frame_length_ < min_size) {
+ set_error(SPDY_INVALID_CONTROL_FRAME);
+ } else if (protocol_version() <= SPDY3 &&
+ current_frame_flags_ & ~CONTROL_FLAG_FIN) {
+ set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS);
+ } else if (protocol_version() > SPDY3 &&
+ current_frame_flags_ &
+ ~(CONTROL_FLAG_FIN | HEADERS_FLAG_PRIORITY |
+ HEADERS_FLAG_END_HEADERS)) {
+ set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS);
+ }
+ } break;
case WINDOW_UPDATE:
if (current_frame_length_ != GetWindowUpdateSize()) {
set_error(SPDY_INVALID_CONTROL_FRAME);
@@ -924,8 +918,8 @@ void SpdyFramer::ProcessControlFrameHeader(uint16 control_frame_type_field) {
set_error(SPDY_INVALID_CONTROL_FRAME);
} else if (protocol_version() <= SPDY3 && current_frame_flags_ != 0) {
set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS);
- } else if (protocol_version() > SPDY3 && current_frame_flags_ &
- ~PUSH_PROMISE_FLAG_END_PUSH_PROMISE) {
+ } else if (protocol_version() > SPDY3 &&
+ current_frame_flags_ & ~PUSH_PROMISE_FLAG_END_PUSH_PROMISE) {
set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS);
}
break;
@@ -1021,8 +1015,8 @@ void SpdyFramer::ProcessControlFrameHeader(uint16 control_frame_type_field) {
// block. The start of the header block varies with the control type.
DCHECK_GE(frame_size_without_variable_data,
static_cast<int32>(current_frame_buffer_length_));
- remaining_control_header_ = frame_size_without_variable_data -
- current_frame_buffer_length_;
+ remaining_control_header_ =
+ frame_size_without_variable_data - current_frame_buffer_length_;
CHANGE_STATE(SPDY_CONTROL_FRAME_BEFORE_HEADER_BLOCK);
return;
@@ -1031,7 +1025,8 @@ void SpdyFramer::ProcessControlFrameHeader(uint16 control_frame_type_field) {
CHANGE_STATE(SPDY_CONTROL_FRAME_PAYLOAD);
}
-size_t SpdyFramer::UpdateCurrentFrameBuffer(const char** data, size_t* len,
+size_t SpdyFramer::UpdateCurrentFrameBuffer(const char** data,
+ size_t* len,
size_t max_bytes) {
size_t bytes_to_read = std::min(*len, max_bytes);
if (bytes_to_read > 0) {
@@ -1047,11 +1042,10 @@ size_t SpdyFramer::UpdateCurrentFrameBuffer(const char** data, size_t* len,
return bytes_to_read;
}
-size_t SpdyFramer::GetSerializedLength(
- const SpdyMajorVersion spdy_version,
- const SpdyHeaderBlock* headers) {
- const size_t num_name_value_pairs_size
- = (spdy_version < SPDY3) ? sizeof(uint16) : sizeof(uint32);
+size_t SpdyFramer::GetSerializedLength(const SpdyMajorVersion spdy_version,
+ const SpdyHeaderBlock* headers) {
+ const size_t num_name_value_pairs_size =
+ (spdy_version < SPDY3) ? sizeof(uint16) : sizeof(uint32);
const size_t length_of_name_size = num_name_value_pairs_size;
const size_t length_of_value_size = num_name_value_pairs_size;
@@ -1117,8 +1111,7 @@ static void WriteZ(const base::StringPiece& data,
// If we are switching from standard to non-standard data then we need to end
// the current Huffman context to avoid it leaking between them.
- if (out->clas == kZStandardData &&
- clas != kZStandardData) {
+ if (out->clas == kZStandardData && clas != kZStandardData) {
out->avail_in = 0;
rv = deflate(out, Z_PARTIAL_FLUSH);
DCHECK_EQ(Z_OK, rv);
@@ -1224,19 +1217,13 @@ void SpdyFramer::WriteHeaderBlockToZ(const SpdyHeaderBlock* headers,
}
WriteZ(cookie, kZCookieData, z);
}
- } else if (it->first == "accept" ||
- it->first == "accept-charset" ||
+ } else if (it->first == "accept" || it->first == "accept-charset" ||
it->first == "accept-encoding" ||
- it->first == "accept-language" ||
- it->first == "host" ||
- it->first == "version" ||
- it->first == "method" ||
- it->first == "scheme" ||
- it->first == ":host" ||
- it->first == ":version" ||
- it->first == ":method" ||
- it->first == ":scheme" ||
- it->first == "user-agent") {
+ it->first == "accept-language" || it->first == "host" ||
+ it->first == "version" || it->first == "method" ||
+ it->first == "scheme" || it->first == ":host" ||
+ it->first == ":version" || it->first == ":method" ||
+ it->first == ":scheme" || it->first == "user-agent") {
WriteLengthZ(it->second.size(), length_length, kZStandardData, z);
WriteZ(it->second, kZStandardData, z);
} else {
@@ -1260,8 +1247,8 @@ size_t SpdyFramer::ProcessControlFrameBeforeHeaderBlock(const char* data,
const size_t original_len = len;
if (remaining_control_header_ > 0) {
- size_t bytes_read = UpdateCurrentFrameBuffer(&data, &len,
- remaining_control_header_);
+ size_t bytes_read =
+ UpdateCurrentFrameBuffer(&data, &len, remaining_control_header_);
remaining_control_header_ -= bytes_read;
remaining_data_length_ -= bytes_read;
}
@@ -1272,47 +1259,45 @@ size_t SpdyFramer::ProcessControlFrameBeforeHeaderBlock(const char* data,
reader.Seek(GetControlFrameHeaderSize()); // Seek past frame header.
switch (current_frame_type_) {
- case SYN_STREAM:
- {
- DCHECK_GE(SPDY3, protocol_version());
- bool successful_read = true;
- successful_read = reader.ReadUInt31(&current_frame_stream_id_);
- DCHECK(successful_read);
- if (current_frame_stream_id_ == 0) {
- set_error(SPDY_INVALID_CONTROL_FRAME);
- break;
- }
+ case SYN_STREAM: {
+ DCHECK_GE(SPDY3, protocol_version());
+ bool successful_read = true;
+ successful_read = reader.ReadUInt31(&current_frame_stream_id_);
+ DCHECK(successful_read);
+ if (current_frame_stream_id_ == 0) {
+ set_error(SPDY_INVALID_CONTROL_FRAME);
+ break;
+ }
- SpdyStreamId associated_to_stream_id = kInvalidStream;
- successful_read = reader.ReadUInt31(&associated_to_stream_id);
- DCHECK(successful_read);
+ SpdyStreamId associated_to_stream_id = kInvalidStream;
+ successful_read = reader.ReadUInt31(&associated_to_stream_id);
+ DCHECK(successful_read);
- SpdyPriority priority = 0;
- successful_read = reader.ReadUInt8(&priority);
- DCHECK(successful_read);
- if (protocol_version() <= SPDY2) {
- priority = priority >> 6;
- } else {
- priority = priority >> 5;
- }
+ SpdyPriority priority = 0;
+ successful_read = reader.ReadUInt8(&priority);
+ DCHECK(successful_read);
+ if (protocol_version() <= SPDY2) {
+ priority = priority >> 6;
+ } else {
+ priority = priority >> 5;
+ }
- // Seek past unused byte; used to be credential slot in SPDY 3.
- reader.Seek(1);
+ // Seek past unused byte; used to be credential slot in SPDY 3.
+ reader.Seek(1);
- DCHECK(reader.IsDoneReading());
- if (debug_visitor_) {
- debug_visitor_->OnReceiveCompressedFrame(
- current_frame_stream_id_,
- current_frame_type_,
- current_frame_length_);
- }
- visitor_->OnSynStream(
- current_frame_stream_id_,
- associated_to_stream_id,
- priority,
- (current_frame_flags_ & CONTROL_FLAG_FIN) != 0,
- (current_frame_flags_ & CONTROL_FLAG_UNIDIRECTIONAL) != 0);
+ DCHECK(reader.IsDoneReading());
+ if (debug_visitor_) {
+ debug_visitor_->OnReceiveCompressedFrame(current_frame_stream_id_,
+ current_frame_type_,
+ current_frame_length_);
}
+ visitor_->OnSynStream(
+ current_frame_stream_id_,
+ associated_to_stream_id,
+ priority,
+ (current_frame_flags_ & CONTROL_FLAG_FIN) != 0,
+ (current_frame_flags_ & CONTROL_FLAG_UNIDIRECTIONAL) != 0);
+ }
CHANGE_STATE(SPDY_CONTROL_FRAME_HEADER_BLOCK);
break;
case SETTINGS:
@@ -1321,7 +1306,8 @@ size_t SpdyFramer::ProcessControlFrameBeforeHeaderBlock(const char* data,
visitor_->OnSettingsAck();
CHANGE_STATE(SPDY_AUTO_RESET);
} else {
- visitor_->OnSettings(current_frame_flags_ &
+ visitor_->OnSettings(
+ current_frame_flags_ &
SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS);
CHANGE_STATE(SPDY_SETTINGS_FRAME_PAYLOAD);
}
@@ -1347,8 +1333,8 @@ size_t SpdyFramer::ProcessControlFrameBeforeHeaderBlock(const char* data,
reader.Seek(2);
}
if (protocol_version() > SPDY3 &&
- !(current_frame_flags_ & HEADERS_FLAG_END_HEADERS) &&
- current_frame_type_ == HEADERS) {
+ !(current_frame_flags_ & HEADERS_FLAG_END_HEADERS) &&
+ current_frame_type_ == HEADERS) {
expect_continuation_ = current_frame_stream_id_;
end_stream_when_done_ = current_frame_flags_ & CONTROL_FLAG_FIN;
}
@@ -1367,88 +1353,80 @@ size_t SpdyFramer::ProcessControlFrameBeforeHeaderBlock(const char* data,
reported_type = SYN_STREAM;
}
debug_visitor_->OnReceiveCompressedFrame(
- current_frame_stream_id_,
- reported_type,
- current_frame_length_);
+ current_frame_stream_id_, reported_type, current_frame_length_);
}
if (current_frame_type_ == SYN_REPLY) {
visitor_->OnSynReply(
current_frame_stream_id_,
(current_frame_flags_ & CONTROL_FLAG_FIN) != 0);
} else if (protocol_version() > SPDY3 &&
- current_frame_flags_ & HEADERS_FLAG_PRIORITY) {
+ current_frame_flags_ & HEADERS_FLAG_PRIORITY) {
// SPDY 4+ is missing SYN_STREAM. Simulate it so that API changes
// can be made independent of wire changes.
- visitor_->OnSynStream(
- current_frame_stream_id_,
- 0, // associated_to_stream_id
- priority,
- current_frame_flags_ & CONTROL_FLAG_FIN,
- false); // unidirectional
+ visitor_->OnSynStream(current_frame_stream_id_,
+ 0, // associated_to_stream_id
+ priority,
+ current_frame_flags_ & CONTROL_FLAG_FIN,
+ false); // unidirectional
} else {
- visitor_->OnHeaders(
- current_frame_stream_id_,
- (current_frame_flags_ & CONTROL_FLAG_FIN) != 0,
- expect_continuation_ == 0);
+ visitor_->OnHeaders(current_frame_stream_id_,
+ (current_frame_flags_ & CONTROL_FLAG_FIN) != 0,
+ expect_continuation_ == 0);
}
}
CHANGE_STATE(SPDY_CONTROL_FRAME_HEADER_BLOCK);
break;
- case PUSH_PROMISE:
- {
- DCHECK_LT(SPDY3, protocol_version());
- if (current_frame_stream_id_ == 0) {
- set_error(SPDY_INVALID_CONTROL_FRAME);
- break;
- }
- SpdyStreamId promised_stream_id = kInvalidStream;
- bool successful_read = reader.ReadUInt31(&promised_stream_id);
- DCHECK(successful_read);
- DCHECK(reader.IsDoneReading());
- if (promised_stream_id == 0) {
- set_error(SPDY_INVALID_CONTROL_FRAME);
- break;
- }
- if (!(current_frame_flags_ & PUSH_PROMISE_FLAG_END_PUSH_PROMISE)) {
- expect_continuation_ = current_frame_stream_id_;
- }
- if (debug_visitor_) {
- debug_visitor_->OnReceiveCompressedFrame(
- current_frame_stream_id_,
- current_frame_type_,
- current_frame_length_);
- }
- visitor_->OnPushPromise(current_frame_stream_id_,
- promised_stream_id,
- (current_frame_flags_ &
- PUSH_PROMISE_FLAG_END_PUSH_PROMISE) != 0);
+ case PUSH_PROMISE: {
+ DCHECK_LT(SPDY3, protocol_version());
+ if (current_frame_stream_id_ == 0) {
+ set_error(SPDY_INVALID_CONTROL_FRAME);
+ break;
+ }
+ SpdyStreamId promised_stream_id = kInvalidStream;
+ bool successful_read = reader.ReadUInt31(&promised_stream_id);
+ DCHECK(successful_read);
+ DCHECK(reader.IsDoneReading());
+ if (promised_stream_id == 0) {
+ set_error(SPDY_INVALID_CONTROL_FRAME);
+ break;
+ }
+ if (!(current_frame_flags_ & PUSH_PROMISE_FLAG_END_PUSH_PROMISE)) {
+ expect_continuation_ = current_frame_stream_id_;
}
+ if (debug_visitor_) {
+ debug_visitor_->OnReceiveCompressedFrame(current_frame_stream_id_,
+ current_frame_type_,
+ current_frame_length_);
+ }
+ visitor_->OnPushPromise(
+ current_frame_stream_id_,
+ promised_stream_id,
+ (current_frame_flags_ & PUSH_PROMISE_FLAG_END_PUSH_PROMISE) != 0);
+ }
CHANGE_STATE(SPDY_CONTROL_FRAME_HEADER_BLOCK);
break;
- case CONTINUATION:
- {
- // Check to make sure the stream id of the current frame is
- // the same as that of the preceding frame.
- // If we're at this point we should already know that
- // expect_continuation_ != 0, so this doubles as a check
- // that current_frame_stream_id != 0.
- if (current_frame_stream_id_ != expect_continuation_) {
- set_error(SPDY_INVALID_CONTROL_FRAME);
- break;
- }
- if (current_frame_flags_ & HEADERS_FLAG_END_HEADERS) {
- expect_continuation_ = 0;
- }
- if (debug_visitor_) {
- debug_visitor_->OnReceiveCompressedFrame(
- current_frame_stream_id_,
- current_frame_type_,
- current_frame_length_);
- }
- visitor_->OnContinuation(current_frame_stream_id_,
- (current_frame_flags_ &
- HEADERS_FLAG_END_HEADERS) != 0);
+ case CONTINUATION: {
+ // Check to make sure the stream id of the current frame is
+ // the same as that of the preceding frame.
+ // If we're at this point we should already know that
+ // expect_continuation_ != 0, so this doubles as a check
+ // that current_frame_stream_id != 0.
+ if (current_frame_stream_id_ != expect_continuation_) {
+ set_error(SPDY_INVALID_CONTROL_FRAME);
+ break;
+ }
+ if (current_frame_flags_ & HEADERS_FLAG_END_HEADERS) {
+ expect_continuation_ = 0;
}
+ if (debug_visitor_) {
+ debug_visitor_->OnReceiveCompressedFrame(current_frame_stream_id_,
+ current_frame_type_,
+ current_frame_length_);
+ }
+ visitor_->OnContinuation(
+ current_frame_stream_id_,
+ (current_frame_flags_ & HEADERS_FLAG_END_HEADERS) != 0);
+ }
CHANGE_STATE(SPDY_CONTROL_FRAME_HEADER_BLOCK);
break;
default:
@@ -1468,18 +1446,15 @@ size_t SpdyFramer::ProcessControlFrameHeaderBlock(const char* data,
DCHECK_EQ(SPDY_CONTROL_FRAME_HEADER_BLOCK, state_);
bool processed_successfully = true;
- if (current_frame_type_ != SYN_STREAM &&
- current_frame_type_ != SYN_REPLY &&
- current_frame_type_ != HEADERS &&
- current_frame_type_ != PUSH_PROMISE &&
+ if (current_frame_type_ != SYN_STREAM && current_frame_type_ != SYN_REPLY &&
+ current_frame_type_ != HEADERS && current_frame_type_ != PUSH_PROMISE &&
current_frame_type_ != CONTINUATION) {
LOG(DFATAL) << "Unhandled frame type in ProcessControlFrameHeaderBlock.";
}
size_t process_bytes = std::min(data_len, remaining_data_length_);
if (is_hpack_header_block) {
- if (!hpack_decoder_.HandleControlFrameHeadersData(current_frame_stream_id_,
- data,
- process_bytes)) {
+ if (!hpack_decoder_.HandleControlFrameHeadersData(
+ current_frame_stream_id_, data, process_bytes)) {
// TODO(jgraettinger): Finer-grained HPACK error codes.
set_error(SPDY_DECOMPRESS_FAILURE);
processed_successfully = false;
@@ -1500,7 +1475,7 @@ size_t SpdyFramer::ProcessControlFrameHeaderBlock(const char* data,
if (expect_continuation_ == 0) {
if (is_hpack_header_block) {
if (!hpack_decoder_.HandleControlFrameHeadersComplete(
- current_frame_stream_id_)) {
+ current_frame_stream_id_)) {
set_error(SPDY_DECOMPRESS_FAILURE);
processed_successfully = false;
} else {
@@ -1601,9 +1576,8 @@ void SpdyFramer::DeliverHpackBlockAsSpdy3Block() {
ProcessControlFrameHeaderBlock(NULL, 0, false);
return;
}
- SpdyFrameBuilder builder(
- GetSerializedLength(protocol_version(), &block),
- SPDY3);
+ SpdyFrameBuilder builder(GetSerializedLength(protocol_version(), &block),
+ SPDY3);
SerializeNameValueBlockWithoutCompression(&builder, block);
scoped_ptr<SpdyFrame> frame(builder.take());
@@ -1622,8 +1596,8 @@ bool SpdyFramer::ProcessSetting(const char* data) {
// Maintain behavior of old SPDY 2 bug with byte ordering of flags/id.
if (protocol_version() <= SPDY3) {
const uint32 id_and_flags_wire = *(reinterpret_cast<const uint32*>(data));
- SettingsFlagsAndId id_and_flags =
- SettingsFlagsAndId::FromWireFormat(protocol_version(), id_and_flags_wire);
+ SettingsFlagsAndId id_and_flags = SettingsFlagsAndId::FromWireFormat(
+ protocol_version(), id_and_flags_wire);
id_field = id_and_flags.id();
flags = id_and_flags.flags();
value = ntohl(*(reinterpret_cast<const uint32*>(data + 4)));
@@ -1666,8 +1640,8 @@ bool SpdyFramer::ProcessSetting(const char* data) {
size_t SpdyFramer::ProcessControlFramePayload(const char* data, size_t len) {
size_t original_len = len;
- size_t bytes_read = UpdateCurrentFrameBuffer(&data, &len,
- remaining_data_length_);
+ size_t bytes_read =
+ UpdateCurrentFrameBuffer(&data, &len, remaining_data_length_);
remaining_data_length_ -= bytes_read;
if (remaining_data_length_ == 0) {
SpdyFrameReader reader(current_frame_buffer_.get(),
@@ -1677,42 +1651,38 @@ size_t SpdyFramer::ProcessControlFramePayload(const char* data, size_t len) {
// Use frame-specific handlers.
switch (current_frame_type_) {
case PING: {
- SpdyPingId id = 0;
- bool is_ack = protocol_version() > SPDY3 &&
- (current_frame_flags_ & PING_FLAG_ACK);
- bool successful_read = true;
- if (protocol_version() <= SPDY3) {
- uint32 id32 = 0;
- successful_read = reader.ReadUInt32(&id32);
- id = id32;
- } else {
- successful_read = reader.ReadUInt64(&id);
- }
- DCHECK(successful_read);
- DCHECK(reader.IsDoneReading());
- visitor_->OnPing(id, is_ack);
+ SpdyPingId id = 0;
+ bool is_ack = protocol_version() > SPDY3 &&
+ (current_frame_flags_ & PING_FLAG_ACK);
+ bool successful_read = true;
+ if (protocol_version() <= SPDY3) {
+ uint32 id32 = 0;
+ successful_read = reader.ReadUInt32(&id32);
+ id = id32;
+ } else {
+ successful_read = reader.ReadUInt64(&id);
}
- break;
+ DCHECK(successful_read);
+ DCHECK(reader.IsDoneReading());
+ visitor_->OnPing(id, is_ack);
+ } break;
case WINDOW_UPDATE: {
- uint32 delta_window_size = 0;
- bool successful_read = true;
- if (protocol_version() <= SPDY3) {
- successful_read = reader.ReadUInt31(&current_frame_stream_id_);
- DCHECK(successful_read);
- }
- successful_read = reader.ReadUInt32(&delta_window_size);
+ uint32 delta_window_size = 0;
+ bool successful_read = true;
+ if (protocol_version() <= SPDY3) {
+ successful_read = reader.ReadUInt31(&current_frame_stream_id_);
DCHECK(successful_read);
- DCHECK(reader.IsDoneReading());
- visitor_->OnWindowUpdate(current_frame_stream_id_,
- delta_window_size);
}
- break;
+ successful_read = reader.ReadUInt32(&delta_window_size);
+ DCHECK(successful_read);
+ DCHECK(reader.IsDoneReading());
+ visitor_->OnWindowUpdate(current_frame_stream_id_, delta_window_size);
+ } break;
case BLOCKED: {
- DCHECK_LT(SPDY3, protocol_version());
- DCHECK(reader.IsDoneReading());
- visitor_->OnBlocked(current_frame_stream_id_);
- }
- break;
+ DCHECK_LT(SPDY3, protocol_version());
+ DCHECK(reader.IsDoneReading());
+ visitor_->OnBlocked(current_frame_stream_id_);
+ } break;
default:
// Unreachable.
LOG(FATAL) << "Unhandled control frame " << current_frame_type_;
@@ -1758,8 +1728,8 @@ size_t SpdyFramer::ProcessGoAwayFramePayload(const char* data, size_t len) {
DCHECK(successful_read);
if (SpdyConstants::IsValidGoAwayStatus(protocol_version(),
status_raw)) {
- status = SpdyConstants::ParseGoAwayStatus(protocol_version(),
- status_raw);
+ status =
+ SpdyConstants::ParseGoAwayStatus(protocol_version(), status_raw);
} else {
DCHECK(false);
// Throw an error for SPDY4+, keep liberal behavior
@@ -1974,8 +1944,8 @@ size_t SpdyFramer::ProcessIgnoredControlFramePayload(/*const char* data,*/
}
size_t SpdyFramer::ParseHeaderBlockInBuffer(const char* header_data,
- size_t header_length,
- SpdyHeaderBlock* block) const {
+ size_t header_length,
+ SpdyHeaderBlock* block) const {
SpdyFrameReader reader(header_data, header_length);
// Read number of headers.
@@ -2000,7 +1970,7 @@ size_t SpdyFramer::ParseHeaderBlockInBuffer(const char* header_data,
// Read header name.
if ((protocol_version() <= SPDY2) ? !reader.ReadStringPiece16(&temp)
- : !reader.ReadStringPiece32(&temp)) {
+ : !reader.ReadStringPiece32(&temp)) {
DVLOG(1) << "Unable to read header name (" << index + 1 << " of "
<< num_headers << ").";
return 0;
@@ -2009,7 +1979,7 @@ size_t SpdyFramer::ParseHeaderBlockInBuffer(const char* header_data,
// Read header value.
if ((protocol_version() <= SPDY2) ? !reader.ReadStringPiece16(&temp)
- : !reader.ReadStringPiece32(&temp)) {
+ : !reader.ReadStringPiece32(&temp)) {
DVLOG(1) << "Unable to read header value (" << index + 1 << " of "
<< num_headers << ").";
return 0;
@@ -2047,9 +2017,9 @@ SpdySerializedFrame* SpdyFramer::SerializeData(
++num_padding_fields;
}
- const size_t size_with_padding = num_padding_fields +
- data_ir.data().length() + data_ir.padding_payload_len() +
- GetDataFrameMinimumSize();
+ const size_t size_with_padding =
+ num_padding_fields + data_ir.data().length() +
+ data_ir.padding_payload_len() + GetDataFrameMinimumSize();
SpdyFrameBuilder builder(size_with_padding, protocol_version());
builder.WriteDataFrameHeader(*this, data_ir.stream_id(), flags);
if (data_ir.pad_high()) {
@@ -2105,8 +2075,9 @@ SpdySerializedFrame* SpdyFramer::SerializeDataFrameHeaderWithPaddingLengthField(
if (data_ir.pad_low()) {
builder.WriteUInt8(data_ir.padding_payload_len() & 0xff);
}
- builder.OverwriteLength(*this, num_padding_fields +
- data_ir.data().length() + data_ir.padding_payload_len());
+ builder.OverwriteLength(*this,
+ num_padding_fields + data_ir.data().length() +
+ data_ir.padding_payload_len());
} else {
builder.OverwriteLength(*this, data_ir.data().length());
}
@@ -2144,8 +2115,8 @@ SpdySerializedFrame* SpdyFramer::SerializeSynStream(
string hpack_encoding;
if (protocol_version() > SPDY3) {
if (enable_compression_) {
- hpack_encoder_.EncodeHeaderSet(
- syn_stream.name_value_block(), &hpack_encoding);
+ hpack_encoder_.EncodeHeaderSet(syn_stream.name_value_block(),
+ &hpack_encoding);
} else {
hpack_encoder_.EncodeHeaderSetWithoutCompression(
syn_stream.name_value_block(), &hpack_encoding);
@@ -2163,10 +2134,7 @@ SpdySerializedFrame* SpdyFramer::SerializeSynStream(
builder.WriteUInt8(priority << ((protocol_version() <= SPDY2) ? 6 : 5));
builder.WriteUInt8(0); // Unused byte where credential slot used to be.
} else {
- builder.BeginNewFrame(*this,
- HEADERS,
- flags,
- syn_stream.stream_id());
+ builder.BeginNewFrame(*this, HEADERS, flags, syn_stream.stream_id());
builder.WriteUInt32(priority);
}
DCHECK_EQ(GetSynStreamMinimumSize(), builder.length());
@@ -2177,15 +2145,14 @@ SpdySerializedFrame* SpdyFramer::SerializeSynStream(
}
if (debug_visitor_) {
- const size_t payload_len = protocol_version() > SPDY3 ?
- hpack_encoding.size() :
- GetSerializedLength(protocol_version(),
- &(syn_stream.name_value_block()));
+ const size_t payload_len =
+ protocol_version() > SPDY3
+ ? hpack_encoding.size()
+ : GetSerializedLength(protocol_version(),
+ &(syn_stream.name_value_block()));
// SPDY 4 reports this compression as a SYN_STREAM compression.
- debug_visitor_->OnSendCompressedFrame(syn_stream.stream_id(),
- SYN_STREAM,
- payload_len,
- builder.length());
+ debug_visitor_->OnSendCompressedFrame(
+ syn_stream.stream_id(), SYN_STREAM, payload_len, builder.length());
}
return builder.take();
@@ -2209,8 +2176,8 @@ SpdySerializedFrame* SpdyFramer::SerializeSynReply(
string hpack_encoding;
if (protocol_version() > SPDY3) {
if (enable_compression_) {
- hpack_encoder_.EncodeHeaderSet(
- syn_reply.name_value_block(), &hpack_encoding);
+ hpack_encoder_.EncodeHeaderSet(syn_reply.name_value_block(),
+ &hpack_encoding);
} else {
hpack_encoder_.EncodeHeaderSetWithoutCompression(
syn_reply.name_value_block(), &hpack_encoding);
@@ -2225,10 +2192,7 @@ SpdySerializedFrame* SpdyFramer::SerializeSynReply(
builder.WriteControlFrameHeader(*this, SYN_REPLY, flags);
builder.WriteUInt32(syn_reply.stream_id());
} else {
- builder.BeginNewFrame(*this,
- HEADERS,
- flags,
- syn_reply.stream_id());
+ builder.BeginNewFrame(*this, HEADERS, flags, syn_reply.stream_id());
}
if (protocol_version() < SPDY3) {
builder.WriteUInt16(0); // Unused.
@@ -2241,14 +2205,13 @@ SpdySerializedFrame* SpdyFramer::SerializeSynReply(
}
if (debug_visitor_) {
- const size_t payload_len = protocol_version() > SPDY3 ?
- hpack_encoding.size() :
- GetSerializedLength(protocol_version(),
- &(syn_reply.name_value_block()));
- debug_visitor_->OnSendCompressedFrame(syn_reply.stream_id(),
- SYN_REPLY,
- payload_len,
- builder.length());
+ const size_t payload_len =
+ protocol_version() > SPDY3
+ ? hpack_encoding.size()
+ : GetSerializedLength(protocol_version(),
+ &(syn_reply.name_value_block()));
+ debug_visitor_->OnSendCompressedFrame(
+ syn_reply.stream_id(), SYN_REPLY, payload_len, builder.length());
}
return builder.take();
@@ -2304,8 +2267,8 @@ SpdySerializedFrame* SpdyFramer::SerializeSettings(
size_t setting_size = (protocol_version() <= SPDY3 ? 8 : 5);
// Size, in bytes, of this SETTINGS frame.
- const size_t size = GetSettingsMinimumSize() +
- (values->size() * setting_size);
+ const size_t size =
+ GetSettingsMinimumSize() + (values->size() * setting_size);
SpdyFrameBuilder builder(size, protocol_version());
if (protocol_version() <= SPDY3) {
builder.WriteControlFrameHeader(*this, SETTINGS, flags);
@@ -2339,8 +2302,8 @@ SpdySerializedFrame* SpdyFramer::SerializeSettings(
uint32 id_and_flags_wire = flags_and_id.GetWireFormat(protocol_version());
builder.WriteBytes(&id_and_flags_wire, 4);
} else {
- builder.WriteUInt8(SpdyConstants::SerializeSettingId(protocol_version(),
- it->first));
+ builder.WriteUInt8(
+ SpdyConstants::SerializeSettingId(protocol_version(), it->first));
}
builder.WriteUInt32(it->second.value);
}
@@ -2367,7 +2330,6 @@ SpdySerializedFrame* SpdyFramer::SerializePing(const SpdyPingIR& ping) const {
SpdySerializedFrame* SpdyFramer::SerializeGoAway(
const SpdyGoAwayIR& goaway) const {
-
// Compute the output buffer size, take opaque data into account.
uint16 expected_length = GetGoAwayMinimumSize();
if (protocol_version() > SPDY3) {
@@ -2433,8 +2395,8 @@ SpdySerializedFrame* SpdyFramer::SerializeHeaders(
string hpack_encoding;
if (protocol_version() > SPDY3) {
if (enable_compression_) {
- hpack_encoder_.EncodeHeaderSet(
- headers.name_value_block(), &hpack_encoding);
+ hpack_encoder_.EncodeHeaderSet(headers.name_value_block(),
+ &hpack_encoding);
} else {
hpack_encoder_.EncodeHeaderSetWithoutCompression(
headers.name_value_block(), &hpack_encoding);
@@ -2454,10 +2416,7 @@ SpdySerializedFrame* SpdyFramer::SerializeHeaders(
builder.WriteControlFrameHeader(*this, HEADERS, flags);
builder.WriteUInt32(headers.stream_id());
} else {
- builder.BeginNewFrame(*this,
- HEADERS,
- flags,
- headers.stream_id());
+ builder.BeginNewFrame(*this, HEADERS, flags, headers.stream_id());
if (headers.has_priority()) {
builder.WriteUInt32(priority);
}
@@ -2468,23 +2427,20 @@ SpdySerializedFrame* SpdyFramer::SerializeHeaders(
DCHECK_EQ(GetHeadersMinimumSize(), builder.length());
if (protocol_version() > SPDY3) {
- WritePayloadWithContinuation(&builder,
- hpack_encoding,
- headers.stream_id(),
- HEADERS);
+ WritePayloadWithContinuation(
+ &builder, hpack_encoding, headers.stream_id(), HEADERS);
} else {
SerializeNameValueBlock(&builder, headers);
}
if (debug_visitor_) {
- const size_t payload_len = protocol_version() > SPDY3 ?
- hpack_encoding.size() :
- GetSerializedLength(protocol_version(),
- &(headers.name_value_block()));
- debug_visitor_->OnSendCompressedFrame(headers.stream_id(),
- HEADERS,
- payload_len,
- builder.length());
+ const size_t payload_len =
+ protocol_version() > SPDY3
+ ? hpack_encoding.size()
+ : GetSerializedLength(protocol_version(),
+ &(headers.name_value_block()));
+ debug_visitor_->OnSendCompressedFrame(
+ headers.stream_id(), HEADERS, payload_len, builder.length());
}
return builder.take();
@@ -2497,10 +2453,8 @@ SpdySerializedFrame* SpdyFramer::SerializeWindowUpdate(
builder.WriteControlFrameHeader(*this, WINDOW_UPDATE, kNoFlags);
builder.WriteUInt32(window_update.stream_id());
} else {
- builder.BeginNewFrame(*this,
- WINDOW_UPDATE,
- kNoFlags,
- window_update.stream_id());
+ builder.BeginNewFrame(
+ *this, WINDOW_UPDATE, kNoFlags, window_update.stream_id());
}
builder.WriteUInt32(window_update.delta());
DCHECK_EQ(GetWindowUpdateSize(), builder.length());
@@ -2530,8 +2484,8 @@ SpdyFrame* SpdyFramer::SerializePushPromise(
string hpack_encoding;
if (protocol_version() > SPDY3) {
if (enable_compression_) {
- hpack_encoder_.EncodeHeaderSet(
- push_promise.name_value_block(), &hpack_encoding);
+ hpack_encoder_.EncodeHeaderSet(push_promise.name_value_block(),
+ &hpack_encoding);
} else {
hpack_encoder_.EncodeHeaderSetWithoutCompression(
push_promise.name_value_block(), &hpack_encoding);
@@ -2547,29 +2501,25 @@ SpdyFrame* SpdyFramer::SerializePushPromise(
}
SpdyFrameBuilder builder(size, protocol_version());
- builder.BeginNewFrame(*this,
- PUSH_PROMISE,
- flags,
- push_promise.stream_id());
+ builder.BeginNewFrame(*this, PUSH_PROMISE, flags, push_promise.stream_id());
builder.WriteUInt32(push_promise.promised_stream_id());
DCHECK_EQ(GetPushPromiseMinimumSize(), builder.length());
if (protocol_version() > SPDY3) {
- WritePayloadWithContinuation(&builder,
- hpack_encoding,
- push_promise.stream_id(),
- PUSH_PROMISE);
+ WritePayloadWithContinuation(
+ &builder, hpack_encoding, push_promise.stream_id(), PUSH_PROMISE);
} else {
SerializeNameValueBlock(&builder, push_promise);
}
if (debug_visitor_) {
- const size_t payload_len = protocol_version() > SPDY3 ?
- hpack_encoding.size() :
- GetSerializedLength(protocol_version(),
- &(push_promise.name_value_block()));
- debug_visitor_->OnSendCompressedFrame(push_promise.stream_id(),
- PUSH_PROMISE, payload_len, builder.length());
+ const size_t payload_len =
+ protocol_version() > SPDY3
+ ? hpack_encoding.size()
+ : GetSerializedLength(protocol_version(),
+ &(push_promise.name_value_block()));
+ debug_visitor_->OnSendCompressedFrame(
+ push_promise.stream_id(), PUSH_PROMISE, payload_len, builder.length());
}
return builder.take();
@@ -2590,8 +2540,8 @@ SpdyFrame* SpdyFramer::SerializeContinuation(
size_t size = GetContinuationMinimumSize();
string hpack_encoding;
if (enable_compression_) {
- hpack_encoder_.EncodeHeaderSet(
- continuation.name_value_block(), &hpack_encoding);
+ hpack_encoder_.EncodeHeaderSet(continuation.name_value_block(),
+ &hpack_encoding);
} else {
hpack_encoder_.EncodeHeaderSetWithoutCompression(
continuation.name_value_block(), &hpack_encoding);
@@ -2599,16 +2549,15 @@ SpdyFrame* SpdyFramer::SerializeContinuation(
size += hpack_encoding.size();
SpdyFrameBuilder builder(size, protocol_version());
- builder.BeginNewFrame(*this, CONTINUATION, flags,
- continuation.stream_id());
+ builder.BeginNewFrame(*this, CONTINUATION, flags, continuation.stream_id());
DCHECK_EQ(GetContinuationMinimumSize(), builder.length());
builder.WriteBytes(&hpack_encoding[0], hpack_encoding.size());
if (debug_visitor_) {
const size_t payload_len = hpack_encoding.size();
- debug_visitor_->OnSendCompressedFrame(continuation.stream_id(),
- CONTINUATION, payload_len, builder.length());
+ debug_visitor_->OnSendCompressedFrame(
+ continuation.stream_id(), CONTINUATION, payload_len, builder.length());
}
return builder.take();
@@ -2679,7 +2628,7 @@ SpdySerializedFrame* SpdyFramer::SerializeFrame(const SpdyFrameIR& frame) {
size_t SpdyFramer::GetSerializedLength(const SpdyHeaderBlock& headers) {
CHECK_GE(SPDY3, protocol_version());
const size_t uncompressed_length =
- GetSerializedLength(protocol_version(), &headers);
+ GetSerializedLength(protocol_version(), &headers);
if (!enable_compression_) {
return uncompressed_length;
}
@@ -2703,53 +2652,49 @@ void SpdyFramer::WritePayloadWithContinuation(SpdyFrameBuilder* builder,
SpdyFrameType type) {
const size_t kMaxControlFrameSize = GetControlFrameBufferMaxSize();
- // In addition to the prefix, fixed_field_size includes the size of
- // any fields that come before the variable-length name/value block.
- size_t fixed_field_size = 0;
- uint8 end_flag = 0;
- uint8 flags = 0;
- if (type == HEADERS) {
- fixed_field_size = GetHeadersMinimumSize();
- end_flag = HEADERS_FLAG_END_HEADERS;
- } else if (type == PUSH_PROMISE) {
- fixed_field_size = GetPushPromiseMinimumSize();
- end_flag = PUSH_PROMISE_FLAG_END_PUSH_PROMISE;
- } else {
- DLOG(FATAL) << "CONTINUATION frames cannot be used with frame type "
- << FrameTypeToString(type);
- }
-
- // Write as much of the payload as possible into the initial frame.
- size_t bytes_remaining = hpack_encoding.size() -
- std::min(hpack_encoding.size(),
- kMaxControlFrameSize - fixed_field_size);
- builder->WriteBytes(&hpack_encoding[0],
- hpack_encoding.size() - bytes_remaining);
-
- if (bytes_remaining > 0) {
- builder->OverwriteLength(*this,
- kMaxControlFrameSize - GetControlFrameHeaderSize());
- }
-
- // Tack on CONTINUATION frames for the overflow.
- while (bytes_remaining > 0) {
- size_t bytes_to_write = std::min(bytes_remaining,
- kMaxControlFrameSize -
- GetContinuationMinimumSize());
- // Write CONTINUATION frame prefix.
- if (bytes_remaining == bytes_to_write) {
- flags |= end_flag;
- }
- builder->BeginNewFrame(*this,
- CONTINUATION,
- flags,
- stream_id);
- // Write payload fragment.
- builder->WriteBytes(&hpack_encoding[hpack_encoding.size() -
- bytes_remaining],
- bytes_to_write);
- bytes_remaining -= bytes_to_write;
+ // In addition to the prefix, fixed_field_size includes the size of
+ // any fields that come before the variable-length name/value block.
+ size_t fixed_field_size = 0;
+ uint8 end_flag = 0;
+ uint8 flags = 0;
+ if (type == HEADERS) {
+ fixed_field_size = GetHeadersMinimumSize();
+ end_flag = HEADERS_FLAG_END_HEADERS;
+ } else if (type == PUSH_PROMISE) {
+ fixed_field_size = GetPushPromiseMinimumSize();
+ end_flag = PUSH_PROMISE_FLAG_END_PUSH_PROMISE;
+ } else {
+ DLOG(FATAL) << "CONTINUATION frames cannot be used with frame type "
+ << FrameTypeToString(type);
+ }
+
+ // Write as much of the payload as possible into the initial frame.
+ size_t bytes_remaining =
+ hpack_encoding.size() -
+ std::min(hpack_encoding.size(), kMaxControlFrameSize - fixed_field_size);
+ builder->WriteBytes(&hpack_encoding[0],
+ hpack_encoding.size() - bytes_remaining);
+
+ if (bytes_remaining > 0) {
+ builder->OverwriteLength(
+ *this, kMaxControlFrameSize - GetControlFrameHeaderSize());
+ }
+
+ // Tack on CONTINUATION frames for the overflow.
+ while (bytes_remaining > 0) {
+ size_t bytes_to_write = std::min(
+ bytes_remaining, kMaxControlFrameSize - GetContinuationMinimumSize());
+ // Write CONTINUATION frame prefix.
+ if (bytes_remaining == bytes_to_write) {
+ flags |= end_flag;
}
+ builder->BeginNewFrame(*this, CONTINUATION, flags, stream_id);
+ // Write payload fragment.
+ builder->WriteBytes(
+ &hpack_encoding[hpack_encoding.size() - bytes_remaining],
+ bytes_to_write);
+ bytes_remaining -= bytes_to_write;
+ }
}
// The following compression setting are based on Brian Olson's analysis. See
@@ -2760,7 +2705,7 @@ void SpdyFramer::WritePayloadWithContinuation(SpdyFrameBuilder* builder,
// so disable compression in that case.
// TODO(phajdan.jr): Remove the special case when it's no longer necessary.
static const int kCompressorLevel = 0;
-#else // !defined(USE_SYSTEM_ZLIB)
+#else // !defined(USE_SYSTEM_ZLIB)
static const int kCompressorLevel = 9;
#endif // !defined(USE_SYSTEM_ZLIB)
static const int kCompressorWindowSizeInBits = 11;
@@ -2780,10 +2725,10 @@ z_stream* SpdyFramer::GetHeaderCompressor() {
kCompressorMemLevel,
Z_DEFAULT_STRATEGY);
if (success == Z_OK) {
- const char* dictionary = (protocol_version() <= SPDY2) ?
- kV2Dictionary : kV3Dictionary;
- const int dictionary_size = (protocol_version() <= SPDY2) ?
- kV2DictionarySize : kV3DictionarySize;
+ const char* dictionary =
+ (protocol_version() <= SPDY2) ? kV2Dictionary : kV3Dictionary;
+ const int dictionary_size =
+ (protocol_version() <= SPDY2) ? kV2DictionarySize : kV3DictionarySize;
success = deflateSetDictionary(header_compressor_.get(),
reinterpret_cast<const Bytef*>(dictionary),
dictionary_size);
@@ -2843,13 +2788,14 @@ bool SpdyFramer::IncrementallyDecompressControlFrameHeaderData(
int rv = inflate(decomp, Z_SYNC_FLUSH);
if (rv == Z_NEED_DICT) {
- const char* dictionary = (protocol_version() <= SPDY2) ? kV2Dictionary
- : kV3Dictionary;
- const int dictionary_size = (protocol_version() <= SPDY2) ?
- kV2DictionarySize : kV3DictionarySize;
+ const char* dictionary =
+ (protocol_version() <= SPDY2) ? kV2Dictionary : kV3Dictionary;
+ const int dictionary_size =
+ (protocol_version() <= SPDY2) ? kV2DictionarySize : kV3DictionarySize;
const DictionaryIds& ids = g_dictionary_ids.Get();
- const uLong dictionary_id = (protocol_version() <= SPDY2) ?
- ids.v2_dictionary_id : ids.v3_dictionary_id;
+ const uLong dictionary_id = (protocol_version() <= SPDY2)
+ ? ids.v2_dictionary_id
+ : ids.v3_dictionary_id;
// Need to try again with the right dictionary.
if (decomp->adler == dictionary_id) {
rv = inflateSetDictionary(decomp,
@@ -2886,12 +2832,14 @@ bool SpdyFramer::IncrementallyDecompressControlFrameHeaderData(
}
bool SpdyFramer::IncrementallyDeliverControlFrameHeaderData(
- SpdyStreamId stream_id, const char* data, size_t len) {
+ SpdyStreamId stream_id,
+ const char* data,
+ size_t len) {
bool read_successfully = true;
while (read_successfully && len > 0) {
size_t bytes_to_deliver = std::min(len, kHeaderDataChunkMaxSize);
- read_successfully = visitor_->OnControlFrameHeaderData(stream_id, data,
- bytes_to_deliver);
+ read_successfully =
+ visitor_->OnControlFrameHeaderData(stream_id, data, bytes_to_deliver);
data += bytes_to_deliver;
len -= bytes_to_deliver;
if (!read_successfully) {
@@ -2937,8 +2885,8 @@ void SpdyFramer::SerializeNameValueBlock(
}
// First build an uncompressed version to be fed into the compressor.
- const size_t uncompressed_len = GetSerializedLength(
- protocol_version(), &(frame.name_value_block()));
+ const size_t uncompressed_len =
+ GetSerializedLength(protocol_version(), &(frame.name_value_block()));
SpdyFrameBuilder uncompressed_builder(uncompressed_len, protocol_version());
SerializeNameValueBlockWithoutCompression(&uncompressed_builder,
frame.name_value_block());
@@ -2963,18 +2911,18 @@ void SpdyFramer::SerializeNameValueBlock(
const int compressed_max_size =
2 * deflateBound(compressor, uncompressed_len);
- // TODO(phajdan.jr): Clean up after we no longer need
- // to workaround http://crbug.com/139744.
+// TODO(phajdan.jr): Clean up after we no longer need
+// to workaround http://crbug.com/139744.
#if defined(USE_SYSTEM_ZLIB)
compressor->next_in = reinterpret_cast<Bytef*>(uncompressed_payload->data());
compressor->avail_in = uncompressed_len;
#endif // defined(USE_SYSTEM_ZLIB)
- compressor->next_out = reinterpret_cast<Bytef*>(
- builder->GetWritableBuffer(compressed_max_size));
+ compressor->next_out =
+ reinterpret_cast<Bytef*>(builder->GetWritableBuffer(compressed_max_size));
compressor->avail_out = compressed_max_size;
- // TODO(phajdan.jr): Clean up after we no longer need
- // to workaround http://crbug.com/139744.
+// TODO(phajdan.jr): Clean up after we no longer need
+// to workaround http://crbug.com/139744.
#if defined(USE_SYSTEM_ZLIB)
int rv = deflate(compressor, Z_SYNC_FLUSH);
if (rv != Z_OK) { // How can we know that it compressed everything?

Powered by Google App Engine
This is Rietveld 408576698