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