1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use crate::{types::Headers, wit};
/// An HTTP endpoint exposed publicly on the Gateway. This is typically used to return metadata for authentication purposes, for example with the [OAuth 2.0 Protected Resource Metadata](https://datatracker.ietf.org/doc/html/rfc9728) spec.
#[non_exhaustive]
pub struct PublicMetadataEndpoint {
/// The absolute path (without domain) of the endpoint. Example: "/.well-known/oauth-protected-resource".
path: String,
/// The contents of the response body that the endpoint will return. Example: `{"resource": "https://secure.example.com" }`.
response_body: Vec<u8>,
/// The headers sent from with the response by the public endpoint. Example: ["Content-Type: application/json"].
response_headers: Headers,
}
impl PublicMetadataEndpoint {
/// Constructor.
pub fn new(path: String, response_body: Vec<u8>) -> Self {
PublicMetadataEndpoint {
path,
response_body,
response_headers: Default::default(),
}
}
/// Set the response headers
pub fn with_headers(mut self, response_headers: Headers) -> Self {
self.response_headers = response_headers;
self
}
/// Access the response headers
pub fn response_headers_mut(&mut self) -> &mut Headers {
&mut self.response_headers
}
}
impl From<wit::PublicMetadataEndpoint> for PublicMetadataEndpoint {
fn from(
wit::PublicMetadataEndpoint {
path,
response_body,
response_headers,
}: wit::PublicMetadataEndpoint,
) -> Self {
PublicMetadataEndpoint {
path,
response_body,
response_headers: response_headers.into(),
}
}
}
impl From<PublicMetadataEndpoint> for wit::PublicMetadataEndpoint {
fn from(
PublicMetadataEndpoint {
path,
response_body,
response_headers,
}: PublicMetadataEndpoint,
) -> Self {
wit::PublicMetadataEndpoint {
path,
response_body,
response_headers: response_headers.into(),
}
}
}