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 14 matching lines...) Expand all Loading... |
25 | 25 |
26 size_t length = SpdyFramer::GetSerializedLength(spdy_version, &headers); | 26 size_t length = SpdyFramer::GetSerializedLength(spdy_version, &headers); |
27 SpdyFrameBuilder builder(length, spdy_version); | 27 SpdyFrameBuilder builder(length, spdy_version); |
28 SpdyFramer::WriteHeaderBlock(&builder, spdy_version, &headers); | 28 SpdyFramer::WriteHeaderBlock(&builder, spdy_version, &headers); |
29 scoped_ptr<SpdyFrame> block(builder.take()); | 29 scoped_ptr<SpdyFrame> block(builder.take()); |
30 return string(block->data(), length); | 30 return string(block->data(), length); |
31 } | 31 } |
32 | 32 |
33 // static | 33 // static |
34 bool SpdyUtils::ParseHeaders(const char* data, | 34 bool SpdyUtils::ParseHeaders(const char* data, |
35 uint32 data_len, | 35 uint32_t data_len, |
36 int* content_length, | 36 int* content_length, |
37 SpdyHeaderBlock* headers) { | 37 SpdyHeaderBlock* headers) { |
38 SpdyFramer framer(HTTP2); | 38 SpdyFramer framer(HTTP2); |
39 if (!framer.ParseHeaderBlockInBuffer(data, data_len, headers) || | 39 if (!framer.ParseHeaderBlockInBuffer(data, data_len, headers) || |
40 headers->empty()) { | 40 headers->empty()) { |
41 return false; // Headers were invalid. | 41 return false; // Headers were invalid. |
42 } | 42 } |
43 | 43 |
44 if (ContainsKey(*headers, "content-length")) { | 44 if (ContainsKey(*headers, "content-length")) { |
45 // Check whether multiple values are consistent. | 45 // Check whether multiple values are consistent. |
(...skipping 14 matching lines...) Expand all Loading... |
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 | 68 // static |
69 bool SpdyUtils::ParseTrailers(const char* data, | 69 bool SpdyUtils::ParseTrailers(const char* data, |
70 uint32 data_len, | 70 uint32_t data_len, |
71 size_t* final_byte_offset, | 71 size_t* final_byte_offset, |
72 SpdyHeaderBlock* trailers) { | 72 SpdyHeaderBlock* trailers) { |
73 SpdyFramer framer(HTTP2); | 73 SpdyFramer framer(HTTP2); |
74 if (!framer.ParseHeaderBlockInBuffer(data, data_len, trailers) || | 74 if (!framer.ParseHeaderBlockInBuffer(data, data_len, trailers) || |
75 trailers->empty()) { | 75 trailers->empty()) { |
76 DVLOG(1) << "Request Trailers are invalid."; | 76 DVLOG(1) << "Request Trailers are invalid."; |
77 return false; // Trailers were invalid. | 77 return false; // Trailers were invalid. |
78 } | 78 } |
79 | 79 |
80 // Pull out the final offset pseudo header which indicates the number of | 80 // Pull out the final offset pseudo header which indicates the number of |
(...skipping 18 matching lines...) Expand all Loading... |
99 } | 99 } |
100 | 100 |
101 // TODO(rjshade): Check for other forbidden keys, following the HTTP/2 spec. | 101 // TODO(rjshade): Check for other forbidden keys, following the HTTP/2 spec. |
102 } | 102 } |
103 | 103 |
104 DVLOG(1) << "Successfully parsed Trailers."; | 104 DVLOG(1) << "Successfully parsed Trailers."; |
105 return true; | 105 return true; |
106 } | 106 } |
107 | 107 |
108 } // namespace net | 108 } // namespace net |
OLD | NEW |