Chromium Code Reviews| 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 <cctype> | 10 #include <cctype> |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 case SPDY_INVALID_CONTROL_FRAME_FLAGS: | 396 case SPDY_INVALID_CONTROL_FRAME_FLAGS: |
| 397 return "SPDY_INVALID_CONTROL_FRAME_FLAGS"; | 397 return "SPDY_INVALID_CONTROL_FRAME_FLAGS"; |
| 398 case SPDY_UNEXPECTED_FRAME: | 398 case SPDY_UNEXPECTED_FRAME: |
| 399 return "UNEXPECTED_FRAME"; | 399 return "UNEXPECTED_FRAME"; |
| 400 case SPDY_INTERNAL_FRAMER_ERROR: | 400 case SPDY_INTERNAL_FRAMER_ERROR: |
| 401 return "SPDY_INTERNAL_FRAMER_ERROR"; | 401 return "SPDY_INTERNAL_FRAMER_ERROR"; |
| 402 } | 402 } |
| 403 return "UNKNOWN_ERROR"; | 403 return "UNKNOWN_ERROR"; |
| 404 } | 404 } |
| 405 | 405 |
| 406 const char* SpdyFramer::StatusCodeToString(int status_code) { | 406 const char* SpdyFramer::StatusCodeToString(int status_code) { |
|
Bence
2017/02/02 15:12:25
This method is removed in server change 145087791,
diannahu
2017/02/02 15:58:09
Got it, will do! (I was wondering why I didn't see
| |
| 407 switch (status_code) { | 407 switch (status_code) { |
| 408 case RST_STREAM_NO_ERROR: | 408 case ERROR_CODE_NO_ERROR: |
| 409 return "NO_ERROR"; | 409 return "NO_ERROR"; |
| 410 case RST_STREAM_PROTOCOL_ERROR: | 410 case ERROR_CODE_PROTOCOL_ERROR: |
| 411 return "PROTOCOL_ERROR"; | 411 return "PROTOCOL_ERROR"; |
| 412 case RST_STREAM_INTERNAL_ERROR: | 412 case ERROR_CODE_INTERNAL_ERROR: |
| 413 return "INTERNAL_ERROR"; | 413 return "INTERNAL_ERROR"; |
| 414 case RST_STREAM_FLOW_CONTROL_ERROR: | 414 case ERROR_CODE_FLOW_CONTROL_ERROR: |
| 415 return "FLOW_CONTROL_ERROR"; | 415 return "FLOW_CONTROL_ERROR"; |
| 416 case RST_STREAM_SETTINGS_TIMEOUT: | 416 case ERROR_CODE_SETTINGS_TIMEOUT: |
| 417 return "SETTINGS_TIMEOUT"; | 417 return "SETTINGS_TIMEOUT"; |
| 418 case RST_STREAM_STREAM_CLOSED: | 418 case ERROR_CODE_STREAM_CLOSED: |
| 419 return "STREAM_CLOSED"; | 419 return "STREAM_CLOSED"; |
| 420 case RST_STREAM_FRAME_SIZE_ERROR: | 420 case ERROR_CODE_FRAME_SIZE_ERROR: |
| 421 return "FRAME_SIZE_ERROR"; | 421 return "FRAME_SIZE_ERROR"; |
| 422 case RST_STREAM_REFUSED_STREAM: | 422 case ERROR_CODE_REFUSED_STREAM: |
| 423 return "REFUSED_STREAM"; | 423 return "REFUSED_STREAM"; |
| 424 case RST_STREAM_CANCEL: | 424 case ERROR_CODE_CANCEL: |
| 425 return "CANCEL"; | 425 return "CANCEL"; |
| 426 case RST_STREAM_COMPRESSION_ERROR: | 426 case ERROR_CODE_COMPRESSION_ERROR: |
| 427 return "COMPRESSION_ERROR"; | 427 return "COMPRESSION_ERROR"; |
| 428 case RST_STREAM_CONNECT_ERROR: | 428 case ERROR_CODE_CONNECT_ERROR: |
| 429 return "CONNECT_ERROR"; | 429 return "CONNECT_ERROR"; |
| 430 case RST_STREAM_ENHANCE_YOUR_CALM: | 430 case ERROR_CODE_ENHANCE_YOUR_CALM: |
| 431 return "ENHANCE_YOUR_CALM"; | 431 return "ENHANCE_YOUR_CALM"; |
| 432 case RST_STREAM_INADEQUATE_SECURITY: | 432 case ERROR_CODE_INADEQUATE_SECURITY: |
| 433 return "INADEQUATE_SECURITY"; | 433 return "INADEQUATE_SECURITY"; |
| 434 case RST_STREAM_HTTP_1_1_REQUIRED: | 434 case ERROR_CODE_HTTP_1_1_REQUIRED: |
| 435 return "HTTP_1_1_REQUIRED"; | 435 return "HTTP_1_1_REQUIRED"; |
| 436 } | 436 } |
| 437 return "UNKNOWN_STATUS"; | 437 return "UNKNOWN_STATUS"; |
| 438 } | 438 } |
| 439 | 439 |
| 440 const char* SpdyFramer::FrameTypeToString(SpdyFrameType type) { | 440 const char* SpdyFramer::FrameTypeToString(SpdyFrameType type) { |
| 441 switch (type) { | 441 switch (type) { |
| 442 case DATA: | 442 case DATA: |
| 443 return "DATA"; | 443 return "DATA"; |
| 444 case RST_STREAM: | 444 case RST_STREAM: |
| (...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1349 remaining_data_length_); | 1349 remaining_data_length_); |
| 1350 remaining_data_length_ -= bytes_read; | 1350 remaining_data_length_ -= bytes_read; |
| 1351 if (remaining_data_length_ == 0) { | 1351 if (remaining_data_length_ == 0) { |
| 1352 SpdyFrameReader reader(current_frame_buffer_.data(), | 1352 SpdyFrameReader reader(current_frame_buffer_.data(), |
| 1353 current_frame_buffer_.len()); | 1353 current_frame_buffer_.len()); |
| 1354 reader.Seek(GetFrameHeaderSize()); // Skip frame header. | 1354 reader.Seek(GetFrameHeaderSize()); // Skip frame header. |
| 1355 | 1355 |
| 1356 // Use frame-specific handlers. | 1356 // Use frame-specific handlers. |
| 1357 switch (current_frame_type_) { | 1357 switch (current_frame_type_) { |
| 1358 case RST_STREAM: { | 1358 case RST_STREAM: { |
| 1359 uint32_t status_raw = RST_STREAM_NO_ERROR; | 1359 uint32_t error_code = ERROR_CODE_NO_ERROR; |
| 1360 bool successful_read = reader.ReadUInt32(&status_raw); | 1360 bool successful_read = reader.ReadUInt32(&error_code); |
| 1361 DCHECK(successful_read); | 1361 DCHECK(successful_read); |
| 1362 DCHECK(reader.IsDoneReading()); | 1362 DCHECK(reader.IsDoneReading()); |
| 1363 SpdyRstStreamStatus status = ParseRstStreamStatus(status_raw); | 1363 visitor_->OnRstStream(current_frame_stream_id_, |
| 1364 visitor_->OnRstStream(current_frame_stream_id_, status); | 1364 ParseErrorCode(error_code)); |
| 1365 } break; | 1365 } break; |
| 1366 case PING: { | 1366 case PING: { |
| 1367 SpdyPingId id = 0; | 1367 SpdyPingId id = 0; |
| 1368 bool is_ack = current_frame_flags_ & PING_FLAG_ACK; | 1368 bool is_ack = current_frame_flags_ & PING_FLAG_ACK; |
| 1369 bool successful_read = true; | 1369 bool successful_read = true; |
| 1370 successful_read = reader.ReadUInt64(&id); | 1370 successful_read = reader.ReadUInt64(&id); |
| 1371 DCHECK(successful_read); | 1371 DCHECK(successful_read); |
| 1372 DCHECK(reader.IsDoneReading()); | 1372 DCHECK(reader.IsDoneReading()); |
| 1373 visitor_->OnPing(id, is_ack); | 1373 visitor_->OnPing(id, is_ack); |
| 1374 } break; | 1374 } break; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1434 // Do we have enough to parse the constant size GOAWAY header? | 1434 // Do we have enough to parse the constant size GOAWAY header? |
| 1435 if (current_frame_buffer_.len() == header_size) { | 1435 if (current_frame_buffer_.len() == header_size) { |
| 1436 // Parse out the last good stream id. | 1436 // Parse out the last good stream id. |
| 1437 SpdyFrameReader reader(current_frame_buffer_.data(), | 1437 SpdyFrameReader reader(current_frame_buffer_.data(), |
| 1438 current_frame_buffer_.len()); | 1438 current_frame_buffer_.len()); |
| 1439 reader.Seek(GetFrameHeaderSize()); // Seek past frame header. | 1439 reader.Seek(GetFrameHeaderSize()); // Seek past frame header. |
| 1440 bool successful_read = reader.ReadUInt31(¤t_frame_stream_id_); | 1440 bool successful_read = reader.ReadUInt31(¤t_frame_stream_id_); |
| 1441 DCHECK(successful_read); | 1441 DCHECK(successful_read); |
| 1442 | 1442 |
| 1443 // Parse status code. | 1443 // Parse status code. |
| 1444 uint32_t status_raw = GOAWAY_NO_ERROR; | 1444 uint32_t error_code = ERROR_CODE_NO_ERROR; |
| 1445 successful_read = reader.ReadUInt32(&status_raw); | 1445 successful_read = reader.ReadUInt32(&error_code); |
| 1446 DCHECK(successful_read); | 1446 DCHECK(successful_read); |
| 1447 SpdyGoAwayStatus status = ParseGoAwayStatus(status_raw); | |
| 1448 // Finished parsing the GOAWAY header, call frame handler. | 1447 // Finished parsing the GOAWAY header, call frame handler. |
| 1449 visitor_->OnGoAway(current_frame_stream_id_, status); | 1448 visitor_->OnGoAway(current_frame_stream_id_, ParseErrorCode(error_code)); |
| 1450 } | 1449 } |
| 1451 } | 1450 } |
| 1452 | 1451 |
| 1453 // Handle remaining data as opaque. | 1452 // Handle remaining data as opaque. |
| 1454 bool processed_successfully = true; | 1453 bool processed_successfully = true; |
| 1455 if (len > 0) { | 1454 if (len > 0) { |
| 1456 processed_successfully = visitor_->OnGoAwayFrameData(data, len); | 1455 processed_successfully = visitor_->OnGoAwayFrameData(data, len); |
| 1457 } | 1456 } |
| 1458 remaining_data_length_ -= original_len; | 1457 remaining_data_length_ -= original_len; |
| 1459 if (!processed_successfully) { | 1458 if (!processed_successfully) { |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1791 return builder.take(); | 1790 return builder.take(); |
| 1792 } | 1791 } |
| 1793 | 1792 |
| 1794 SpdySerializedFrame SpdyFramer::SerializeRstStream( | 1793 SpdySerializedFrame SpdyFramer::SerializeRstStream( |
| 1795 const SpdyRstStreamIR& rst_stream) const { | 1794 const SpdyRstStreamIR& rst_stream) const { |
| 1796 size_t expected_length = GetRstStreamSize(); | 1795 size_t expected_length = GetRstStreamSize(); |
| 1797 SpdyFrameBuilder builder(expected_length); | 1796 SpdyFrameBuilder builder(expected_length); |
| 1798 | 1797 |
| 1799 builder.BeginNewFrame(*this, RST_STREAM, 0, rst_stream.stream_id()); | 1798 builder.BeginNewFrame(*this, RST_STREAM, 0, rst_stream.stream_id()); |
| 1800 | 1799 |
| 1801 builder.WriteUInt32(rst_stream.status()); | 1800 builder.WriteUInt32(rst_stream.error_code()); |
| 1802 | 1801 |
| 1803 DCHECK_EQ(expected_length, builder.length()); | 1802 DCHECK_EQ(expected_length, builder.length()); |
| 1804 return builder.take(); | 1803 return builder.take(); |
| 1805 } | 1804 } |
| 1806 | 1805 |
| 1807 SpdySerializedFrame SpdyFramer::SerializeSettings( | 1806 SpdySerializedFrame SpdyFramer::SerializeSettings( |
| 1808 const SpdySettingsIR& settings) const { | 1807 const SpdySettingsIR& settings) const { |
| 1809 uint8_t flags = 0; | 1808 uint8_t flags = 0; |
| 1810 | 1809 |
| 1811 if (settings.is_ack()) { | 1810 if (settings.is_ack()) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1855 size_t expected_length = GetGoAwayMinimumSize(); | 1854 size_t expected_length = GetGoAwayMinimumSize(); |
| 1856 expected_length += goaway.description().size(); | 1855 expected_length += goaway.description().size(); |
| 1857 SpdyFrameBuilder builder(expected_length); | 1856 SpdyFrameBuilder builder(expected_length); |
| 1858 | 1857 |
| 1859 // Serialize the GOAWAY frame. | 1858 // Serialize the GOAWAY frame. |
| 1860 builder.BeginNewFrame(*this, GOAWAY, 0, 0); | 1859 builder.BeginNewFrame(*this, GOAWAY, 0, 0); |
| 1861 | 1860 |
| 1862 // GOAWAY frames specify the last good stream id. | 1861 // GOAWAY frames specify the last good stream id. |
| 1863 builder.WriteUInt32(goaway.last_good_stream_id()); | 1862 builder.WriteUInt32(goaway.last_good_stream_id()); |
| 1864 | 1863 |
| 1865 // GOAWAY frames also specify the error status code. | 1864 // GOAWAY frames also specify the error code. |
| 1866 builder.WriteUInt32(goaway.status()); | 1865 builder.WriteUInt32(goaway.error_code()); |
| 1867 | 1866 |
| 1868 // GOAWAY frames may also specify opaque data. | 1867 // GOAWAY frames may also specify opaque data. |
| 1869 if (!goaway.description().empty()) { | 1868 if (!goaway.description().empty()) { |
| 1870 builder.WriteBytes(goaway.description().data(), | 1869 builder.WriteBytes(goaway.description().data(), |
| 1871 goaway.description().size()); | 1870 goaway.description().size()); |
| 1872 } | 1871 } |
| 1873 | 1872 |
| 1874 DCHECK_EQ(expected_length, builder.length()); | 1873 DCHECK_EQ(expected_length, builder.length()); |
| 1875 return builder.take(); | 1874 return builder.take(); |
| 1876 } | 1875 } |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2434 builder->WriteUInt32(header_block.size()); | 2433 builder->WriteUInt32(header_block.size()); |
| 2435 | 2434 |
| 2436 // Serialize each header. | 2435 // Serialize each header. |
| 2437 for (const auto& header : header_block) { | 2436 for (const auto& header : header_block) { |
| 2438 builder->WriteStringPiece32(base::ToLowerASCII(header.first)); | 2437 builder->WriteStringPiece32(base::ToLowerASCII(header.first)); |
| 2439 builder->WriteStringPiece32(header.second); | 2438 builder->WriteStringPiece32(header.second); |
| 2440 } | 2439 } |
| 2441 } | 2440 } |
| 2442 | 2441 |
| 2443 } // namespace net | 2442 } // namespace net |
| OLD | NEW |