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