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 #ifndef NET_TOOLS_QUIC_QUIC_RELIABLE_SERVER_STREAM_H_ 6 #define NET_TOOLS_QUIC_QUIC_RELIABLE_SERVER_STREAM_H_ 7 8 #include <string> 9 10 #include "net/quic/quic_protocol.h" 11 #include "net/quic/reliable_quic_stream.h" 12 #include "net/tools/flip_server/balsa_headers.h" 13 14 namespace net { 15 16 class QuicSession; 17 18 namespace tools { 19 20 namespace test { 21 class QuicReliableServerStreamPeer; 22 } // namespace test 23 24 // A base class for spdy/http server streams which handles the concept 25 // of sending and receiving headers and bodies. 26 class QuicReliableServerStream : public ReliableQuicStream { 27 public: 28 QuicReliableServerStream(QuicStreamId id, QuicSession* session); 29 virtual ~QuicReliableServerStream() {} 30 31 // Subclasses should process and frame data when this is called, returning 32 // how many bytes are processed. 33 virtual uint32 ProcessData(const char* data, uint32 data_len) = 0; 34 // Subclasses should implement this to serialize headers in a 35 // protocol-specific manner, and send it out to the client. 36 virtual void SendHeaders(const BalsaHeaders& response_headers) = 0; 37 38 // Sends a basic 200 response using SendHeaders for the headers and WriteData 39 // for the body. 40 void SendResponse(); 41 // Sends a basic 500 response using SendHeaders for the headers and WriteData 42 // for the body 43 void SendErrorResponse(); 44 // Make sure that as soon as we start writing data, we stop reading. 45 virtual QuicConsumedData WriteData(base::StringPiece data, bool fin) OVERRIDE; 46 47 // Returns whatever headers have been received for this stream. 48 const BalsaHeaders& headers() { return headers_; } 49 50 const string& body() { return body_; } 51 protected: 52 BalsaHeaders* mutable_headers() { return &headers_; } 53 string* mutable_body() { return &body_; } 54 55 private: 56 friend class test::QuicReliableServerStreamPeer; 57 58 BalsaHeaders headers_; 59 string body_; 60 }; 61 62 } // namespace tools 63 } // namespace net 64 65 #endif // NET_TOOLS_QUIC_QUIC_RELIABLE_SERVER_STREAM_H_ 66