| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/quic/core/spdy_utils.h" | 5 #include "net/quic/core/spdy_utils.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "net/quic/platform/api/quic_logging.h" | 10 #include "net/quic/platform/api/quic_logging.h" |
| 11 #include "net/quic/platform/api/quic_map_util.h" | 11 #include "net/quic/platform/api/quic_map_util.h" |
| 12 #include "net/quic/platform/api/quic_string_piece.h" |
| 12 #include "net/quic/platform/api/quic_text_utils.h" | 13 #include "net/quic/platform/api/quic_text_utils.h" |
| 13 #include "net/quic/platform/api/quic_url_utils.h" | 14 #include "net/quic/platform/api/quic_url_utils.h" |
| 14 #include "net/spdy/spdy_flags.h" | 15 #include "net/spdy/spdy_flags.h" |
| 15 #include "net/spdy/spdy_frame_builder.h" | 16 #include "net/spdy/spdy_frame_builder.h" |
| 16 #include "net/spdy/spdy_framer.h" | 17 #include "net/spdy/spdy_framer.h" |
| 17 #include "net/spdy/spdy_protocol.h" | 18 #include "net/spdy/spdy_protocol.h" |
| 18 | 19 |
| 19 using base::StringPiece; | |
| 20 using std::string; | 20 using std::string; |
| 21 | 21 |
| 22 namespace net { | 22 namespace net { |
| 23 | 23 |
| 24 // static | 24 // static |
| 25 string SpdyUtils::SerializeUncompressedHeaders(const SpdyHeaderBlock& headers) { | 25 string SpdyUtils::SerializeUncompressedHeaders(const SpdyHeaderBlock& headers) { |
| 26 size_t length = SpdyFramer::GetSerializedLength(&headers); | 26 size_t length = SpdyFramer::GetSerializedLength(&headers); |
| 27 SpdyFrameBuilder builder(length); | 27 SpdyFrameBuilder builder(length); |
| 28 SpdyFramer framer(SpdyFramer::DISABLE_COMPRESSION); | 28 SpdyFramer framer(SpdyFramer::DISABLE_COMPRESSION); |
| 29 framer.SerializeHeaderBlockWithoutCompression(&builder, headers); | 29 framer.SerializeHeaderBlockWithoutCompression(&builder, headers); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 50 } | 50 } |
| 51 | 51 |
| 52 // static | 52 // static |
| 53 bool SpdyUtils::ExtractContentLengthFromHeaders(int64_t* content_length, | 53 bool SpdyUtils::ExtractContentLengthFromHeaders(int64_t* content_length, |
| 54 SpdyHeaderBlock* headers) { | 54 SpdyHeaderBlock* headers) { |
| 55 auto it = headers->find("content-length"); | 55 auto it = headers->find("content-length"); |
| 56 if (it == headers->end()) { | 56 if (it == headers->end()) { |
| 57 return false; | 57 return false; |
| 58 } else { | 58 } else { |
| 59 // Check whether multiple values are consistent. | 59 // Check whether multiple values are consistent. |
| 60 StringPiece content_length_header = it->second; | 60 QuicStringPiece content_length_header = it->second; |
| 61 std::vector<StringPiece> values = | 61 std::vector<QuicStringPiece> values = |
| 62 QuicTextUtils::Split(content_length_header, '\0'); | 62 QuicTextUtils::Split(content_length_header, '\0'); |
| 63 for (const StringPiece& value : values) { | 63 for (const QuicStringPiece& value : values) { |
| 64 uint64_t new_value; | 64 uint64_t new_value; |
| 65 if (!QuicTextUtils::StringToUint64(value, &new_value)) { | 65 if (!QuicTextUtils::StringToUint64(value, &new_value)) { |
| 66 QUIC_DLOG(ERROR) | 66 QUIC_DLOG(ERROR) |
| 67 << "Content length was either unparseable or negative."; | 67 << "Content length was either unparseable or negative."; |
| 68 return false; | 68 return false; |
| 69 } | 69 } |
| 70 if (*content_length < 0) { | 70 if (*content_length < 0) { |
| 71 *content_length = new_value; | 71 *content_length = new_value; |
| 72 continue; | 72 continue; |
| 73 } | 73 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 102 !QuicTextUtils::StringToSizeT(it->second, final_byte_offset)) { | 102 !QuicTextUtils::StringToSizeT(it->second, final_byte_offset)) { |
| 103 QUIC_DVLOG(1) << "Required key '" << kFinalOffsetHeaderKey | 103 QUIC_DVLOG(1) << "Required key '" << kFinalOffsetHeaderKey |
| 104 << "' not present"; | 104 << "' not present"; |
| 105 return false; | 105 return false; |
| 106 } | 106 } |
| 107 // The final offset header is no longer needed. | 107 // The final offset header is no longer needed. |
| 108 trailers->erase(it->first); | 108 trailers->erase(it->first); |
| 109 | 109 |
| 110 // Trailers must not have empty keys, and must not contain pseudo headers. | 110 // Trailers must not have empty keys, and must not contain pseudo headers. |
| 111 for (const auto& trailer : *trailers) { | 111 for (const auto& trailer : *trailers) { |
| 112 StringPiece key = trailer.first; | 112 QuicStringPiece key = trailer.first; |
| 113 StringPiece value = trailer.second; | 113 QuicStringPiece value = trailer.second; |
| 114 if (QuicTextUtils::StartsWith(key, ":")) { | 114 if (QuicTextUtils::StartsWith(key, ":")) { |
| 115 QUIC_DVLOG(1) << "Trailers must not contain pseudo-header: '" << key | 115 QUIC_DVLOG(1) << "Trailers must not contain pseudo-header: '" << key |
| 116 << "','" << value << "'."; | 116 << "','" << value << "'."; |
| 117 return false; | 117 return false; |
| 118 } | 118 } |
| 119 | 119 |
| 120 // TODO(rjshade): Check for other forbidden keys, following the HTTP/2 spec. | 120 // TODO(rjshade): Check for other forbidden keys, following the HTTP/2 spec. |
| 121 } | 121 } |
| 122 | 122 |
| 123 QUIC_DVLOG(1) << "Successfully parsed Trailers: " << trailers->DebugString(); | 123 QUIC_DVLOG(1) << "Successfully parsed Trailers: " << trailers->DebugString(); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 (*headers)[":authority"] = url.substr(start); | 252 (*headers)[":authority"] = url.substr(start); |
| 253 (*headers)[":path"] = "/"; | 253 (*headers)[":path"] = "/"; |
| 254 return true; | 254 return true; |
| 255 } | 255 } |
| 256 (*headers)[":authority"] = url.substr(start, pos - start); | 256 (*headers)[":authority"] = url.substr(start, pos - start); |
| 257 (*headers)[":path"] = url.substr(pos); | 257 (*headers)[":path"] = url.substr(pos); |
| 258 return true; | 258 return true; |
| 259 } | 259 } |
| 260 | 260 |
| 261 } // namespace net | 261 } // namespace net |
| OLD | NEW |