• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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>
9 #include <string>
10 
11 #include "absl/strings/string_view.h"
12 #include "quiche/quic/core/http/quic_spdy_stream.h"
13 #include "quiche/quic/core/quic_packets.h"
14 #include "quiche/spdy/core/http2_header_block.h"
15 #include "quiche/spdy/core/spdy_framer.h"
16 
17 namespace quic {
18 
19 class QuicSpdyClientSession;
20 
21 // All this does right now is send an SPDY request, and aggregate the
22 // SPDY response.
23 class QUIC_EXPORT_PRIVATE QuicSpdyClientStream : public QuicSpdyStream {
24  public:
25   QuicSpdyClientStream(QuicStreamId id, QuicSpdyClientSession* session,
26                        StreamType type);
27   QuicSpdyClientStream(PendingStream* pending,
28                        QuicSpdyClientSession* spdy_session);
29   QuicSpdyClientStream(const QuicSpdyClientStream&) = delete;
30   QuicSpdyClientStream& operator=(const QuicSpdyClientStream&) = delete;
31   ~QuicSpdyClientStream() override;
32 
33   // Override the base class to parse and store headers.
34   void OnInitialHeadersComplete(bool fin, size_t frame_len,
35                                 const QuicHeaderList& header_list) override;
36 
37   // Override the base class to parse and store trailers.
38   void OnTrailingHeadersComplete(bool fin, size_t frame_len,
39                                  const QuicHeaderList& header_list) override;
40 
41   // Override the base class to handle creation of the push stream.
42   void OnPromiseHeaderList(QuicStreamId promised_id, size_t frame_len,
43                            const QuicHeaderList& header_list) override;
44 
45   // QuicStream implementation called by the session when there's data for us.
46   void OnBodyAvailable() 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(spdy::Http2HeaderBlock headers, absl::string_view body,
51                      bool fin);
52 
53   // Returns the response data.
data()54   absl::string_view data() const { return data_; }
55 
56   // Returns whatever headers have been received for this stream.
response_headers()57   const spdy::Http2HeaderBlock& response_headers() { return response_headers_; }
58 
preliminary_headers()59   const spdy::Http2HeaderBlock& preliminary_headers() {
60     return preliminary_headers_;
61   }
62 
header_bytes_read()63   size_t header_bytes_read() const { return header_bytes_read_; }
64 
header_bytes_written()65   size_t header_bytes_written() const { return header_bytes_written_; }
66 
response_code()67   int response_code() const { return response_code_; }
68 
69   // While the server's SetPriority shouldn't be called externally, the creator
70   // of client-side streams should be able to set the priority.
71   using QuicSpdyStream::SetPriority;
72 
73  protected:
74   bool AreHeadersValid(const QuicHeaderList& header_list) const override;
75 
76   // Called by OnInitialHeadersComplete to set response_header_. Returns false
77   // on error.
78   virtual bool CopyAndValidateHeaders(const QuicHeaderList& header_list,
79                                       int64_t& content_length,
80                                       spdy::Http2HeaderBlock& headers);
81 
82   // Called by OnInitialHeadersComplete to set response_code_ based on
83   // response_header_. Returns false on error.
84   virtual bool ParseAndValidateStatusCode();
85 
86  private:
87   // The parsed headers received from the server.
88   spdy::Http2HeaderBlock response_headers_;
89 
90   // The parsed content-length, or -1 if none is specified.
91   int64_t content_length_;
92   int response_code_;
93   std::string data_;
94   size_t header_bytes_read_;
95   size_t header_bytes_written_;
96 
97   QuicSpdyClientSession* session_;
98 
99   // These preliminary headers are used for the 100 Continue headers
100   // that may arrive before the response headers when the request has
101   // Expect: 100-continue.
102   bool has_preliminary_headers_;
103   spdy::Http2HeaderBlock preliminary_headers_;
104 };
105 
106 }  // namespace quic
107 
108 #endif  // QUICHE_QUIC_CORE_HTTP_QUIC_SPDY_CLIENT_STREAM_H_
109