| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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 | 24 |
| 25 namespace net { | 25 namespace net { |
| 26 | 26 |
| 27 // static | 27 // static |
| 28 string SpdyUtils::SerializeUncompressedHeaders(const SpdyHeaderBlock& headers) { | 28 string SpdyUtils::SerializeUncompressedHeaders(const SpdyHeaderBlock& headers) { |
| 29 size_t length = SpdyFramer::GetSerializedLength(&headers); | 29 size_t length = SpdyFramer::GetSerializedLength(&headers); |
| 30 SpdyFrameBuilder builder(length); | 30 SpdyFrameBuilder builder(length); |
| 31 SpdyFramer framer; | 31 SpdyFramer framer(SpdyFramer::DISABLE_COMPRESSION); |
| 32 framer.SerializeHeaderBlockWithoutCompression(&builder, headers); | 32 framer.SerializeHeaderBlockWithoutCompression(&builder, headers); |
| 33 SpdySerializedFrame block(builder.take()); | 33 SpdySerializedFrame block(builder.take()); |
| 34 return string(block.data(), length); | 34 return string(block.data(), length); |
| 35 } | 35 } |
| 36 | 36 |
| 37 // static | 37 // static |
| 38 bool SpdyUtils::ParseHeaders(const char* data, | 38 bool SpdyUtils::ParseHeaders(const char* data, |
| 39 uint32_t data_len, | 39 uint32_t data_len, |
| 40 int64_t* content_length, | 40 int64_t* content_length, |
| 41 SpdyHeaderBlock* headers) { | 41 SpdyHeaderBlock* headers) { |
| 42 SpdyFramer framer; | 42 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 43 if (!framer.ParseHeaderBlockInBuffer(data, data_len, headers) || | 43 if (!framer.ParseHeaderBlockInBuffer(data, data_len, headers) || |
| 44 headers->empty()) { | 44 headers->empty()) { |
| 45 return false; // Headers were invalid. | 45 return false; // Headers were invalid. |
| 46 } | 46 } |
| 47 | 47 |
| 48 if (!ContainsKey(*headers, "content-length")) { | 48 if (!ContainsKey(*headers, "content-length")) { |
| 49 return true; | 49 return true; |
| 50 } | 50 } |
| 51 | 51 |
| 52 return ExtractContentLengthFromHeaders(content_length, headers); | 52 return ExtractContentLengthFromHeaders(content_length, headers); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 83 } | 83 } |
| 84 return true; | 84 return true; |
| 85 } | 85 } |
| 86 } | 86 } |
| 87 | 87 |
| 88 // static | 88 // static |
| 89 bool SpdyUtils::ParseTrailers(const char* data, | 89 bool SpdyUtils::ParseTrailers(const char* data, |
| 90 uint32_t data_len, | 90 uint32_t data_len, |
| 91 size_t* final_byte_offset, | 91 size_t* final_byte_offset, |
| 92 SpdyHeaderBlock* trailers) { | 92 SpdyHeaderBlock* trailers) { |
| 93 SpdyFramer framer; | 93 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 94 if (!framer.ParseHeaderBlockInBuffer(data, data_len, trailers) || | 94 if (!framer.ParseHeaderBlockInBuffer(data, data_len, trailers) || |
| 95 trailers->empty()) { | 95 trailers->empty()) { |
| 96 DVLOG(1) << "Request Trailers are invalid."; | 96 DVLOG(1) << "Request Trailers are invalid."; |
| 97 return false; // Trailers were invalid. | 97 return false; // Trailers were invalid. |
| 98 } | 98 } |
| 99 | 99 |
| 100 // Pull out the final offset pseudo header which indicates the number of | 100 // Pull out the final offset pseudo header which indicates the number of |
| 101 // response body bytes expected. | 101 // response body bytes expected. |
| 102 auto it = trailers->find(kFinalOffsetHeaderKey); | 102 auto it = trailers->find(kFinalOffsetHeaderKey); |
| 103 if (it == trailers->end() || | 103 if (it == trailers->end() || |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 (*headers)[":authority"] = url.substr(start); | 251 (*headers)[":authority"] = url.substr(start); |
| 252 (*headers)[":path"] = "/"; | 252 (*headers)[":path"] = "/"; |
| 253 return true; | 253 return true; |
| 254 } | 254 } |
| 255 (*headers)[":authority"] = url.substr(start, pos - start); | 255 (*headers)[":authority"] = url.substr(start, pos - start); |
| 256 (*headers)[":path"] = url.substr(pos); | 256 (*headers)[":path"] = url.substr(pos); |
| 257 return true; | 257 return true; |
| 258 } | 258 } |
| 259 | 259 |
| 260 } // namespace net | 260 } // namespace net |
| OLD | NEW |