mirror of
https://codeberg.org/slatian/service.echoip-slatecave.git
synced 2024-12-27 12:18:20 +01:00
Added echoing of user agents
This commit is contained in:
parent
c7ba9a6346
commit
64498da57a
20
src/main.rs
20
src/main.rs
@ -225,6 +225,7 @@ async fn main() {
|
||||
.route("/dig/:name", get(handle_dig_route_with_path))
|
||||
.route("/ip", get(handle_ip_route))
|
||||
.route("/ip/:address", get(handle_ip_route_with_path))
|
||||
.route("/ua", get(user_agent_handler))
|
||||
.route("/hi", get(hello_world_handler))
|
||||
.with_state(shared_state)
|
||||
.layer(
|
||||
@ -271,7 +272,6 @@ async fn format_and_language_middleware<B>(
|
||||
next.run(req).await
|
||||
}
|
||||
|
||||
#[axum::debug_handler]
|
||||
async fn hello_world_handler(
|
||||
State(arc_state): State<Arc<ServiceSharedState>>,
|
||||
Extension(settings): Extension<TemplateSettings>,
|
||||
@ -287,9 +287,16 @@ async fn hello_world_handler(
|
||||
).await
|
||||
}
|
||||
|
||||
async fn user_agent_handler(
|
||||
TypedHeader(user_agent): TypedHeader<headers::UserAgent>,
|
||||
) -> String {
|
||||
user_agent.to_string()
|
||||
}
|
||||
|
||||
async fn handle_default_route(
|
||||
State(arc_state): State<Arc<ServiceSharedState>>,
|
||||
Extension(settings): Extension<TemplateSettings>,
|
||||
user_agent_header: Option<TypedHeader<headers::UserAgent>>,
|
||||
SecureClientIp(address): SecureClientIp
|
||||
) -> Response {
|
||||
|
||||
@ -301,9 +308,18 @@ async fn handle_default_route(
|
||||
|
||||
let result = get_ip_result(&ip_query, &settings.lang, &state).await;
|
||||
|
||||
let user_agent: Option<String> = match user_agent_header {
|
||||
Some(TypedHeader(user_agent)) => Some(user_agent.to_string()),
|
||||
None => None,
|
||||
};
|
||||
|
||||
state.templating_engine.render_view(
|
||||
&settings,
|
||||
&View::Index{query: ip_query, result: result}
|
||||
&View::Index{
|
||||
query: ip_query,
|
||||
result: result,
|
||||
user_agent: user_agent,
|
||||
}
|
||||
).await
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ pub struct TemplateSettings {
|
||||
#[serde(untagged)]
|
||||
pub enum View {
|
||||
Dig { query: DigQuery, result: simple_dns::DnsLookupResult },
|
||||
Index { query: IpQuery, result: IpResult },
|
||||
Index { query: IpQuery, result: IpResult, user_agent: Option<String> },
|
||||
Ip { query: IpQuery, result: IpResult },
|
||||
Message{ title: String, message: String },
|
||||
#[serde(rename="404")]
|
||||
|
@ -57,5 +57,12 @@
|
||||
</small></p>
|
||||
</section>
|
||||
{% endif %}
|
||||
{% if data.user_agent %}
|
||||
<section>
|
||||
<h2>User Agent</h2>
|
||||
<p>Independent of your IP-Address your browser sends a <a href="https://en.wikipedia.org/wiki/User_agent">User Agent</a> header with each http request.</p>
|
||||
<p>Your browser sent: <code>{{data.user_agent}}</code></p>
|
||||
</section>
|
||||
{% endif %}
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user