OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/tools/quic/quic_spdy_server_stream.h" | 5 #include "net/tools/quic/quic_spdy_server_stream.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_piece.h" |
10 #include "net/quic/quic_data_stream.h" | 11 #include "net/quic/quic_data_stream.h" |
11 #include "net/quic/quic_spdy_session.h" | 12 #include "net/quic/quic_spdy_session.h" |
12 #include "net/quic/spdy_utils.h" | 13 #include "net/quic/spdy_utils.h" |
13 #include "net/spdy/spdy_protocol.h" | 14 #include "net/spdy/spdy_protocol.h" |
14 #include "net/tools/quic/quic_in_memory_cache.h" | 15 #include "net/tools/quic/quic_in_memory_cache.h" |
15 | 16 |
16 using base::StringPiece; | 17 using base::StringPiece; |
17 using base::StringToInt; | 18 using base::StringToInt; |
18 using std::string; | 19 using std::string; |
19 | 20 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 data_len, | 91 data_len, |
91 &request_headers_); | 92 &request_headers_); |
92 DCHECK_LE(len, data_len); | 93 DCHECK_LE(len, data_len); |
93 if (len == 0 || request_headers_.empty()) { | 94 if (len == 0 || request_headers_.empty()) { |
94 return false; // Headers were invalid. | 95 return false; // Headers were invalid. |
95 } | 96 } |
96 | 97 |
97 if (data_len > len) { | 98 if (data_len > len) { |
98 body_.append(data + len, data_len - len); | 99 body_.append(data + len, data_len - len); |
99 } | 100 } |
100 if (ContainsKey(request_headers_, "content-length") && | 101 if (ContainsKey(request_headers_, "content-length")) { |
101 !StringToInt(request_headers_["content-length"], &content_length_)) { | 102 // Historically, if an input to SimpleAtoi contained null byte, anything |
102 return false; // Invalid content-length. | 103 // past it would be silently ignored. This behavior is being removed, but |
| 104 // this method relies on it (see cl/101239633). Hence, we explicitly call |
| 105 // c_str() on request headers to simulate the old behavior. |
| 106 // TODO(rch): Correctly handle null-separated value in content-length. |
| 107 // b/23554022 |
| 108 StringPiece trimmed_header(request_headers_["content-length"].c_str()); |
| 109 if (!StringToInt(trimmed_header, &content_length_)) { |
| 110 return false; // Invalid content-length. |
| 111 } |
103 } | 112 } |
104 return true; | 113 return true; |
105 } | 114 } |
106 | 115 |
107 void QuicSpdyServerStream::SendResponse() { | 116 void QuicSpdyServerStream::SendResponse() { |
108 if (!ContainsKey(request_headers_, GetHostKey()) || | 117 if (!ContainsKey(request_headers_, GetHostKey()) || |
109 !ContainsKey(request_headers_, ":path")) { | 118 !ContainsKey(request_headers_, ":path")) { |
110 SendErrorResponse(); | 119 SendErrorResponse(); |
111 return; | 120 return; |
112 } | 121 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 } | 179 } |
171 } | 180 } |
172 | 181 |
173 const string QuicSpdyServerStream::GetHostKey() { | 182 const string QuicSpdyServerStream::GetHostKey() { |
174 // SPDY/4 uses ":authority" instead of ":host". | 183 // SPDY/4 uses ":authority" instead of ":host". |
175 return version() > QUIC_VERSION_24 ? ":authority" : ":host"; | 184 return version() > QUIC_VERSION_24 ? ":authority" : ":host"; |
176 } | 185 } |
177 | 186 |
178 } // namespace tools | 187 } // namespace tools |
179 } // namespace net | 188 } // namespace net |
OLD | NEW |