blob: 78dfbf4105a40a81c409046cd420aef844b0fa03 [file] [log] [blame]
dschinazi22e23c72019-12-17 17:16:15 -08001// Copyright 2019 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_MASQUE_MASQUE_SERVER_BACKEND_H_
6#define QUICHE_QUIC_MASQUE_MASQUE_SERVER_BACKEND_H_
7
8#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
9#include "net/third_party/quiche/src/quic/tools/quic_memory_cache_backend.h"
10
11namespace quic {
12
13// QUIC server backend that understands MASQUE requests, but otherwise answers
14// HTTP queries using an in-memory cache.
15class QUIC_NO_EXPORT MasqueServerBackend : public QuicMemoryCacheBackend {
16 public:
17 // Interface meant to be implemented by the owner of the MasqueServerBackend
18 // instance.
19 class QUIC_NO_EXPORT BackendClient {
20 public:
21 virtual std::unique_ptr<QuicBackendResponse> HandleMasqueRequest(
22 const std::string& masque_path,
23 const spdy::SpdyHeaderBlock& request_headers,
24 const std::string& request_body,
25 QuicSimpleServerBackend::RequestHandler* request_handler) = 0;
26 virtual ~BackendClient() = default;
27 };
28
29 explicit MasqueServerBackend(const std::string& server_authority,
30 const std::string& cache_directory);
31
32 // Disallow copy and assign.
33 MasqueServerBackend(const MasqueServerBackend&) = delete;
34 MasqueServerBackend& operator=(const MasqueServerBackend&) = delete;
35
36 // From QuicMemoryCacheBackend.
37 void FetchResponseFromBackend(
38 const spdy::SpdyHeaderBlock& request_headers,
39 const std::string& request_body,
40 QuicSimpleServerBackend::RequestHandler* request_handler) override;
41
42 void CloseBackendResponseStream(
43 QuicSimpleServerBackend::RequestHandler* request_handler) override;
44
45 // Register backend client that can handle MASQUE requests.
46 void RegisterBackendClient(QuicConnectionId connection_id,
47 BackendClient* backend_client);
48
49 // Unregister backend client.
50 void RemoveBackendClient(QuicConnectionId connection_id);
51
52 private:
53 // Handle MASQUE request.
54 bool MaybeHandleMasqueRequest(
55 const spdy::SpdyHeaderBlock& request_headers,
56 const std::string& request_body,
57 QuicSimpleServerBackend::RequestHandler* request_handler);
58
59 std::string server_authority_;
60 QuicUnorderedMap<std::string, std::unique_ptr<QuicBackendResponse>>
61 active_response_map_;
62 QuicUnorderedMap<QuicConnectionId, BackendClient*, QuicConnectionIdHash>
63 backend_clients_;
64};
65
66} // namespace quic
67
68#endif // QUICHE_QUIC_MASQUE_MASQUE_SERVER_BACKEND_H_