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