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 "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 2398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2409 SYN_STREAM, | 2409 SYN_STREAM, |
2410 payload_len, | 2410 payload_len, |
2411 builder.length()); | 2411 builder.length()); |
2412 } | 2412 } |
2413 | 2413 |
2414 return builder.take(); | 2414 return builder.take(); |
2415 } | 2415 } |
2416 | 2416 |
2417 SpdySerializedFrame* SpdyFramer::SerializeSynReply( | 2417 SpdySerializedFrame* SpdyFramer::SerializeSynReply( |
2418 const SpdySynReplyIR& syn_reply) { | 2418 const SpdySynReplyIR& syn_reply) { |
| 2419 DCHECK_GE(SPDY3, protocol_version()); |
2419 uint8 flags = 0; | 2420 uint8 flags = 0; |
2420 if (syn_reply.fin()) { | 2421 if (syn_reply.fin()) { |
2421 flags |= CONTROL_FLAG_FIN; | 2422 flags |= CONTROL_FLAG_FIN; |
2422 } | 2423 } |
2423 // In SPDY >= 4, SYN_REPLY frames are HEADERS frames, but for now | |
2424 // we never expect to have to overflow into a CONTINUATION frame. | |
2425 if (protocol_version() > SPDY3) { | |
2426 flags |= HEADERS_FLAG_END_HEADERS; | |
2427 } | |
2428 | 2424 |
2429 // The size of this frame, including variable-length name-value block. | 2425 // The size of this frame, including variable-length name-value block. |
2430 size_t size = GetSynReplyMinimumSize(); | 2426 const size_t size = GetSynReplyMinimumSize() + |
2431 | 2427 GetSerializedLength(syn_reply.name_value_block()); |
2432 string hpack_encoding; | |
2433 if (protocol_version() > SPDY3) { | |
2434 if (enable_compression_) { | |
2435 GetHpackEncoder()->EncodeHeaderSet( | |
2436 syn_reply.name_value_block(), &hpack_encoding); | |
2437 } else { | |
2438 GetHpackEncoder()->EncodeHeaderSetWithoutCompression( | |
2439 syn_reply.name_value_block(), &hpack_encoding); | |
2440 } | |
2441 size += hpack_encoding.size(); | |
2442 } else { | |
2443 size += GetSerializedLength(syn_reply.name_value_block()); | |
2444 } | |
2445 | 2428 |
2446 SpdyFrameBuilder builder(size, protocol_version()); | 2429 SpdyFrameBuilder builder(size, protocol_version()); |
2447 if (protocol_version() <= SPDY3) { | 2430 if (protocol_version() <= SPDY3) { |
2448 builder.WriteControlFrameHeader(*this, SYN_REPLY, flags); | 2431 builder.WriteControlFrameHeader(*this, SYN_REPLY, flags); |
2449 builder.WriteUInt32(syn_reply.stream_id()); | 2432 builder.WriteUInt32(syn_reply.stream_id()); |
2450 } else { | 2433 } else { |
2451 builder.BeginNewFrame(*this, | 2434 builder.BeginNewFrame(*this, |
2452 HEADERS, | 2435 HEADERS, |
2453 flags, | 2436 flags, |
2454 syn_reply.stream_id()); | 2437 syn_reply.stream_id()); |
2455 } | 2438 } |
2456 if (protocol_version() < SPDY3) { | 2439 if (protocol_version() < SPDY3) { |
2457 builder.WriteUInt16(0); // Unused. | 2440 builder.WriteUInt16(0); // Unused. |
2458 } | 2441 } |
2459 DCHECK_EQ(GetSynReplyMinimumSize(), builder.length()); | 2442 DCHECK_EQ(GetSynReplyMinimumSize(), builder.length()); |
2460 if (protocol_version() > SPDY3) { | 2443 SerializeNameValueBlock(&builder, syn_reply); |
2461 builder.WriteBytes(&hpack_encoding[0], hpack_encoding.size()); | |
2462 } else { | |
2463 SerializeNameValueBlock(&builder, syn_reply); | |
2464 } | |
2465 | 2444 |
2466 if (debug_visitor_) { | 2445 if (debug_visitor_) { |
2467 const size_t payload_len = protocol_version() > SPDY3 ? | 2446 const size_t payload_len = GetSerializedLength( |
2468 hpack_encoding.size() : | 2447 protocol_version(), &(syn_reply.name_value_block())); |
2469 GetSerializedLength(protocol_version(), | |
2470 &(syn_reply.name_value_block())); | |
2471 debug_visitor_->OnSendCompressedFrame(syn_reply.stream_id(), | 2448 debug_visitor_->OnSendCompressedFrame(syn_reply.stream_id(), |
2472 SYN_REPLY, | 2449 SYN_REPLY, |
2473 payload_len, | 2450 payload_len, |
2474 builder.length()); | 2451 builder.length()); |
2475 } | 2452 } |
2476 | 2453 |
2477 return builder.take(); | 2454 return builder.take(); |
2478 } | 2455 } |
2479 | 2456 |
2480 SpdySerializedFrame* SpdyFramer::SerializeRstStream( | 2457 SpdySerializedFrame* SpdyFramer::SerializeRstStream( |
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3262 builder->Seek(compressed_size); | 3239 builder->Seek(compressed_size); |
3263 builder->RewriteLength(*this); | 3240 builder->RewriteLength(*this); |
3264 | 3241 |
3265 pre_compress_bytes.Add(uncompressed_len); | 3242 pre_compress_bytes.Add(uncompressed_len); |
3266 post_compress_bytes.Add(compressed_size); | 3243 post_compress_bytes.Add(compressed_size); |
3267 | 3244 |
3268 compressed_frames.Increment(); | 3245 compressed_frames.Increment(); |
3269 } | 3246 } |
3270 | 3247 |
3271 } // namespace net | 3248 } // namespace net |
OLD | NEW |