base: Make it possible to replace the MessageLoop's task runner
[chromium-blink-merge.git] / net / tools / quic / quic_spdy_server_stream.h
blob08b031a94a754f94789b72eb04fcfcad4a378916
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 #ifndef NET_TOOLS_QUIC_QUIC_SPDY_SERVER_STREAM_H_
6 #define NET_TOOLS_QUIC_QUIC_SPDY_SERVER_STREAM_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "net/quic/quic_data_stream.h"
12 #include "net/quic/quic_protocol.h"
13 #include "net/spdy/spdy_framer.h"
15 namespace net {
17 class QuicSpdySession;
19 namespace tools {
21 namespace test {
22 class QuicSpdyServerStreamPeer;
23 } // namespace test
25 // All this does right now is aggregate data, and on fin, send an HTTP
26 // response.
27 class QuicSpdyServerStream : public QuicDataStream {
28 public:
29 QuicSpdyServerStream(QuicStreamId id, QuicSpdySession* session);
30 ~QuicSpdyServerStream() override;
32 // QuicDataStream
33 void OnStreamHeadersComplete(bool fin, size_t frame_len) override;
35 // ReliableQuicStream implementation called by the session when there's
36 // data for us.
37 uint32 ProcessData(const char* data, uint32 data_len) override;
38 void OnFinRead() override;
40 protected:
41 // Sends a basic 200 response using SendHeaders for the headers and WriteData
42 // for the body.
43 virtual void SendResponse();
45 SpdyHeaderBlock* request_headers() { return &request_headers_; }
47 private:
48 friend class test::QuicSpdyServerStreamPeer;
50 // Parses the request headers from |data| to |request_headers_|.
51 // Returns false if there was an error parsing the headers.
52 bool ParseRequestHeaders(const char* data, uint32 data_len);
54 // Sends a basic 500 response using SendHeaders for the headers and WriteData
55 // for the body
56 void SendErrorResponse();
58 void SendHeadersAndBody(const SpdyHeaderBlock& response_headers,
59 base::StringPiece body);
61 // Returns the key for |request_headers_| which identifies the host.
62 const std::string GetHostKey();
64 // The parsed headers received from the client.
65 SpdyHeaderBlock request_headers_;
66 int content_length_;
67 std::string body_;
69 DISALLOW_COPY_AND_ASSIGN(QuicSpdyServerStream);
72 } // namespace tools
73 } // namespace net
75 #endif // NET_TOOLS_QUIC_QUIC_SPDY_SERVER_STREAM_H_