1 // Copyright 2023 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_WEB_TRANSPORT_ONLY_BACKEND_H_ 6 #define QUICHE_QUIC_TOOLS_WEB_TRANSPORT_ONLY_BACKEND_H_ 7 8 #include <memory> 9 #include <string> 10 #include <utility> 11 12 #include "absl/status/statusor.h" 13 #include "absl/strings/string_view.h" 14 #include "quiche/quic/core/web_transport_interface.h" 15 #include "quiche/quic/tools/quic_simple_server_backend.h" 16 #include "quiche/common/quiche_callbacks.h" 17 #include "quiche/web_transport/web_transport.h" 18 #include "quiche/spdy/core/http2_header_block.h" 19 20 namespace quic { 21 22 // A callback to create a WebTransport session visitor for a given path and the 23 // session object. The path includes both the path and the query. 24 using WebTransportRequestCallback = quiche::MultiUseCallback< 25 absl::StatusOr<std::unique_ptr<webtransport::SessionVisitor>>( 26 absl::string_view path, WebTransportSession* session)>; 27 28 class WebTransportOnlyBackend : public QuicSimpleServerBackend { 29 public: WebTransportOnlyBackend(WebTransportRequestCallback callback)30 explicit WebTransportOnlyBackend(WebTransportRequestCallback callback) 31 : callback_(std::move(callback)) {} 32 33 // QuicSimpleServerBackend implementation. InitializeBackend(const std::string &)34 bool InitializeBackend(const std::string&) override { return true; } IsBackendInitialized()35 bool IsBackendInitialized() const override { return true; } 36 void FetchResponseFromBackend(const spdy::Http2HeaderBlock&, 37 const std::string&, 38 RequestHandler* request_handler) override; CloseBackendResponseStream(RequestHandler *)39 void CloseBackendResponseStream(RequestHandler*) override {} SupportsWebTransport()40 bool SupportsWebTransport() override { return true; } 41 WebTransportResponse ProcessWebTransportRequest( 42 const spdy::Http2HeaderBlock& request_headers, 43 WebTransportSession* session) override; 44 45 private: 46 WebTransportRequestCallback callback_; 47 }; 48 49 } // namespace quic 50 51 #endif // QUICHE_QUIC_TOOLS_WEB_TRANSPORT_ONLY_BACKEND_H_ 52