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 #ifndef NET_TOOLS_QUIC_QUIC_SIMPLE_CLIENT_STREAM_H_ | |
6 #define NET_TOOLS_QUIC_QUIC_SIMPLE_CLIENT_STREAM_H_ | |
7 | |
8 #include <sys/types.h> | |
9 #include <string> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/strings/string_piece.h" | |
13 #include "net/base/io_buffer.h" | |
14 #include "net/http/http_request_info.h" | |
15 #include "net/http/http_response_headers.h" | |
16 #include "net/quic/quic_data_stream.h" | |
17 #include "net/quic/quic_protocol.h" | |
18 #include "net/tools/balsa/balsa_frame.h" | |
19 #include "net/tools/balsa/balsa_headers.h" | |
20 | |
21 namespace net { | |
22 | |
23 namespace tools { | |
24 | |
25 class QuicSimpleClientSession; | |
26 | |
27 // All this does right now is send an SPDY request, and aggregate the | |
28 // SPDY response. | |
29 class QuicSimpleClientStream : public QuicDataStream { | |
30 public: | |
31 QuicSimpleClientStream(QuicStreamId id, QuicSimpleClientSession* session); | |
32 ~QuicSimpleClientStream() override; | |
33 | |
34 // Override the base class to close the write side as soon as we get a | |
35 // response. | |
36 // SPDY/HTTP does not support bidirectional streaming. | |
37 void OnStreamFrame(const QuicStreamFrame& frame) override; | |
38 | |
39 // Override the base class to store the size of the headers. | |
40 void OnStreamHeadersComplete(bool fin, size_t frame_len) override; | |
41 | |
42 // ReliableQuicStream implementation called by the session when there's | |
43 // data for us. | |
44 uint32 ProcessData(const char* data, uint32 data_len) override; | |
45 | |
46 void OnFinRead() override; | |
47 | |
48 // Serializes the headers and body, sends it to the server, and | |
49 // returns the number of bytes sent. | |
50 size_t SendRequest(const HttpRequestInfo& headers, | |
51 base::StringPiece body, | |
52 bool fin); | |
53 | |
54 // Sends body data to the server, or buffers if it can't be sent immediately. | |
55 void SendBody(const std::string& data, bool fin); | |
56 // As above, but |delegate| will be notified once |data| is ACKed. | |
57 void SendBody(const std::string& data, | |
58 bool fin, | |
59 QuicAckNotifier::DelegateInterface* delegate); | |
60 | |
61 // Returns the response data. | |
62 const std::string& data() { return data_; } | |
63 | |
64 // Returns whatever headers have been received for this stream. | |
65 scoped_refptr<HttpResponseHeaders> headers() { return headers_; } | |
66 | |
67 size_t header_bytes_read() const { return header_bytes_read_; } | |
68 | |
69 size_t header_bytes_written() const { return header_bytes_written_; } | |
70 | |
71 // While the server's set_priority shouldn't be called externally, the creator | |
72 // of client-side streams should be able to set the priority. | |
73 using QuicDataStream::set_priority; | |
74 | |
75 private: | |
76 int ParseResponseHeaders(); | |
77 | |
78 scoped_refptr<HttpResponseHeaders> headers_; | |
79 std::string data_; | |
80 | |
81 scoped_refptr<GrowableIOBuffer> read_buf_; | |
82 bool response_headers_received_; | |
83 size_t header_bytes_read_; | |
84 size_t header_bytes_written_; | |
85 | |
86 DISALLOW_COPY_AND_ASSIGN(QuicSimpleClientStream); | |
87 }; | |
88 | |
89 } // namespace tools | |
90 } // namespace net | |
91 | |
92 #endif // NET_TOOLS_QUIC_QUIC_SIMPLE_CLIENT_STREAM_H_ | |
OLD | NEW |