Skip to content

Commit fca155b

Browse files
Joe WOlfgrmapicklejw
authored andcommitted
Fix for 400 error, needs additional header to work successfully
1 parent df12537 commit fca155b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

onvif/src/soap/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod tests;
66
use auth::username_token::UsernameToken;
77
use schema::soap_envelope;
88
use xmltree::{Element, Namespace, XMLNode};
9+
use url::Url;
910

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

@@ -24,11 +25,12 @@ pub struct Response {
2425
pub response: Option<String>,
2526
}
2627

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

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

3335
let mut body = Element::new("Body");
3436
body.prefix = Some("s".to_string());
@@ -44,6 +46,10 @@ pub fn soap(xml: &str, username_token: &Option<UsernameToken>) -> Result<String,
4446
header
4547
.children
4648
.push(XMLNode::Element(parse(&username_token.to_xml())?));
49+
let mut to_el = Element::new("To");
50+
to_el.prefix = Some("a".to_string());
51+
to_el.children.push(XMLNode::Text(uri.as_str().to_owned()));
52+
header.children.push(XMLNode::Element(to_el));
4753
envelope.children.push(XMLNode::Element(header));
4854
}
4955

0 commit comments

Comments
 (0)