A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
Loading...
Searching...
No Matches
describe_endpoint.h
Go to the documentation of this file.
1/*
2 * Copyright 2026 The A11 Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
34#ifndef A11_NET_DESCRIBE_ENDPOINT_H_
35#define A11_NET_DESCRIBE_ENDPOINT_H_
36
37#include <functional>
38#include <memory>
39#include <optional>
40#include <string>
41#include <string_view>
42
43#include <absl/base/nullability.h>
44#include <absl/status/statusor.h>
45
47#include "a11/net/http2.h"
48
49namespace a11::net {
50
59using DescribeActionsHandler = std::function<absl::StatusOr<std::string>(
60 std::string_view name, std::string_view query)>;
61
63inline constexpr std::string_view kDefaultDescribeEndpoint = "/actions";
64
74 std::string path = std::string(kDefaultDescribeEndpoint);
75
77 [[nodiscard]] bool Enabled() const {
78 return static_cast<bool>(handler) && !path.empty();
79 }
80};
81
93bool MatchDescribePath(std::string_view path,
94 const DescribeEndpointOptions& options,
95 std::string* absl_nonnull name);
96
112std::optional<a11::Task> TryDescribeOverHttp(
113 const DescribeEndpointOptions& options, const HttpRequest& request,
114 const std::shared_ptr<Http2ResponseWriter>& response,
115 HttpHeaders extra_headers = {});
116
118std::string_view QueryOfPath(std::string_view path);
119
120} // namespace a11::net
121
122#endif // A11_NET_DESCRIBE_ENDPOINT_H_
std::string name
The name and its colon, which travel together because they always do.
Definition format.cc:49
Completion values used by every asynchronous A11 operation.
A11's nghttp2 HTTP/2 client, server, and streaming primitives.
std::string path
Definition main.cc:133
Definition action.h:65
bool MatchDescribePath(std::string_view path, const DescribeEndpointOptions &options, std::string *absl_nonnull name)
Whether path addresses the describe endpoint, and what it names.
Definition describe_endpoint.cc:56
constexpr std::string_view kDefaultDescribeEndpoint
Default path serving the action descriptors.
Definition describe_endpoint.h:63
std::vector< std::pair< std::string, std::string > > HttpHeaders
An ordered list of (name, value) HTTP/2 header fields.
Definition http2.h:70
std::optional< a11::Task > TryDescribeOverHttp(const DescribeEndpointOptions &options, const HttpRequest &request, const std::shared_ptr< Http2ResponseWriter > &response, HttpHeaders extra_headers)
Answers request from options, if it is addressed to it.
Definition describe_endpoint.cc:77
std::string_view QueryOfPath(std::string_view path)
The query part of path, without the ?.
Definition describe_endpoint.cc:46
std::function< absl::StatusOr< std::string >(std::string_view name, std::string_view query)> DescribeActionsHandler
Answers a discovery request without opening a wire stream.
Definition describe_endpoint.h:60
Where and whether a server answers discovery over plain HTTP.
Definition describe_endpoint.h:72
bool Enabled() const
Whether this server should answer discovery at all.
Definition describe_endpoint.h:77
std::string path
Definition describe_endpoint.h:74
DescribeActionsHandler handler
Definition describe_endpoint.h:73