| 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/spdy_utils.h" | 5 #include "net/quic/spdy_utils.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 } | 58 } |
| 59 if (new_value != *content_length) { | 59 if (new_value != *content_length) { |
| 60 return false; | 60 return false; |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 return true; | 65 return true; |
| 66 } | 66 } |
| 67 | 67 |
| 68 // static |
| 69 bool SpdyUtils::ParseTrailers(const char* data, |
| 70 uint32 data_len, |
| 71 size_t* final_byte_offset, |
| 72 SpdyHeaderBlock* trailers) { |
| 73 SpdyFramer framer(HTTP2); |
| 74 if (!framer.ParseHeaderBlockInBuffer(data, data_len, trailers) || |
| 75 trailers->empty()) { |
| 76 DVLOG(1) << "Request Trailers are invalid."; |
| 77 return false; // Trailers were invalid. |
| 78 } |
| 79 |
| 80 // Pull out the :final-offset pseudo header which indicates the number of |
| 81 // response body bytes expected. |
| 82 auto it = trailers->find(":final-offset"); |
| 83 if (it == trailers->end() || |
| 84 !base::StringToSizeT(it->second, final_byte_offset)) { |
| 85 DVLOG(1) << ":final-offset not present"; |
| 86 return false; // :final-offset key must be present. |
| 87 } |
| 88 // :final-offset header is no longer used. |
| 89 trailers->erase(it->first); |
| 90 |
| 91 // Trailers must not have empty keys, and must not contain pseudo headers. |
| 92 for (const auto& trailer : *trailers) { |
| 93 base::StringPiece key = trailer.first; |
| 94 base::StringPiece value = trailer.second; |
| 95 if (key.starts_with(":")) { |
| 96 DVLOG(1) << "Trailers must not contain pseudo-header: '" << key << "','" |
| 97 << value << "'."; |
| 98 return false; |
| 99 } |
| 100 |
| 101 // TODO(rjshade): Check for other forbidden keys, following the HTTP/2 spec. |
| 102 } |
| 103 |
| 104 DVLOG(1) << "Successfully parsed Trailers."; |
| 105 return true; |
| 106 } |
| 107 |
| 68 } // namespace net | 108 } // namespace net |
| OLD | NEW |