Fix UPnP on Sony
This commit is contained in:
parent
a38480e876
commit
f4f82ed4b4
5 changed files with 47 additions and 17 deletions
|
|
@ -17,7 +17,8 @@ use std::str::FromStr;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::io::AsyncSeekExt;
|
use tokio::io::AsyncSeekExt;
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
use tracing::{debug, error_span, trace};
|
use tower_http::trace::{DefaultOnFailure, DefaultOnResponse, OnFailure};
|
||||||
|
use tracing::{debug, error_span, trace, Span};
|
||||||
|
|
||||||
use axum::Router;
|
use axum::Router;
|
||||||
|
|
||||||
|
|
@ -572,17 +573,33 @@ impl HttpApi {
|
||||||
let app = app
|
let app = app
|
||||||
.layer(cors_layer)
|
.layer(cors_layer)
|
||||||
.layer(
|
.layer(
|
||||||
tower_http::trace::TraceLayer::new_for_http().make_span_with(|req: &Request| {
|
tower_http::trace::TraceLayer::new_for_http()
|
||||||
let method = req.method();
|
.make_span_with(|req: &Request| {
|
||||||
let uri = req.uri();
|
let method = req.method();
|
||||||
if let Some(ConnectInfo(addr)) =
|
let uri = req.uri();
|
||||||
req.extensions().get::<ConnectInfo<SocketAddr>>()
|
if let Some(ConnectInfo(addr)) =
|
||||||
{
|
req.extensions().get::<ConnectInfo<SocketAddr>>()
|
||||||
error_span!("request", %method, %uri, %addr)
|
{
|
||||||
} else {
|
error_span!("request", %method, %uri, %addr)
|
||||||
error_span!("request", %method, %uri)
|
} else {
|
||||||
}
|
error_span!("request", %method, %uri)
|
||||||
}),
|
}
|
||||||
|
})
|
||||||
|
.on_request(|req: &Request, _: &Span| {
|
||||||
|
if req.uri().path().starts_with("/upnp") {
|
||||||
|
debug!(headers=?req.headers())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on_response(DefaultOnResponse::new().include_headers(true))
|
||||||
|
.on_failure({
|
||||||
|
let mut default = DefaultOnFailure::new();
|
||||||
|
move |failure_class, latency, span: &Span| match failure_class {
|
||||||
|
tower_http::classify::ServerErrorsFailureClass::StatusCode(
|
||||||
|
StatusCode::NOT_IMPLEMENTED,
|
||||||
|
) => {}
|
||||||
|
_ => default.on_failure(failure_class, latency, span),
|
||||||
|
}
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
.into_make_service_with_connect_info::<SocketAddr>();
|
.into_make_service_with_connect_info::<SocketAddr>();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,10 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
async fn description_xml(State(state): State<UnpnServerState>) -> impl IntoResponse {
|
async fn description_xml(State(state): State<UnpnServerState>) -> impl IntoResponse {
|
||||||
state.rendered_root_description.clone()
|
(
|
||||||
|
[(CONTENT_TYPE, CONTENT_TYPE_XML_UTF8)],
|
||||||
|
state.rendered_root_description.clone(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn generate_content_directory_control_response(
|
async fn generate_content_directory_control_response(
|
||||||
|
|
@ -94,7 +97,6 @@ async fn subscription(
|
||||||
}
|
}
|
||||||
|
|
||||||
let (parts, _body) = request.into_parts();
|
let (parts, _body) = request.into_parts();
|
||||||
trace!(?parts.headers, "subscription request");
|
|
||||||
let is_event = parts
|
let is_event = parts
|
||||||
.headers
|
.headers
|
||||||
.get(HeaderName::from_static("nt"))
|
.get(HeaderName::from_static("nt"))
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,16 @@
|
||||||
<minor>0</minor>
|
<minor>0</minor>
|
||||||
</specVersion>
|
</specVersion>
|
||||||
<actionList>
|
<actionList>
|
||||||
|
<action>
|
||||||
|
<name>GetSystemUpdateID</name>
|
||||||
|
<argumentList>
|
||||||
|
<argument>
|
||||||
|
<name>Id</name>
|
||||||
|
<direction>out</direction>
|
||||||
|
<relatedStateVariable>SystemUpdateID</relatedStateVariable>
|
||||||
|
</argument>
|
||||||
|
</argumentList>
|
||||||
|
</action>
|
||||||
<action>
|
<action>
|
||||||
<name>Browse</name>
|
<name>Browse</name>
|
||||||
<argumentList>
|
<argumentList>
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
<serviceId>urn:upnp-org:serviceId:ConnectionManager</serviceId>
|
<serviceId>urn:upnp-org:serviceId:ConnectionManager</serviceId>
|
||||||
<SCPDURL>{http_prefix}/scpd/ConnectionManager.xml</SCPDURL>
|
<SCPDURL>{http_prefix}/scpd/ConnectionManager.xml</SCPDURL>
|
||||||
<controlURL>{http_prefix}/control/ConnectionManager</controlURL>
|
<controlURL>{http_prefix}/control/ConnectionManager</controlURL>
|
||||||
|
<eventSubURL>{http_prefix}/subscribe</eventSubURL>
|
||||||
</service>
|
</service>
|
||||||
</serviceList>
|
</serviceList>
|
||||||
<presentationURL>/</presentationURL>
|
<presentationURL>/</presentationURL>
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ use std::{
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
use tokio::sync::{broadcast::error::RecvError, Notify};
|
use tokio::sync::{broadcast::error::RecvError, Notify};
|
||||||
use tracing::{error_span, warn, Instrument};
|
use tracing::{debug, error_span, warn, Instrument};
|
||||||
|
|
||||||
pub struct Subscription {
|
pub struct Subscription {
|
||||||
pub url: url::Url,
|
pub url: url::Url,
|
||||||
|
|
@ -142,7 +142,7 @@ impl UpnpServerStateInner {
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
warn!(error=?e, "error updating UPNP subscription");
|
debug!(error=?e, "error updating UPNP subscription");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(RecvError::Lagged(by)) => {
|
Err(RecvError::Lagged(by)) => {
|
||||||
|
|
@ -158,7 +158,7 @@ impl UpnpServerStateInner {
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
warn!(error=?e, "error updating UPNP subscription");
|
debug!(error=?e, "error updating UPNP subscription");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(RecvError::Closed) => return Ok(()),
|
Err(RecvError::Closed) => return Ok(()),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue