QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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_TOOLS_QUIC_SIMPLE_SERVER_BACKEND_H_ |
| 6 | #define QUICHE_QUIC_TOOLS_QUIC_SIMPLE_SERVER_BACKEND_H_ |
| 7 | |
danzh | 2a93046 | 2019-07-03 07:28:06 -0700 | [diff] [blame] | 8 | #include "net/third_party/quiche/src/quic/core/quic_types.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9 | #include "net/third_party/quiche/src/quic/tools/quic_backend_response.h" |
| 10 | |
| 11 | namespace spdy { |
| 12 | class SpdyHeaderBlock; |
| 13 | } // namespace spdy |
| 14 | |
| 15 | namespace quic { |
| 16 | |
| 17 | // This interface implements the functionality to fetch a response |
| 18 | // from the backend (such as cache, http-proxy etc) to serve |
| 19 | // requests received by a Quic Server |
| 20 | class QuicSimpleServerBackend { |
| 21 | public: |
| 22 | // This interface implements the methods |
| 23 | // called by the QuicSimpleServerBackend implementation |
| 24 | // to process the request in the backend |
| 25 | class RequestHandler { |
| 26 | public: |
| 27 | virtual ~RequestHandler() {} |
| 28 | |
| 29 | virtual QuicConnectionId connection_id() const = 0; |
| 30 | virtual QuicStreamId stream_id() const = 0; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 31 | virtual std::string peer_host() const = 0; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 32 | // Called when the response is ready at the backend and can be send back to |
| 33 | // the QUIC client. |
| 34 | virtual void OnResponseBackendComplete( |
| 35 | const QuicBackendResponse* response, |
| 36 | std::list<QuicBackendResponse::ServerPushInfo> resources) = 0; |
| 37 | }; |
| 38 | |
| 39 | virtual ~QuicSimpleServerBackend() = default; |
| 40 | // This method initializes the backend instance to fetch responses |
| 41 | // from a backend server, in-memory cache etc. |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 42 | virtual bool InitializeBackend(const std::string& backend_url) = 0; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 43 | // Returns true if the backend has been successfully initialized |
| 44 | // and could be used to fetch HTTP requests |
| 45 | virtual bool IsBackendInitialized() const = 0; |
| 46 | // Triggers a HTTP request to be sent to the backend server or cache |
| 47 | // If response is immediately available, the function synchronously calls |
| 48 | // the |request_handler| with the HTTP response. |
| 49 | // If the response has to be fetched over the network, the function |
| 50 | // asynchronously calls |request_handler| with the HTTP response. |
| 51 | virtual void FetchResponseFromBackend( |
| 52 | const spdy::SpdyHeaderBlock& request_headers, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 53 | const std::string& request_body, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 54 | RequestHandler* request_handler) = 0; |
| 55 | // Clears the state of the backend instance |
| 56 | virtual void CloseBackendResponseStream(RequestHandler* request_handler) = 0; |
| 57 | }; |
| 58 | |
| 59 | } // namespace quic |
| 60 | |
| 61 | #endif // QUICHE_QUIC_TOOLS_QUIC_SIMPLE_SERVER_BACKEND_H_ |