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.
5 #include "net/tools/quic/quic_reliable_server_stream.h"
7 #include "base/logging.h"
8 #include "base/memory/singleton.h"
9 #include "net/tools/quic/quic_in_memory_cache.h"
11 using base::StringPiece
;
16 QuicReliableServerStream::QuicReliableServerStream(QuicStreamId id
,
18 : ReliableQuicStream(id
, session
) {
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
) {
31 DLOG(INFO
) << "Sending response for stream " << id();
32 SendHeaders(response
->headers());
33 WriteData(response
->body(), true);
36 void QuicReliableServerStream::SendErrorResponse() {
37 DLOG(INFO
) << "Sending error response for stream " << id();
39 headers
.SetResponseFirstlineFromStringPieces(
40 "HTTP/1.1", "500", "Server Error");
41 headers
.ReplaceOrAppendHeader("content-length", "3");
43 WriteData("bad", true);
46 QuicConsumedData
QuicReliableServerStream::WriteData(StringPiece data
,
48 // We only support SPDY and HTTP, and neither handles bidirectional streaming.
49 if (!read_side_closed()) {
52 return ReliableQuicStream::WriteData(data
, fin
);