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
//! The response for OAuth redirect.

use crate::response::{CT_TEXT_HTML, CT_TEXT_PLAIN};
use axum::body::Body;
use axum::http::Response;
use axum::response::IntoResponse;

/// The response for OAuth redirect.
#[derive(Debug)]
pub enum OauthRedirectResponse {
    /// The variant to return plain-text.
    Text(String),

    /// The variant to return HTML.
    Html(String),
}

impl OauthRedirectResponse {
    /// Creates [`Text`][`Self::Text`].
    pub fn text(inner: String) -> Self {
        Self::Text(inner)
    }

    /// Creates [`Html`][`Self::Html`].
    pub fn html(inner: String) -> Self {
        Self::Html(inner)
    }
}

impl IntoResponse for OauthRedirectResponse {
    fn into_response(self) -> Response<Body> {
        match self {
            Self::Text(inner) => ([CT_TEXT_PLAIN], inner).into_response(),

            Self::Html(inner) => ([CT_TEXT_HTML], inner).into_response(),
        }
    }
}