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_simple_server_stream.h" | 5 #include "net/tools/quic/quic_simple_server_stream.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } | 96 } |
97 | 97 |
98 // If the sequencer is closed, then all the body, including the fin, has been | 98 // If the sequencer is closed, then all the body, including the fin, has been |
99 // consumed. | 99 // consumed. |
100 OnFinRead(); | 100 OnFinRead(); |
101 | 101 |
102 if (write_side_closed() || fin_buffered()) { | 102 if (write_side_closed() || fin_buffered()) { |
103 return; | 103 return; |
104 } | 104 } |
105 | 105 |
106 if (request_headers_.empty()) { | |
107 DVLOG(1) << "Request headers empty."; | |
108 SendErrorResponse(); | |
109 return; | |
110 } | |
111 | |
112 if (content_length_ > 0 && | |
113 static_cast<uint64_t>(content_length_) != body_.size()) { | |
114 DVLOG(1) << "Content length (" << content_length_ << ") != body size (" | |
115 << body_.size() << ")."; | |
116 SendErrorResponse(); | |
117 return; | |
118 } | |
119 | |
120 SendResponse(); | 106 SendResponse(); |
121 } | 107 } |
122 | 108 |
123 void QuicSimpleServerStream::PushResponse( | 109 void QuicSimpleServerStream::PushResponse( |
124 SpdyHeaderBlock push_request_headers) { | 110 SpdyHeaderBlock push_request_headers) { |
125 if (id() % 2 != 0) { | 111 if (id() % 2 != 0) { |
126 QUIC_BUG << "Client initiated stream shouldn't be used as promised stream."; | 112 QUIC_BUG << "Client initiated stream shouldn't be used as promised stream."; |
127 return; | 113 return; |
128 } | 114 } |
129 // Change the stream state to emulate a client request. | 115 // Change the stream state to emulate a client request. |
130 request_headers_ = std::move(push_request_headers); | 116 request_headers_ = std::move(push_request_headers); |
131 content_length_ = 0; | 117 content_length_ = 0; |
132 DVLOG(1) << "Stream " << id() << ": Ready to receive server push response."; | 118 DVLOG(1) << "Stream " << id() << ": Ready to receive server push response."; |
133 | 119 |
134 // Set as if stream decompresed the headers and received fin. | 120 // Set as if stream decompresed the headers and received fin. |
135 QuicSpdyStream::OnInitialHeadersComplete(/*fin=*/true, 0); | 121 QuicSpdyStream::OnInitialHeadersComplete(/*fin=*/true, 0); |
136 } | 122 } |
137 | 123 |
138 void QuicSimpleServerStream::SendResponse() { | 124 void QuicSimpleServerStream::SendResponse() { |
| 125 if (request_headers_.empty()) { |
| 126 DVLOG(1) << "Request headers empty."; |
| 127 SendErrorResponse(); |
| 128 return; |
| 129 } |
| 130 |
| 131 if (content_length_ > 0 && |
| 132 static_cast<uint64_t>(content_length_) != body_.size()) { |
| 133 DVLOG(1) << "Content length (" << content_length_ << ") != body size (" |
| 134 << body_.size() << ")."; |
| 135 SendErrorResponse(); |
| 136 return; |
| 137 } |
| 138 |
139 if (!base::ContainsKey(request_headers_, ":authority") || | 139 if (!base::ContainsKey(request_headers_, ":authority") || |
140 !base::ContainsKey(request_headers_, ":path")) { | 140 !base::ContainsKey(request_headers_, ":path")) { |
141 DVLOG(1) << "Request headers do not contain :authority or :path."; | 141 DVLOG(1) << "Request headers do not contain :authority or :path."; |
142 SendErrorResponse(); | 142 SendErrorResponse(); |
143 return; | 143 return; |
144 } | 144 } |
145 | 145 |
146 // Find response in cache. If not found, send error response. | 146 // Find response in cache. If not found, send error response. |
147 const QuicInMemoryCache::Response* response = | 147 const QuicInMemoryCache::Response* response = |
148 QuicInMemoryCache::GetInstance()->GetResponse( | 148 QuicInMemoryCache::GetInstance()->GetResponse( |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 SpdyHeaderBlock response_headers, | 227 SpdyHeaderBlock response_headers, |
228 StringPiece body) { | 228 StringPiece body) { |
229 SendHeadersAndBodyAndTrailers(std::move(response_headers), body, | 229 SendHeadersAndBodyAndTrailers(std::move(response_headers), body, |
230 SpdyHeaderBlock()); | 230 SpdyHeaderBlock()); |
231 } | 231 } |
232 | 232 |
233 void QuicSimpleServerStream::SendHeadersAndBodyAndTrailers( | 233 void QuicSimpleServerStream::SendHeadersAndBodyAndTrailers( |
234 SpdyHeaderBlock response_headers, | 234 SpdyHeaderBlock response_headers, |
235 StringPiece body, | 235 StringPiece body, |
236 SpdyHeaderBlock response_trailers) { | 236 SpdyHeaderBlock response_trailers) { |
237 // This server only supports SPDY and HTTP, and neither handles bidirectional | 237 if (!allow_bidirectional_data() && !reading_stopped()) { |
238 // streaming. | |
239 if (!reading_stopped()) { | |
240 StopReading(); | 238 StopReading(); |
241 } | 239 } |
242 | 240 |
243 // Send the headers, with a FIN if there's nothing else to send. | 241 // Send the headers, with a FIN if there's nothing else to send. |
244 bool send_fin = (body.empty() && response_trailers.empty()); | 242 bool send_fin = (body.empty() && response_trailers.empty()); |
245 DVLOG(1) << "Writing headers (fin = " << send_fin | 243 DVLOG(1) << "Writing headers (fin = " << send_fin |
246 << ") : " << response_headers.DebugString(); | 244 << ") : " << response_headers.DebugString(); |
247 WriteHeaders(std::move(response_headers), send_fin, nullptr); | 245 WriteHeaders(std::move(response_headers), send_fin, nullptr); |
248 if (send_fin) { | 246 if (send_fin) { |
249 // Nothing else to send. | 247 // Nothing else to send. |
(...skipping 16 matching lines...) Expand all Loading... |
266 DVLOG(1) << "Writing trailers (fin = true): " | 264 DVLOG(1) << "Writing trailers (fin = true): " |
267 << response_trailers.DebugString(); | 265 << response_trailers.DebugString(); |
268 WriteTrailers(std::move(response_trailers), nullptr); | 266 WriteTrailers(std::move(response_trailers), nullptr); |
269 } | 267 } |
270 | 268 |
271 const char* const QuicSimpleServerStream::kErrorResponseBody = "bad"; | 269 const char* const QuicSimpleServerStream::kErrorResponseBody = "bad"; |
272 const char* const QuicSimpleServerStream::kNotFoundResponseBody = | 270 const char* const QuicSimpleServerStream::kNotFoundResponseBody = |
273 "file not found"; | 271 "file not found"; |
274 | 272 |
275 } // namespace net | 273 } // namespace net |
OLD | NEW |