blob: 968ec66dd093e129918fa1a1bbb7c088465ec95f [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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
danzh2a930462019-07-03 07:28:06 -07008#include "net/third_party/quiche/src/quic/core/quic_types.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -05009#include "net/third_party/quiche/src/quic/tools/quic_backend_response.h"
10
11namespace spdy {
12class SpdyHeaderBlock;
13} // namespace spdy
14
15namespace 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
20class 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;
vasilvvc48c8712019-03-11 13:38:16 -070031 virtual std::string peer_host() const = 0;
QUICHE teama6ef0a62019-03-07 20:34:33 -050032 // 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.
vasilvvc48c8712019-03-11 13:38:16 -070042 virtual bool InitializeBackend(const std::string& backend_url) = 0;
QUICHE teama6ef0a62019-03-07 20:34:33 -050043 // 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,
vasilvvc48c8712019-03-11 13:38:16 -070053 const std::string& request_body,
QUICHE teama6ef0a62019-03-07 20:34:33 -050054 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_