blob: 50fe687cdd345a1c0357be7f10427b76c4122fc3 [file] [log] [blame]
renjietangd21094b2019-06-14 09:39:11 -07001// Copyright 2019 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#include "net/third_party/quiche/src/quic/core/qpack/qpack_send_stream.h"
6
renjietang89e73562019-07-22 11:24:22 -07007#include "net/third_party/quiche/src/quic/core/quic_session.h"
renjietangd21094b2019-06-14 09:39:11 -07008#include "net/third_party/quiche/src/quic/platform/api/quic_arraysize.h"
9
10namespace quic {
11QpackSendStream::QpackSendStream(QuicStreamId id,
renjietang89e73562019-07-22 11:24:22 -070012 QuicSession* session,
renjietanga2736fc2019-07-18 11:07:23 -070013 uint64_t http3_stream_type)
renjietangd21094b2019-06-14 09:39:11 -070014 : QuicStream(id, session, /*is_static = */ true, WRITE_UNIDIRECTIONAL),
renjietanga2736fc2019-07-18 11:07:23 -070015 http3_stream_type_(http3_stream_type),
renjietangd21094b2019-06-14 09:39:11 -070016 stream_type_sent_(false) {}
17
dschinazi17d42422019-06-18 16:35:07 -070018void QpackSendStream::OnStreamReset(const QuicRstStreamFrame& /*frame*/) {
renjietangd21094b2019-06-14 09:39:11 -070019 // TODO(renjietang) Change the error code to H/3 specific
20 // HTTP_CLOSED_CRITICAL_STREAM.
21 session()->connection()->CloseConnection(
22 QUIC_INVALID_STREAM_ID, "Attempt to reset qpack send stream",
23 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET);
24}
25
26void QpackSendStream::WriteStreamData(QuicStringPiece data) {
fayanga4b37b22019-06-18 13:37:47 -070027 QuicConnection::ScopedPacketFlusher flusher(session()->connection());
renjietangc8c02a52019-08-22 10:38:37 -070028 MaybeSendStreamType();
renjietangd6f5afa2019-08-19 11:27:55 -070029 WriteOrBufferData(data, false, nullptr);
30}
31
renjietangc8c02a52019-08-22 10:38:37 -070032void QpackSendStream::MaybeSendStreamType() {
renjietangd21094b2019-06-14 09:39:11 -070033 if (!stream_type_sent_) {
renjietanga2736fc2019-07-18 11:07:23 -070034 char type[sizeof(http3_stream_type_)];
renjietangd21094b2019-06-14 09:39:11 -070035 QuicDataWriter writer(QUIC_ARRAYSIZE(type), type);
renjietanga2736fc2019-07-18 11:07:23 -070036 writer.WriteVarInt62(http3_stream_type_);
renjietangd21094b2019-06-14 09:39:11 -070037 WriteOrBufferData(QuicStringPiece(writer.data(), writer.length()), false,
38 nullptr);
39 stream_type_sent_ = true;
40 }
renjietang87cd7de2019-08-16 08:35:10 -070041}
42
renjietangd21094b2019-06-14 09:39:11 -070043} // namespace quic