ruma_client_api/session/
login_fallback.rs1use ruma_common::{
8 OwnedDeviceId,
9 api::{auth_scheme::NoAuthentication, request},
10 metadata,
11};
12
13metadata! {
14 method: GET,
15 rate_limited: false,
16 authentication: NoAuthentication,
17 path: "/_matrix/static/client/login/",
18}
19
20#[request(error = crate::Error)]
22#[derive(Default)]
23pub struct Request {
24 #[ruma_api(query)]
26 #[serde(skip_serializing_if = "Option::is_none")]
27 pub device_id: Option<OwnedDeviceId>,
28
29 #[ruma_api(query)]
33 #[serde(skip_serializing_if = "Option::is_none")]
34 pub initial_device_display_name: Option<String>,
35}
36
37impl Request {
38 pub fn new(
40 device_id: Option<OwnedDeviceId>,
41 initial_device_display_name: Option<String>,
42 ) -> Self {
43 Self { device_id, initial_device_display_name }
44 }
45}
46
47#[derive(Debug, Clone)]
49#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
50pub struct Response {
51 pub body: Vec<u8>,
53}
54
55impl Response {
56 pub fn new(body: Vec<u8>) -> Self {
58 Self { body }
59 }
60}
61
62#[cfg(feature = "server")]
63impl ruma_common::api::OutgoingResponse for Response {
64 fn try_into_http_response<T: Default + bytes::BufMut>(
65 self,
66 ) -> Result<http::Response<T>, ruma_common::api::error::IntoHttpError> {
67 Ok(http::Response::builder()
68 .status(http::StatusCode::OK)
69 .header(http::header::CONTENT_TYPE, "text/html")
70 .body(ruma_common::serde::slice_to_buf(&self.body))?)
71 }
72}
73
74#[cfg(feature = "client")]
75impl ruma_common::api::IncomingResponse for Response {
76 type EndpointError = crate::Error;
77
78 fn try_from_http_response<T: AsRef<[u8]>>(
79 response: http::Response<T>,
80 ) -> Result<Self, ruma_common::api::error::FromHttpResponseError<Self::EndpointError>> {
81 use ruma_common::api::{EndpointError, error::FromHttpResponseError};
82
83 if response.status().as_u16() >= 400 {
84 return Err(FromHttpResponseError::Server(Self::EndpointError::from_http_response(
85 response,
86 )));
87 }
88
89 let body = response.into_body().as_ref().to_owned();
90 Ok(Self { body })
91 }
92}