A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
Loading...
Searching...
No Matches
url.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
33#ifndef A11_NET_HTTP_URL_H_
34#define A11_NET_HTTP_URL_H_
35
36#include <cstdint>
37#include <string>
38#include <string_view>
39
40#include <absl/status/statusor.h>
41
42namespace a11::net {
43
50struct ParsedUrl {
51 std::string scheme;
52 std::string host;
53 std::uint16_t port = 0;
54 std::string path;
55 std::string query;
56
58 [[nodiscard]] bool secure() const;
63 [[nodiscard]] std::string authority() const;
65 [[nodiscard]] std::string target() const;
67 [[nodiscard]] std::string origin() const;
69 [[nodiscard]] std::string ToString() const;
70};
71
73std::uint16_t DefaultPortForScheme(std::string_view scheme);
74
85absl::StatusOr<ParsedUrl> ParseUrl(std::string_view url);
86
100absl::StatusOr<ParsedUrl> ResolveReference(const ParsedUrl& base,
101 std::string_view reference);
102
103} // namespace a11::net
104
105#endif // A11_NET_HTTP_URL_H_
Definition action.h:65
absl::StatusOr< ParsedUrl > ResolveReference(const ParsedUrl &base, std::string_view reference)
Resolves reference against base, as a redirect target.
Definition url.cc:202
std::uint16_t DefaultPortForScheme(std::string_view scheme)
Definition url.cc:156
absl::StatusOr< ParsedUrl > ParseUrl(std::string_view url)
Parses an absolute http/https/ws/wss URL.
Definition url.cc:166
An absolute URL split into the parts a connection needs.
Definition url.h:50
bool secure() const
Definition url.cc:127
std::string host
Hostname or IP literal, without IPv6 brackets.
Definition url.h:52
std::string authority() const
Definition url.cc:131
std::string scheme
Lowercase, without "://" (e.g. "https").
Definition url.h:51
std::string path
Begins with '/', or is empty when none was given.
Definition url.h:54
std::string origin() const
Definition url.cc:148
std::string ToString() const
Definition url.cc:152
std::string query
Query without the leading '?'; empty when absent.
Definition url.h:55
std::uint16_t port
Explicit port, or the scheme's default.
Definition url.h:53
std::string target() const
Definition url.cc:140