QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 QUICHE_QUIC_CORE_HTTP_QUIC_SPDY_CLIENT_STREAM_H_ |
| 6 | #define QUICHE_QUIC_CORE_HTTP_QUIC_SPDY_CLIENT_STREAM_H_ |
| 7 | |
| 8 | #include <cstddef> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 9 | #include <string> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11 | #include "net/third_party/quiche/src/quic/core/http/quic_spdy_stream.h" |
| 12 | #include "net/third_party/quiche/src/quic/core/quic_packets.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13 | #include "net/third_party/quiche/src/quic/platform/api/quic_string_piece.h" |
| 14 | #include "net/third_party/quiche/src/spdy/core/spdy_framer.h" |
| 15 | |
| 16 | namespace quic { |
| 17 | |
| 18 | class QuicSpdyClientSession; |
| 19 | |
| 20 | // All this does right now is send an SPDY request, and aggregate the |
| 21 | // SPDY response. |
| 22 | class QuicSpdyClientStream : public QuicSpdyStream { |
| 23 | public: |
| 24 | QuicSpdyClientStream(QuicStreamId id, |
| 25 | QuicSpdyClientSession* session, |
| 26 | StreamType type); |
renjietang | baea59c | 2019-05-29 15:08:14 -0700 | [diff] [blame] | 27 | QuicSpdyClientStream(PendingStream* pending, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 28 | QuicSpdyClientSession* spdy_session, |
| 29 | StreamType type); |
| 30 | QuicSpdyClientStream(const QuicSpdyClientStream&) = delete; |
| 31 | QuicSpdyClientStream& operator=(const QuicSpdyClientStream&) = delete; |
| 32 | ~QuicSpdyClientStream() override; |
| 33 | |
| 34 | // Override the base class to parse and store headers. |
| 35 | void OnInitialHeadersComplete(bool fin, |
| 36 | size_t frame_len, |
| 37 | const QuicHeaderList& header_list) override; |
| 38 | |
| 39 | // Override the base class to parse and store trailers. |
| 40 | void OnTrailingHeadersComplete(bool fin, |
| 41 | size_t frame_len, |
| 42 | const QuicHeaderList& header_list) override; |
| 43 | |
| 44 | // Override the base class to handle creation of the push stream. |
| 45 | void OnPromiseHeaderList(QuicStreamId promised_id, |
| 46 | size_t frame_len, |
| 47 | const QuicHeaderList& header_list) override; |
| 48 | |
| 49 | // QuicStream implementation called by the session when there's data for us. |
| 50 | void OnBodyAvailable() override; |
| 51 | |
| 52 | // Serializes the headers and body, sends it to the server, and |
| 53 | // returns the number of bytes sent. |
| 54 | size_t SendRequest(spdy::SpdyHeaderBlock headers, |
| 55 | QuicStringPiece body, |
| 56 | bool fin); |
| 57 | |
| 58 | // Returns the response data. |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 59 | const std::string& data() { return data_; } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 60 | |
| 61 | // Returns whatever headers have been received for this stream. |
| 62 | const spdy::SpdyHeaderBlock& response_headers() { return response_headers_; } |
| 63 | |
| 64 | const spdy::SpdyHeaderBlock& preliminary_headers() { |
| 65 | return preliminary_headers_; |
| 66 | } |
| 67 | |
| 68 | size_t header_bytes_read() const { return header_bytes_read_; } |
| 69 | |
| 70 | size_t header_bytes_written() const { return header_bytes_written_; } |
| 71 | |
| 72 | int response_code() const { return response_code_; } |
| 73 | |
| 74 | // While the server's SetPriority shouldn't be called externally, the creator |
| 75 | // of client-side streams should be able to set the priority. |
| 76 | using QuicSpdyStream::SetPriority; |
| 77 | |
| 78 | private: |
| 79 | // The parsed headers received from the server. |
| 80 | spdy::SpdyHeaderBlock response_headers_; |
| 81 | |
| 82 | // The parsed content-length, or -1 if none is specified. |
| 83 | int64_t content_length_; |
| 84 | int response_code_; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 85 | std::string data_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 86 | size_t header_bytes_read_; |
| 87 | size_t header_bytes_written_; |
| 88 | |
| 89 | QuicSpdyClientSession* session_; |
| 90 | |
| 91 | // These preliminary headers are used for the 100 Continue headers |
| 92 | // that may arrive before the response headers when the request has |
| 93 | // Expect: 100-continue. |
| 94 | bool has_preliminary_headers_; |
| 95 | spdy::SpdyHeaderBlock preliminary_headers_; |
| 96 | }; |
| 97 | |
| 98 | } // namespace quic |
| 99 | |
| 100 | #endif // QUICHE_QUIC_CORE_HTTP_QUIC_SPDY_CLIENT_STREAM_H_ |