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 "net/quic/core/quic_flags.h" | 10 #include "net/quic/core/quic_flags.h" |
11 #include "net/quic/core/quic_spdy_stream.h" | 11 #include "net/quic/core/quic_spdy_stream.h" |
12 #include "net/quic/core/spdy_utils.h" | 12 #include "net/quic/core/spdy_utils.h" |
13 #include "net/quic/platform/api/quic_bug_tracker.h" | 13 #include "net/quic/platform/api/quic_bug_tracker.h" |
14 #include "net/quic/platform/api/quic_logging.h" | 14 #include "net/quic/platform/api/quic_logging.h" |
15 #include "net/quic/platform/api/quic_map_util.h" | 15 #include "net/quic/platform/api/quic_map_util.h" |
16 #include "net/quic/platform/api/quic_text_utils.h" | 16 #include "net/quic/platform/api/quic_text_utils.h" |
17 #include "net/spdy/spdy_protocol.h" | 17 #include "net/spdy/spdy_protocol.h" |
18 #include "net/tools/quic/quic_http_response_cache.h" | 18 #include "net/tools/quic/quic_http_response_cache.h" |
19 #include "net/tools/quic/quic_simple_server_session.h" | 19 #include "net/tools/quic/quic_simple_server_session.h" |
20 | 20 |
21 using base::StringPiece; | |
22 using std::string; | 21 using std::string; |
23 | 22 |
24 namespace net { | 23 namespace net { |
25 | 24 |
26 QuicSimpleServerStream::QuicSimpleServerStream( | 25 QuicSimpleServerStream::QuicSimpleServerStream( |
27 QuicStreamId id, | 26 QuicStreamId id, |
28 QuicSpdySession* session, | 27 QuicSpdySession* session, |
29 QuicHttpResponseCache* response_cache) | 28 QuicHttpResponseCache* response_cache) |
30 : QuicSpdyServerStreamBase(id, session), | 29 : QuicSpdyServerStreamBase(id, session), |
31 content_length_(-1), | 30 content_length_(-1), |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 QUIC_DVLOG(1) << "Stream " << id() << " sending error response."; | 215 QUIC_DVLOG(1) << "Stream " << id() << " sending error response."; |
217 SpdyHeaderBlock headers; | 216 SpdyHeaderBlock headers; |
218 headers[":status"] = "500"; | 217 headers[":status"] = "500"; |
219 headers["content-length"] = | 218 headers["content-length"] = |
220 QuicTextUtils::Uint64ToString(strlen(kErrorResponseBody)); | 219 QuicTextUtils::Uint64ToString(strlen(kErrorResponseBody)); |
221 SendHeadersAndBody(std::move(headers), kErrorResponseBody); | 220 SendHeadersAndBody(std::move(headers), kErrorResponseBody); |
222 } | 221 } |
223 | 222 |
224 void QuicSimpleServerStream::SendHeadersAndBody( | 223 void QuicSimpleServerStream::SendHeadersAndBody( |
225 SpdyHeaderBlock response_headers, | 224 SpdyHeaderBlock response_headers, |
226 StringPiece body) { | 225 QuicStringPiece body) { |
227 SendHeadersAndBodyAndTrailers(std::move(response_headers), body, | 226 SendHeadersAndBodyAndTrailers(std::move(response_headers), body, |
228 SpdyHeaderBlock()); | 227 SpdyHeaderBlock()); |
229 } | 228 } |
230 | 229 |
231 void QuicSimpleServerStream::SendHeadersAndBodyAndTrailers( | 230 void QuicSimpleServerStream::SendHeadersAndBodyAndTrailers( |
232 SpdyHeaderBlock response_headers, | 231 SpdyHeaderBlock response_headers, |
233 StringPiece body, | 232 QuicStringPiece body, |
234 SpdyHeaderBlock response_trailers) { | 233 SpdyHeaderBlock response_trailers) { |
235 if (!allow_bidirectional_data() && !reading_stopped()) { | 234 if (!allow_bidirectional_data() && !reading_stopped()) { |
236 StopReading(); | 235 StopReading(); |
237 } | 236 } |
238 | 237 |
239 // Send the headers, with a FIN if there's nothing else to send. | 238 // Send the headers, with a FIN if there's nothing else to send. |
240 bool send_fin = (body.empty() && response_trailers.empty()); | 239 bool send_fin = (body.empty() && response_trailers.empty()); |
241 QUIC_DLOG(INFO) << "Stream " << id() << " writing headers (fin = " << send_fin | 240 QUIC_DLOG(INFO) << "Stream " << id() << " writing headers (fin = " << send_fin |
242 << ") : " << response_headers.DebugString(); | 241 << ") : " << response_headers.DebugString(); |
243 WriteHeaders(std::move(response_headers), send_fin, nullptr); | 242 WriteHeaders(std::move(response_headers), send_fin, nullptr); |
(...skipping 18 matching lines...) Expand all Loading... |
262 QUIC_DLOG(INFO) << "Stream " << id() << " writing trailers (fin = true): " | 261 QUIC_DLOG(INFO) << "Stream " << id() << " writing trailers (fin = true): " |
263 << response_trailers.DebugString(); | 262 << response_trailers.DebugString(); |
264 WriteTrailers(std::move(response_trailers), nullptr); | 263 WriteTrailers(std::move(response_trailers), nullptr); |
265 } | 264 } |
266 | 265 |
267 const char* const QuicSimpleServerStream::kErrorResponseBody = "bad"; | 266 const char* const QuicSimpleServerStream::kErrorResponseBody = "bad"; |
268 const char* const QuicSimpleServerStream::kNotFoundResponseBody = | 267 const char* const QuicSimpleServerStream::kNotFoundResponseBody = |
269 "file not found"; | 268 "file not found"; |
270 | 269 |
271 } // namespace net | 270 } // namespace net |
OLD | NEW |