Skip to content

Commit

Permalink
Fix for 400 error, needs additional header to work successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe WOlfgrma authored and Joe WOlfgrma committed Jul 8, 2024
1 parent 1b1e6fd commit 467087d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion onvif/src/soap/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl Client {
"About to make request. auth_type={:?}, redirections={}", auth_type, redirections
);

let soap_msg = soap::soap(message, &username_token)
let soap_msg = soap::soap(message, &username_token, &uri)
.map_err(|e| Error::Protocol(format!("{:?}", e)))?;

let mut request = self
Expand Down
8 changes: 7 additions & 1 deletion onvif/src/soap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod tests;
use auth::username_token::UsernameToken;
use schema::soap_envelope;
use xmltree::{Element, Namespace, XMLNode};
use url::Url;

const SOAP_URI: &str = "http://www.w3.org/2003/05/soap-envelope";

Expand All @@ -24,11 +25,12 @@ pub struct Response {
pub response: Option<String>,
}

pub fn soap(xml: &str, username_token: &Option<UsernameToken>) -> Result<String, Error> {
pub fn soap(xml: &str, username_token: &Option<UsernameToken>, uri: &Url) -> Result<String, Error> {
let app_data = parse(xml)?;

let mut namespaces = app_data.namespaces.clone().unwrap_or_else(Namespace::empty);
namespaces.put("s", SOAP_URI);
namespaces.put("a", "http://www.w3.org/2005/08/addressing");

let mut body = Element::new("Body");
body.prefix = Some("s".to_string());
Expand All @@ -44,6 +46,10 @@ pub fn soap(xml: &str, username_token: &Option<UsernameToken>) -> Result<String,
header
.children
.push(XMLNode::Element(parse(&username_token.to_xml())?));
let mut to_el = Element::new("To");
to_el.prefix = Some("a".to_string());
to_el.children.push(XMLNode::Text(uri.as_str().to_owned()));
header.children.push(XMLNode::Element(to_el));
envelope.children.push(XMLNode::Element(header));
}

Expand Down

0 comments on commit 467087d

Please sign in to comment.