| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_headers_block_parser.h" | 5 #include "net/spdy/spdy_headers_block_parser.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 // Encode the value as SPDY header. | 74 // Encode the value as SPDY header. |
| 75 headers += EncodeLength(value.length()); | 75 headers += EncodeLength(value.length()); |
| 76 headers += value; | 76 headers += value; |
| 77 } | 77 } |
| 78 return headers; | 78 return headers; |
| 79 } | 79 } |
| 80 | 80 |
| 81 string EncodeLength(uint32_t len) { | 81 string EncodeLength(uint32_t len) { |
| 82 char buffer[4]; | 82 char buffer[4]; |
| 83 if (length_field_size_ == sizeof(uint32_t)) { | 83 if (length_field_size_ == sizeof(uint32_t)) { |
| 84 uint32_t net_order_len = htonl(len); | 84 uint32_t net_order_len = base::HostToNet32(len); |
| 85 memcpy(buffer, &net_order_len, length_field_size_); | 85 memcpy(buffer, &net_order_len, length_field_size_); |
| 86 } else if (length_field_size_ == sizeof(uint16_t)) { | 86 } else if (length_field_size_ == sizeof(uint16_t)) { |
| 87 uint16_t net_order_len = htons(len); | 87 uint16_t net_order_len = base::HostToNet16(static_cast<uint16_t>(len)); |
| 88 memcpy(buffer, &net_order_len, length_field_size_); | 88 memcpy(buffer, &net_order_len, length_field_size_); |
| 89 } else { | 89 } else { |
| 90 CHECK(false) << "Invalid length field size"; | 90 CHECK(false) << "Invalid length field size"; |
| 91 } | 91 } |
| 92 return string(buffer, length_field_size_); | 92 return string(buffer, length_field_size_); |
| 93 } | 93 } |
| 94 | 94 |
| 95 size_t length_field_size_; | 95 size_t length_field_size_; |
| 96 SpdyMajorVersion spdy_version_; | 96 SpdyMajorVersion spdy_version_; |
| 97 | 97 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 string headers(CreateHeaders(kNumHeadersInBlock, false)); | 269 string headers(CreateHeaders(kNumHeadersInBlock, false)); |
| 270 bool result; | 270 bool result; |
| 271 EXPECT_DFATAL( | 271 EXPECT_DFATAL( |
| 272 result = parser_->HandleControlFrameHeadersData(0, headers.data(), 1), | 272 result = parser_->HandleControlFrameHeadersData(0, headers.data(), 1), |
| 273 "Expected nonzero stream id, saw: 0"); | 273 "Expected nonzero stream id, saw: 0"); |
| 274 EXPECT_FALSE(result); | 274 EXPECT_FALSE(result); |
| 275 EXPECT_EQ(SpdyHeadersBlockParser::UNEXPECTED_STREAM_ID, parser_->get_error()); | 275 EXPECT_EQ(SpdyHeadersBlockParser::UNEXPECTED_STREAM_ID, parser_->get_error()); |
| 276 } | 276 } |
| 277 | 277 |
| 278 } // namespace net | 278 } // namespace net |
| OLD | NEW |