| 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 <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <iterator> | 10 #include <iterator> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
| 17 #include "net/quic/quic_flags.h" |
| 17 #include "net/spdy/hpack/hpack_constants.h" | 18 #include "net/spdy/hpack/hpack_constants.h" |
| 18 #include "net/spdy/spdy_frame_builder.h" | 19 #include "net/spdy/spdy_frame_builder.h" |
| 19 #include "net/spdy/spdy_frame_reader.h" | 20 #include "net/spdy/spdy_frame_reader.h" |
| 20 #include "net/spdy/spdy_bitmasks.h" | 21 #include "net/spdy/spdy_bitmasks.h" |
| 21 #include "third_party/zlib/zlib.h" | 22 #include "third_party/zlib/zlib.h" |
| 22 | 23 |
| 23 using base::StringPiece; | 24 using base::StringPiece; |
| 24 using std::string; | 25 using std::string; |
| 25 using std::vector; | 26 using std::vector; |
| 26 | 27 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 SpdyFramer::SpdyFramer(SpdyMajorVersion version) | 165 SpdyFramer::SpdyFramer(SpdyMajorVersion version) |
| 165 : current_frame_buffer_(kControlFrameBufferSize), | 166 : current_frame_buffer_(kControlFrameBufferSize), |
| 166 expect_continuation_(0), | 167 expect_continuation_(0), |
| 167 visitor_(NULL), | 168 visitor_(NULL), |
| 168 debug_visitor_(NULL), | 169 debug_visitor_(NULL), |
| 169 display_protocol_("SPDY"), | 170 display_protocol_("SPDY"), |
| 170 protocol_version_(version), | 171 protocol_version_(version), |
| 171 enable_compression_(true), | 172 enable_compression_(true), |
| 172 syn_frame_processed_(false), | 173 syn_frame_processed_(false), |
| 173 probable_http_response_(false), | 174 probable_http_response_(false), |
| 174 end_stream_when_done_(false) { | 175 end_stream_when_done_(false), |
| 176 spdy_on_stream_end_(FLAGS_spdy_on_stream_end) { |
| 175 DCHECK(protocol_version_ == SPDY3 || protocol_version_ == HTTP2); | 177 DCHECK(protocol_version_ == SPDY3 || protocol_version_ == HTTP2); |
| 176 DCHECK_LE(kMaxControlFrameSize, | 178 DCHECK_LE(kMaxControlFrameSize, |
| 177 SpdyConstants::GetFrameMaximumSize(protocol_version_) + | 179 SpdyConstants::GetFrameMaximumSize(protocol_version_) + |
| 178 SpdyConstants::GetControlFrameHeaderSize(protocol_version_)); | 180 SpdyConstants::GetControlFrameHeaderSize(protocol_version_)); |
| 179 Reset(); | 181 Reset(); |
| 180 } | 182 } |
| 181 | 183 |
| 182 SpdyFramer::~SpdyFramer() { | 184 SpdyFramer::~SpdyFramer() { |
| 183 if (header_compressor_.get()) { | 185 if (header_compressor_.get()) { |
| 184 deflateEnd(header_compressor_.get()); | 186 deflateEnd(header_compressor_.get()); |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 set_error(SPDY_INVALID_DATA_FRAME_FLAGS); | 825 set_error(SPDY_INVALID_DATA_FRAME_FLAGS); |
| 824 } else { | 826 } else { |
| 825 visitor_->OnDataFrameHeader(current_frame_stream_id_, | 827 visitor_->OnDataFrameHeader(current_frame_stream_id_, |
| 826 remaining_data_length_, | 828 remaining_data_length_, |
| 827 current_frame_flags_ & DATA_FLAG_FIN); | 829 current_frame_flags_ & DATA_FLAG_FIN); |
| 828 if (remaining_data_length_ > 0) { | 830 if (remaining_data_length_ > 0) { |
| 829 CHANGE_STATE(SPDY_READ_DATA_FRAME_PADDING_LENGTH); | 831 CHANGE_STATE(SPDY_READ_DATA_FRAME_PADDING_LENGTH); |
| 830 } else { | 832 } else { |
| 831 // Empty data frame. | 833 // Empty data frame. |
| 832 if (current_frame_flags_ & DATA_FLAG_FIN) { | 834 if (current_frame_flags_ & DATA_FLAG_FIN) { |
| 833 visitor_->OnStreamFrameData( | 835 if (spdy_on_stream_end_) { |
| 834 current_frame_stream_id_, NULL, 0, true); | 836 visitor_->OnStreamEnd(current_frame_stream_id_); |
| 837 } else { |
| 838 visitor_->OnStreamFrameData(current_frame_stream_id_, nullptr, 0, |
| 839 true); |
| 840 } |
| 835 } | 841 } |
| 836 CHANGE_STATE(SPDY_FRAME_COMPLETE); | 842 CHANGE_STATE(SPDY_FRAME_COMPLETE); |
| 837 } | 843 } |
| 838 } | 844 } |
| 839 } else { | 845 } else { |
| 840 ProcessControlFrameHeader(control_frame_type_field); | 846 ProcessControlFrameHeader(control_frame_type_field); |
| 841 } | 847 } |
| 842 | 848 |
| 843 return original_len - len; | 849 return original_len - len; |
| 844 } | 850 } |
| (...skipping 1258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2103 remaining_data_length_ -= amount_to_discard; | 2109 remaining_data_length_ -= amount_to_discard; |
| 2104 } | 2110 } |
| 2105 | 2111 |
| 2106 if (remaining_data_length_ == 0) { | 2112 if (remaining_data_length_ == 0) { |
| 2107 // If the FIN flag is set, or this ends a header block which set FIN, | 2113 // If the FIN flag is set, or this ends a header block which set FIN, |
| 2108 // inform the visitor of EOF via a 0-length data frame. | 2114 // inform the visitor of EOF via a 0-length data frame. |
| 2109 if (expect_continuation_ == 0 && | 2115 if (expect_continuation_ == 0 && |
| 2110 ((current_frame_flags_ & CONTROL_FLAG_FIN) != 0 || | 2116 ((current_frame_flags_ & CONTROL_FLAG_FIN) != 0 || |
| 2111 end_stream_when_done_)) { | 2117 end_stream_when_done_)) { |
| 2112 end_stream_when_done_ = false; | 2118 end_stream_when_done_ = false; |
| 2113 visitor_->OnStreamFrameData(current_frame_stream_id_, NULL, 0, true); | 2119 if (spdy_on_stream_end_) { |
| 2120 visitor_->OnStreamEnd(current_frame_stream_id_); |
| 2121 } else { |
| 2122 visitor_->OnStreamFrameData(current_frame_stream_id_, nullptr, 0, true); |
| 2123 } |
| 2114 } | 2124 } |
| 2115 CHANGE_STATE(SPDY_FRAME_COMPLETE); | 2125 CHANGE_STATE(SPDY_FRAME_COMPLETE); |
| 2116 } | 2126 } |
| 2117 return original_len - len; | 2127 return original_len - len; |
| 2118 } | 2128 } |
| 2119 | 2129 |
| 2120 size_t SpdyFramer::ProcessDataFramePayload(const char* data, size_t len) { | 2130 size_t SpdyFramer::ProcessDataFramePayload(const char* data, size_t len) { |
| 2121 size_t original_len = len; | 2131 size_t original_len = len; |
| 2122 if (remaining_data_length_ - remaining_padding_payload_length_ > 0) { | 2132 if (remaining_data_length_ - remaining_padding_payload_length_ > 0) { |
| 2123 size_t amount_to_forward = std::min( | 2133 size_t amount_to_forward = std::min( |
| (...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3137 #else | 3147 #else |
| 3138 WriteHeaderBlockToZ(&frame.header_block(), compressor); | 3148 WriteHeaderBlockToZ(&frame.header_block(), compressor); |
| 3139 #endif // defined(USE_SYSTEM_ZLIB) | 3149 #endif // defined(USE_SYSTEM_ZLIB) |
| 3140 | 3150 |
| 3141 int compressed_size = compressed_max_size - compressor->avail_out; | 3151 int compressed_size = compressed_max_size - compressor->avail_out; |
| 3142 builder->Seek(compressed_size); | 3152 builder->Seek(compressed_size); |
| 3143 builder->RewriteLength(*this); | 3153 builder->RewriteLength(*this); |
| 3144 } | 3154 } |
| 3145 | 3155 |
| 3146 } // namespace net | 3156 } // namespace net |
| OLD | NEW |