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" |
danzh | 2a93046 | 2019-07-03 07:28:06 -0700 | [diff] [blame] | 9 | #include "net/third_party/quiche/src/spdy/core/spdy_protocol.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10 | |
| 11 | namespace quic { |
| 12 | |
| 13 | // Container for HTTP response header/body pairs |
| 14 | // fetched by the QuicSimpleServerBackend |
| 15 | class QuicBackendResponse { |
| 16 | public: |
| 17 | // A ServerPushInfo contains path of the push request and everything needed in |
| 18 | // comprising a response for the push request. |
| 19 | struct ServerPushInfo { |
| 20 | ServerPushInfo(QuicUrl request_url, |
| 21 | spdy::SpdyHeaderBlock headers, |
| 22 | spdy::SpdyPriority priority, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 23 | std::string body); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 24 | ServerPushInfo(const ServerPushInfo& other); |
| 25 | |
| 26 | QuicUrl request_url; |
| 27 | spdy::SpdyHeaderBlock headers; |
| 28 | spdy::SpdyPriority priority; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 29 | std::string body; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | enum SpecialResponseType { |
| 33 | REGULAR_RESPONSE, // Send the headers and body like a server should. |
| 34 | CLOSE_CONNECTION, // Close the connection (sending the close packet). |
| 35 | IGNORE_REQUEST, // Do nothing, expect the client to time out. |
| 36 | BACKEND_ERR_RESPONSE, // There was an error fetching the response from |
| 37 | // the backend, for example as a TCP connection |
| 38 | // error. |
| 39 | INCOMPLETE_RESPONSE, // The server will act as if there is a non-empty |
| 40 | // trailer but it will not be sent, as a result, FIN |
| 41 | // will not be sent too. |
| 42 | STOP_SENDING, // Acts like INCOMPLETE_RESPONSE in that the entire |
| 43 | // response is not sent. After sending what is sent, |
| 44 | // the server will send a STOP_SENDING. |
| 45 | }; |
| 46 | QuicBackendResponse(); |
| 47 | |
| 48 | QuicBackendResponse(const QuicBackendResponse& other) = delete; |
| 49 | QuicBackendResponse& operator=(const QuicBackendResponse& other) = delete; |
| 50 | |
| 51 | ~QuicBackendResponse(); |
| 52 | |
| 53 | SpecialResponseType response_type() const { return response_type_; } |
| 54 | const spdy::SpdyHeaderBlock& headers() const { return headers_; } |
| 55 | const spdy::SpdyHeaderBlock& trailers() const { return trailers_; } |
| 56 | const QuicStringPiece body() const { return QuicStringPiece(body_); } |
| 57 | |
| 58 | void set_response_type(SpecialResponseType response_type) { |
| 59 | response_type_ = response_type; |
| 60 | } |
| 61 | |
| 62 | void set_headers(spdy::SpdyHeaderBlock headers) { |
| 63 | headers_ = std::move(headers); |
| 64 | } |
| 65 | void set_trailers(spdy::SpdyHeaderBlock trailers) { |
| 66 | trailers_ = std::move(trailers); |
| 67 | } |
| 68 | void set_body(QuicStringPiece body) { |
| 69 | body_.assign(body.data(), body.size()); |
| 70 | } |
| 71 | uint16_t stop_sending_code() const { return stop_sending_code_; } |
| 72 | void set_stop_sending_code(uint16_t code) { stop_sending_code_ = code; } |
| 73 | |
| 74 | private: |
| 75 | SpecialResponseType response_type_; |
| 76 | spdy::SpdyHeaderBlock headers_; |
| 77 | spdy::SpdyHeaderBlock trailers_; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 78 | std::string body_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 79 | uint16_t stop_sending_code_; |
| 80 | }; |
| 81 | |
| 82 | } // namespace quic |
| 83 | |
| 84 | #endif // QUICHE_QUIC_TOOLS_QUIC_BACKEND_RESPONSE_H_ |