1use http::header::{HeaderName, HeaderValue, InvalidHeaderValue, AUTHORIZATION, CONTENT_TYPE};
2use http::Method;
3use serde::{de::DeserializeOwned, Serialize};
4
5pub(crate) const NSID_REFRESH_SESSION: &str = "com.atproto.server.refreshSession";
6
7pub enum AuthorizationToken {
8 Bearer(String),
9 Dpop(String),
10}
11
12impl TryFrom<AuthorizationToken> for HeaderValue {
13 type Error = InvalidHeaderValue;
14
15 fn try_from(token: AuthorizationToken) -> Result<Self, Self::Error> {
16 HeaderValue::from_str(&match token {
17 AuthorizationToken::Bearer(t) => format!("Bearer {t}"),
18 AuthorizationToken::Dpop(t) => format!("DPoP {t}"),
19 })
20 }
21}
22
23pub enum Header {
25 ContentType,
26 Authorization,
27 AtprotoProxy,
28 AtprotoAcceptLabelers,
29}
30
31impl From<Header> for HeaderName {
32 fn from(value: Header) -> Self {
33 match value {
34 Header::ContentType => CONTENT_TYPE,
35 Header::Authorization => AUTHORIZATION,
36 Header::AtprotoProxy => HeaderName::from_static("atproto-proxy"),
37 Header::AtprotoAcceptLabelers => HeaderName::from_static("atproto-accept-labelers"),
38 }
39 }
40}
41
42pub struct XrpcRequest<P, I>
44where
45 I: Serialize,
46{
47 pub method: Method,
48 pub nsid: String,
49 pub parameters: Option<P>,
50 pub input: Option<InputDataOrBytes<I>>,
51 pub encoding: Option<String>,
52}
53
54pub enum InputDataOrBytes<T>
58where
59 T: Serialize,
60{
61 Data(T),
62 Bytes(Vec<u8>),
63}
64
65pub enum OutputDataOrBytes<T>
69where
70 T: DeserializeOwned,
71{
72 Data(T),
73 Bytes(Vec<u8>),
74}