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> |
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 } | 946 } |
947 break; | 947 break; |
948 case SYN_REPLY: | 948 case SYN_REPLY: |
949 if (current_frame_length_ < GetSynReplyMinimumSize()) { | 949 if (current_frame_length_ < GetSynReplyMinimumSize()) { |
950 set_error(SPDY_INVALID_CONTROL_FRAME); | 950 set_error(SPDY_INVALID_CONTROL_FRAME); |
951 } else if (current_frame_flags_ & ~CONTROL_FLAG_FIN) { | 951 } else if (current_frame_flags_ & ~CONTROL_FLAG_FIN) { |
952 set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS); | 952 set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS); |
953 } | 953 } |
954 break; | 954 break; |
955 case RST_STREAM: | 955 case RST_STREAM: |
956 // For SPDY versions < 4, the header has a fixed length. | 956 // TODO(bnc): Enforce the length of the header, and change error to |
957 // For SPDY version 4 and up, the RST_STREAM frame may include optional | 957 // FRAME_SIZE_ERROR. |
958 // opaque data, so we only have a lower limit on the frame size. | |
959 if ((current_frame_length_ != GetRstStreamMinimumSize() && | 958 if ((current_frame_length_ != GetRstStreamMinimumSize() && |
960 protocol_version() <= SPDY3) || | 959 protocol_version() <= SPDY3) || |
961 (current_frame_length_ < GetRstStreamMinimumSize() && | 960 (current_frame_length_ < GetRstStreamMinimumSize() && |
962 protocol_version() > SPDY3)) { | 961 protocol_version() > SPDY3)) { |
963 set_error(SPDY_INVALID_CONTROL_FRAME); | 962 set_error(SPDY_INVALID_CONTROL_FRAME); |
964 } else if (current_frame_flags_ != 0) { | 963 } else if (current_frame_flags_ != 0) { |
965 set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS); | 964 set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS); |
966 } | 965 } |
967 break; | 966 break; |
968 case SETTINGS: | 967 case SETTINGS: |
(...skipping 1466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2435 } | 2434 } |
2436 | 2435 |
2437 SpdySerializedFrame* SpdyFramer::SerializeRstStream( | 2436 SpdySerializedFrame* SpdyFramer::SerializeRstStream( |
2438 const SpdyRstStreamIR& rst_stream) const { | 2437 const SpdyRstStreamIR& rst_stream) const { |
2439 // TODO(jgraettinger): For now, Chromium will support parsing RST_STREAM | 2438 // TODO(jgraettinger): For now, Chromium will support parsing RST_STREAM |
2440 // payloads, but will not emit them. SPDY4 is used for draft HTTP/2, | 2439 // payloads, but will not emit them. SPDY4 is used for draft HTTP/2, |
2441 // which doesn't currently include RST_STREAM payloads. GFE flags have been | 2440 // which doesn't currently include RST_STREAM payloads. GFE flags have been |
2442 // commented but left in place to simplify future patching. | 2441 // commented but left in place to simplify future patching. |
2443 // Compute the output buffer size, taking opaque data into account. | 2442 // Compute the output buffer size, taking opaque data into account. |
2444 size_t expected_length = GetRstStreamMinimumSize(); | 2443 size_t expected_length = GetRstStreamMinimumSize(); |
2445 if (protocol_version() > SPDY3) { | |
2446 expected_length += rst_stream.description().size(); | |
2447 } | |
2448 SpdyFrameBuilder builder(expected_length, protocol_version()); | 2444 SpdyFrameBuilder builder(expected_length, protocol_version()); |
2449 | 2445 |
2450 // Serialize the RST_STREAM frame. | 2446 // Serialize the RST_STREAM frame. |
2451 if (protocol_version() <= SPDY3) { | 2447 if (protocol_version() <= SPDY3) { |
2452 builder.WriteControlFrameHeader(*this, RST_STREAM, 0); | 2448 builder.WriteControlFrameHeader(*this, RST_STREAM, 0); |
2453 builder.WriteUInt32(rst_stream.stream_id()); | 2449 builder.WriteUInt32(rst_stream.stream_id()); |
2454 } else { | 2450 } else { |
2455 builder.BeginNewFrame(*this, RST_STREAM, 0, rst_stream.stream_id()); | 2451 builder.BeginNewFrame(*this, RST_STREAM, 0, rst_stream.stream_id()); |
2456 } | 2452 } |
2457 | 2453 |
2458 builder.WriteUInt32(SpdyConstants::SerializeRstStreamStatus( | 2454 builder.WriteUInt32(SpdyConstants::SerializeRstStreamStatus( |
2459 protocol_version(), rst_stream.status())); | 2455 protocol_version(), rst_stream.status())); |
2460 | 2456 |
2461 // In HTTP2 and up, RST_STREAM frames may also specify opaque data. | |
2462 if (protocol_version() > SPDY3 && rst_stream.description().size() > 0) { | |
2463 builder.WriteBytes(rst_stream.description().data(), | |
2464 rst_stream.description().size()); | |
2465 } | |
2466 | |
2467 DCHECK_EQ(expected_length, builder.length()); | 2457 DCHECK_EQ(expected_length, builder.length()); |
2468 return builder.take(); | 2458 return builder.take(); |
2469 } | 2459 } |
2470 | 2460 |
2471 SpdySerializedFrame* SpdyFramer::SerializeSettings( | 2461 SpdySerializedFrame* SpdyFramer::SerializeSettings( |
2472 const SpdySettingsIR& settings) const { | 2462 const SpdySettingsIR& settings) const { |
2473 uint8 flags = 0; | 2463 uint8 flags = 0; |
2474 | 2464 |
2475 if (protocol_version() <= SPDY3) { | 2465 if (protocol_version() <= SPDY3) { |
2476 if (settings.clear_settings()) { | 2466 if (settings.clear_settings()) { |
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3250 #else | 3240 #else |
3251 WriteHeaderBlockToZ(&frame.header_block(), compressor); | 3241 WriteHeaderBlockToZ(&frame.header_block(), compressor); |
3252 #endif // defined(USE_SYSTEM_ZLIB) | 3242 #endif // defined(USE_SYSTEM_ZLIB) |
3253 | 3243 |
3254 int compressed_size = compressed_max_size - compressor->avail_out; | 3244 int compressed_size = compressed_max_size - compressor->avail_out; |
3255 builder->Seek(compressed_size); | 3245 builder->Seek(compressed_size); |
3256 builder->RewriteLength(*this); | 3246 builder->RewriteLength(*this); |
3257 } | 3247 } |
3258 | 3248 |
3259 } // namespace net | 3249 } // namespace net |
OLD | NEW |