| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/tools/quic/quic_reliable_server_stream.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/memory/singleton.h" | |
| 9 #include "net/tools/quic/quic_in_memory_cache.h" | |
| 10 | |
| 11 using base::StringPiece; | |
| 12 | |
| 13 namespace net { | |
| 14 namespace tools { | |
| 15 | |
| 16 QuicReliableServerStream::QuicReliableServerStream(QuicStreamId id, | |
| 17 QuicSession* session) | |
| 18 : ReliableQuicStream(id, session) { | |
| 19 } | |
| 20 | |
| 21 | |
| 22 void QuicReliableServerStream::SendResponse() { | |
| 23 // Find response in cache. If not found, send error response. | |
| 24 const QuicInMemoryCache::Response* response = | |
| 25 QuicInMemoryCache::GetInstance()->GetResponse(headers_); | |
| 26 if (response == NULL) { | |
| 27 SendErrorResponse(); | |
| 28 return; | |
| 29 } | |
| 30 | |
| 31 DLOG(INFO) << "Sending response for stream " << id(); | |
| 32 SendHeaders(response->headers()); | |
| 33 WriteData(response->body(), true); | |
| 34 } | |
| 35 | |
| 36 void QuicReliableServerStream::SendErrorResponse() { | |
| 37 DLOG(INFO) << "Sending error response for stream " << id(); | |
| 38 BalsaHeaders headers; | |
| 39 headers.SetResponseFirstlineFromStringPieces( | |
| 40 "HTTP/1.1", "500", "Server Error"); | |
| 41 headers.ReplaceOrAppendHeader("content-length", "3"); | |
| 42 SendHeaders(headers); | |
| 43 WriteData("bad", true); | |
| 44 } | |
| 45 | |
| 46 QuicConsumedData QuicReliableServerStream::WriteData(StringPiece data, | |
| 47 bool fin) { | |
| 48 // We only support SPDY and HTTP, and neither handles bidirectional streaming. | |
| 49 if (!read_side_closed()) { | |
| 50 CloseReadSide(); | |
| 51 } | |
| 52 return ReliableQuicStream::WriteData(data, fin); | |
| 53 } | |
| 54 | |
| 55 } // namespace tools | |
| 56 } // namespace net | |
| OLD | NEW |