| 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 "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "net/spdy/spdy_flags.h" | 15 #include "net/spdy/spdy_flags.h" |
| 16 #include "net/spdy/spdy_frame_builder.h" | 16 #include "net/spdy/spdy_frame_builder.h" |
| 17 #include "net/spdy/spdy_framer.h" | 17 #include "net/spdy/spdy_framer.h" |
| 18 #include "net/spdy/spdy_protocol.h" | 18 #include "net/spdy/spdy_protocol.h" |
| 19 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 20 | 20 |
| 21 using base::StringPiece; | 21 using base::StringPiece; |
| 22 using base::ContainsKey; | 22 using base::ContainsKey; |
| 23 using std::string; | 23 using std::string; |
| 24 using std::vector; | 24 using std::vector; |
| 25 | 25 |
| 26 namespace net { | 26 namespace net { |
| 27 | 27 |
| 28 // static | 28 // static |
| 29 string SpdyUtils::SerializeUncompressedHeaders(const SpdyHeaderBlock& headers) { | 29 string SpdyUtils::SerializeUncompressedHeaders(const SpdyHeaderBlock& headers) { |
| 30 SpdyMajorVersion spdy_version = HTTP2; | 30 size_t length = SpdyFramer::GetSerializedLength(&headers); |
| 31 | 31 SpdyFrameBuilder builder(length); |
| 32 size_t length = SpdyFramer::GetSerializedLength(spdy_version, &headers); | 32 SpdyFramer framer; |
| 33 SpdyFrameBuilder builder(length, spdy_version); | |
| 34 SpdyFramer framer(spdy_version); | |
| 35 framer.SerializeHeaderBlockWithoutCompression(&builder, headers); | 33 framer.SerializeHeaderBlockWithoutCompression(&builder, headers); |
| 36 SpdySerializedFrame block(builder.take()); | 34 SpdySerializedFrame block(builder.take()); |
| 37 return string(block.data(), length); | 35 return string(block.data(), length); |
| 38 } | 36 } |
| 39 | 37 |
| 40 // static | 38 // static |
| 41 bool SpdyUtils::ParseHeaders(const char* data, | 39 bool SpdyUtils::ParseHeaders(const char* data, |
| 42 uint32_t data_len, | 40 uint32_t data_len, |
| 43 int64_t* content_length, | 41 int64_t* content_length, |
| 44 SpdyHeaderBlock* headers) { | 42 SpdyHeaderBlock* headers) { |
| 45 SpdyFramer framer(HTTP2); | 43 SpdyFramer framer; |
| 46 if (!framer.ParseHeaderBlockInBuffer(data, data_len, headers) || | 44 if (!framer.ParseHeaderBlockInBuffer(data, data_len, headers) || |
| 47 headers->empty()) { | 45 headers->empty()) { |
| 48 return false; // Headers were invalid. | 46 return false; // Headers were invalid. |
| 49 } | 47 } |
| 50 | 48 |
| 51 if (!ContainsKey(*headers, "content-length")) { | 49 if (!ContainsKey(*headers, "content-length")) { |
| 52 return true; | 50 return true; |
| 53 } | 51 } |
| 54 | 52 |
| 55 return ExtractContentLengthFromHeaders(content_length, headers); | 53 return ExtractContentLengthFromHeaders(content_length, headers); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 86 } | 84 } |
| 87 return true; | 85 return true; |
| 88 } | 86 } |
| 89 } | 87 } |
| 90 | 88 |
| 91 // static | 89 // static |
| 92 bool SpdyUtils::ParseTrailers(const char* data, | 90 bool SpdyUtils::ParseTrailers(const char* data, |
| 93 uint32_t data_len, | 91 uint32_t data_len, |
| 94 size_t* final_byte_offset, | 92 size_t* final_byte_offset, |
| 95 SpdyHeaderBlock* trailers) { | 93 SpdyHeaderBlock* trailers) { |
| 96 SpdyFramer framer(HTTP2); | 94 SpdyFramer framer; |
| 97 if (!framer.ParseHeaderBlockInBuffer(data, data_len, trailers) || | 95 if (!framer.ParseHeaderBlockInBuffer(data, data_len, trailers) || |
| 98 trailers->empty()) { | 96 trailers->empty()) { |
| 99 DVLOG(1) << "Request Trailers are invalid."; | 97 DVLOG(1) << "Request Trailers are invalid."; |
| 100 return false; // Trailers were invalid. | 98 return false; // Trailers were invalid. |
| 101 } | 99 } |
| 102 | 100 |
| 103 // Pull out the final offset pseudo header which indicates the number of | 101 // Pull out the final offset pseudo header which indicates the number of |
| 104 // response body bytes expected. | 102 // response body bytes expected. |
| 105 auto it = trailers->find(kFinalOffsetHeaderKey); | 103 auto it = trailers->find(kFinalOffsetHeaderKey); |
| 106 if (it == trailers->end() || | 104 if (it == trailers->end() || |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 (*headers)[":authority"] = url.substr(start); | 252 (*headers)[":authority"] = url.substr(start); |
| 255 (*headers)[":path"] = "/"; | 253 (*headers)[":path"] = "/"; |
| 256 return true; | 254 return true; |
| 257 } | 255 } |
| 258 (*headers)[":authority"] = url.substr(start, pos - start); | 256 (*headers)[":authority"] = url.substr(start, pos - start); |
| 259 (*headers)[":path"] = url.substr(pos); | 257 (*headers)[":path"] = url.substr(pos); |
| 260 return true; | 258 return true; |
| 261 } | 259 } |
| 262 | 260 |
| 263 } // namespace net | 261 } // namespace net |
| OLD | NEW |