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