QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // 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 team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8 | #include "net/third_party/quiche/src/quic/tools/quic_url.h" |
QUICHE team | 5015e2e | 2019-12-11 09:38:06 -0800 | [diff] [blame^] | 9 | #include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" |
danzh | 2a93046 | 2019-07-03 07:28:06 -0700 | [diff] [blame] | 10 | #include "net/third_party/quiche/src/spdy/core/spdy_protocol.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11 | |
| 12 | namespace quic { |
| 13 | |
| 14 | // Container for HTTP response header/body pairs |
| 15 | // fetched by the QuicSimpleServerBackend |
| 16 | class 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, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 24 | std::string body); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 25 | ServerPushInfo(const ServerPushInfo& other); |
| 26 | |
| 27 | QuicUrl request_url; |
| 28 | spdy::SpdyHeaderBlock headers; |
| 29 | spdy::SpdyPriority priority; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 30 | std::string body; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 31 | }; |
| 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. |
rch | 7bd5476 | 2019-10-15 10:53:24 -0700 | [diff] [blame] | 46 | GENERATE_BYTES // Sends a response with a length equal to the number |
| 47 | // of bytes in the URL path. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 48 | }; |
| 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 team | 5015e2e | 2019-12-11 09:38:06 -0800 | [diff] [blame^] | 59 | const quiche::QuicheStringPiece body() const { |
| 60 | return quiche::QuicheStringPiece(body_); |
| 61 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 62 | |
| 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 team | 5015e2e | 2019-12-11 09:38:06 -0800 | [diff] [blame^] | 73 | void set_body(quiche::QuicheStringPiece body) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 74 | 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_; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 83 | std::string body_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 84 | uint16_t stop_sending_code_; |
| 85 | }; |
| 86 | |
| 87 | } // namespace quic |
| 88 | |
| 89 | #endif // QUICHE_QUIC_TOOLS_QUIC_BACKEND_RESPONSE_H_ |