summaryrefslogtreecommitdiff
path: root/chromium/net/tools/quic/quic_reliable_client_stream.h
blob: 10b60c2f69628dcb4103588f5f055089fe1bb59e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef NET_TOOLS_QUIC_QUIC_RELIABLE_CLIENT_STREAM_H_
#define NET_TOOLS_QUIC_QUIC_RELIABLE_CLIENT_STREAM_H_

#include <sys/types.h>
#include <string>

#include "base/strings/string_piece.h"
#include "net/quic/quic_protocol.h"
#include "net/quic/reliable_quic_stream.h"
#include "net/tools/flip_server/balsa_frame.h"
#include "net/tools/flip_server/balsa_headers.h"

namespace net {

class QuicSession;

namespace tools {

class QuicClientSession;

// A base class for spdy/http client streams which handles the concept
// of sending and receiving headers and bodies.
class QuicReliableClientStream : public ReliableQuicStream {
 public:
  QuicReliableClientStream(QuicStreamId id, QuicSession* session)
      : ReliableQuicStream(id, session) {
  }

  // Serializes the headers and body, sends it to the server, and
  // returns the number of bytes sent.
  virtual ssize_t SendRequest(const BalsaHeaders& headers,
                              base::StringPiece body,
                              bool fin) = 0;
  // Sends body data to the server and returns the number of bytes sent.
  virtual ssize_t SendBody(const std::string& data, bool fin);

  // Override the base class to close the Write side as soon as we get a
  // response.
  // SPDY/HTTP do not support bidirectional streaming.
  virtual bool OnStreamFrame(const QuicStreamFrame& frame) OVERRIDE;

  // Returns the response data.
  const std::string& data() { return data_; }

  // Returns whatever headers have been received for this stream.
  const BalsaHeaders& headers() { return headers_; }

 protected:
  std::string* mutable_data() { return &data_; }
  BalsaHeaders* mutable_headers() { return &headers_; }

 private:
  BalsaHeaders headers_;
  std::string data_;

  DISALLOW_COPY_AND_ASSIGN(QuicReliableClientStream);
};

}  // namespace tools
}  // namespace net

#endif  // NET_TOOLS_QUIC_QUIC_RELIABLE_CLIENT_STREAM_H_