blob: 6537987a381412f7ba2e0fa2037c044ff7bc4fce [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// Copyright 2017 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_TOOLS_QUIC_BACKEND_RESPONSE_H_
6#define QUICHE_QUIC_TOOLS_QUIC_BACKEND_RESPONSE_H_
7
QUICHE teama6ef0a62019-03-07 20:34:33 -05008#include "net/third_party/quiche/src/quic/tools/quic_url.h"
QUICHE team5015e2e2019-12-11 09:38:06 -08009#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h"
danzh2a930462019-07-03 07:28:06 -070010#include "net/third_party/quiche/src/spdy/core/spdy_protocol.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050011
12namespace quic {
13
14// Container for HTTP response header/body pairs
15// fetched by the QuicSimpleServerBackend
16class QuicBackendResponse {
17 public:
18 // A ServerPushInfo contains path of the push request and everything needed in
19 // comprising a response for the push request.
20 struct ServerPushInfo {
21 ServerPushInfo(QuicUrl request_url,
22 spdy::SpdyHeaderBlock headers,
23 spdy::SpdyPriority priority,
vasilvvc48c8712019-03-11 13:38:16 -070024 std::string body);
QUICHE teama6ef0a62019-03-07 20:34:33 -050025 ServerPushInfo(const ServerPushInfo& other);
26
27 QuicUrl request_url;
28 spdy::SpdyHeaderBlock headers;
29 spdy::SpdyPriority priority;
vasilvvc48c8712019-03-11 13:38:16 -070030 std::string body;
QUICHE teama6ef0a62019-03-07 20:34:33 -050031 };
32
33 enum SpecialResponseType {
34 REGULAR_RESPONSE, // Send the headers and body like a server should.
35 CLOSE_CONNECTION, // Close the connection (sending the close packet).
36 IGNORE_REQUEST, // Do nothing, expect the client to time out.
37 BACKEND_ERR_RESPONSE, // There was an error fetching the response from
38 // the backend, for example as a TCP connection
39 // error.
40 INCOMPLETE_RESPONSE, // The server will act as if there is a non-empty
41 // trailer but it will not be sent, as a result, FIN
42 // will not be sent too.
43 STOP_SENDING, // Acts like INCOMPLETE_RESPONSE in that the entire
44 // response is not sent. After sending what is sent,
45 // the server will send a STOP_SENDING.
rch7bd54762019-10-15 10:53:24 -070046 GENERATE_BYTES // Sends a response with a length equal to the number
47 // of bytes in the URL path.
QUICHE teama6ef0a62019-03-07 20:34:33 -050048 };
49 QuicBackendResponse();
50
51 QuicBackendResponse(const QuicBackendResponse& other) = delete;
52 QuicBackendResponse& operator=(const QuicBackendResponse& other) = delete;
53
54 ~QuicBackendResponse();
55
56 SpecialResponseType response_type() const { return response_type_; }
57 const spdy::SpdyHeaderBlock& headers() const { return headers_; }
58 const spdy::SpdyHeaderBlock& trailers() const { return trailers_; }
QUICHE team5015e2e2019-12-11 09:38:06 -080059 const quiche::QuicheStringPiece body() const {
60 return quiche::QuicheStringPiece(body_);
61 }
QUICHE teama6ef0a62019-03-07 20:34:33 -050062
63 void set_response_type(SpecialResponseType response_type) {
64 response_type_ = response_type;
65 }
66
67 void set_headers(spdy::SpdyHeaderBlock headers) {
68 headers_ = std::move(headers);
69 }
70 void set_trailers(spdy::SpdyHeaderBlock trailers) {
71 trailers_ = std::move(trailers);
72 }
QUICHE team5015e2e2019-12-11 09:38:06 -080073 void set_body(quiche::QuicheStringPiece body) {
QUICHE teama6ef0a62019-03-07 20:34:33 -050074 body_.assign(body.data(), body.size());
75 }
76 uint16_t stop_sending_code() const { return stop_sending_code_; }
77 void set_stop_sending_code(uint16_t code) { stop_sending_code_ = code; }
78
79 private:
80 SpecialResponseType response_type_;
81 spdy::SpdyHeaderBlock headers_;
82 spdy::SpdyHeaderBlock trailers_;
vasilvvc48c8712019-03-11 13:38:16 -070083 std::string body_;
QUICHE teama6ef0a62019-03-07 20:34:33 -050084 uint16_t stop_sending_code_;
85};
86
87} // namespace quic
88
89#endif // QUICHE_QUIC_TOOLS_QUIC_BACKEND_RESPONSE_H_