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 // TODO(rtenhove) clean up frame buffer size calculations so that we aren't | 5 // TODO(rtenhove) clean up frame buffer size calculations so that we aren't |
6 // constantly adding and subtracting header sizes; this is ugly and error- | 6 // constantly adding and subtracting header sizes; this is ugly and error- |
7 // prone. | 7 // prone. |
8 | 8 |
9 #include "net/spdy/spdy_framer.h" | 9 #include "net/spdy/spdy_framer.h" |
10 | 10 |
(...skipping 2014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2025 return read_successfully; | 2025 return read_successfully; |
2026 } | 2026 } |
2027 | 2027 |
2028 SpdyFrame* SpdyFramer::DuplicateFrame(const SpdyFrame& frame) { | 2028 SpdyFrame* SpdyFramer::DuplicateFrame(const SpdyFrame& frame) { |
2029 int size = SpdyFrame::kHeaderSize + frame.length(); | 2029 int size = SpdyFrame::kHeaderSize + frame.length(); |
2030 SpdyFrame* new_frame = new SpdyFrame(size); | 2030 SpdyFrame* new_frame = new SpdyFrame(size); |
2031 memcpy(new_frame->data(), frame.data(), size); | 2031 memcpy(new_frame->data(), frame.data(), size); |
2032 return new_frame; | 2032 return new_frame; |
2033 } | 2033 } |
2034 | 2034 |
2035 bool SpdyFramer::IsCompressible(const SpdyFrame& frame) const { | |
2036 // The important frames to compress are those which contain large | |
2037 // amounts of compressible data - namely the headers in the SYN_STREAM | |
2038 // and SYN_REPLY. | |
2039 if (frame.is_control_frame()) { | |
2040 const SpdyControlFrame& control_frame = | |
2041 reinterpret_cast<const SpdyControlFrame&>(frame); | |
2042 return control_frame.type() == SYN_STREAM || | |
2043 control_frame.type() == SYN_REPLY || | |
2044 control_frame.type() == HEADERS; | |
2045 } | |
2046 | |
2047 // We don't compress Data frames. | |
2048 return false; | |
2049 } | |
2050 | |
2051 void SpdyFramer::SerializeNameValueBlock( | 2035 void SpdyFramer::SerializeNameValueBlock( |
2052 SpdyFrameBuilder* builder, | 2036 SpdyFrameBuilder* builder, |
2053 const SpdyFrameWithNameValueBlockIR& frame) const { | 2037 const SpdyFrameWithNameValueBlockIR& frame) const { |
2054 const SpdyNameValueBlock* name_value_block = &(frame.name_value_block()); | 2038 const SpdyNameValueBlock* name_value_block = &(frame.name_value_block()); |
2055 | 2039 |
2056 // Serialize number of headers. | 2040 // Serialize number of headers. |
2057 if (protocol_version() < 3) { | 2041 if (protocol_version() < 3) { |
2058 builder->WriteUInt16(name_value_block->size()); | 2042 builder->WriteUInt16(name_value_block->size()); |
2059 } else { | 2043 } else { |
2060 builder->WriteUInt32(name_value_block->size()); | 2044 builder->WriteUInt32(name_value_block->size()); |
2061 } | 2045 } |
2062 | 2046 |
2063 // Serialize each header. | 2047 // Serialize each header. |
2064 for (SpdyHeaderBlock::const_iterator it = name_value_block->begin(); | 2048 for (SpdyHeaderBlock::const_iterator it = name_value_block->begin(); |
2065 it != name_value_block->end(); | 2049 it != name_value_block->end(); |
2066 ++it) { | 2050 ++it) { |
2067 if (protocol_version() < 3) { | 2051 if (protocol_version() < 3) { |
2068 builder->WriteString(it->first); | 2052 builder->WriteString(it->first); |
2069 builder->WriteString(it->second); | 2053 builder->WriteString(it->second); |
2070 } else { | 2054 } else { |
2071 builder->WriteStringPiece32(it->first); | 2055 builder->WriteStringPiece32(it->first); |
2072 builder->WriteStringPiece32(it->second); | 2056 builder->WriteStringPiece32(it->second); |
2073 } | 2057 } |
2074 } | 2058 } |
2075 } | 2059 } |
2076 | 2060 |
2077 } // namespace net | 2061 } // namespace net |
OLD | NEW |