mirror of
https://github.com/minio/minio-rs.git
synced 2026-01-26 17:42:08 +08:00
Use roxmltree for parsing
This commit is contained in:
parent
21f4de0540
commit
035fced940
@ -11,5 +11,5 @@ http = "0.1.17"
|
|||||||
hyper = "0.12.28"
|
hyper = "0.12.28"
|
||||||
hyper-tls = "0.3.2"
|
hyper-tls = "0.3.2"
|
||||||
ring = "0.14.6"
|
ring = "0.14.6"
|
||||||
|
roxmltree = "0.6.0"
|
||||||
time = "0.1.42"
|
time = "0.1.42"
|
||||||
xml-rs = "0.8.0"
|
|
||||||
|
|||||||
@ -159,7 +159,8 @@ impl Client {
|
|||||||
resp.into_body()
|
resp.into_body()
|
||||||
.concat2()
|
.concat2()
|
||||||
.map_err(|err| Err::HyperErr(err))
|
.map_err(|err| Err::HyperErr(err))
|
||||||
.and_then(move |chunk| xml::parse_bucket_location(chunk.into_bytes()))
|
.and_then(move |chunk| b2s(chunk.into_bytes()))
|
||||||
|
.and_then(|s| xml::parse_bucket_location(s))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use hyper::{body::Body, Response};
|
use hyper::{body::Body, Response};
|
||||||
|
use roxmltree;
|
||||||
use std::string;
|
use std::string;
|
||||||
use xml;
|
|
||||||
|
|
||||||
pub struct Region(String);
|
pub struct Region(String);
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ pub enum Err {
|
|||||||
HyperErr(hyper::Error),
|
HyperErr(hyper::Error),
|
||||||
FailStatusCodeErr(hyper::StatusCode, Bytes),
|
FailStatusCodeErr(hyper::StatusCode, Bytes),
|
||||||
Utf8DecodingErr(string::FromUtf8Error),
|
Utf8DecodingErr(string::FromUtf8Error),
|
||||||
XmlParseErr(xml::reader::Error),
|
XmlParseErr(roxmltree::Error),
|
||||||
UnexpectedEOF(String),
|
UnexpectedEOF(String),
|
||||||
RawSvcErr(hyper::StatusCode, Response<Body>),
|
RawSvcErr(hyper::StatusCode, Response<Body>),
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +1,17 @@
|
|||||||
use crate::minio::types::{Err, Region};
|
use crate::minio::types::{Err, Region};
|
||||||
use bytes::Bytes;
|
use roxmltree;
|
||||||
use xml::reader::{EventReader, XmlEvent};
|
|
||||||
|
|
||||||
pub fn parse_bucket_location(b: Bytes) -> Result<Region, Err> {
|
pub fn parse_bucket_location(s: String) -> Result<Region, Err> {
|
||||||
let mut reader = EventReader::new(b.as_ref());
|
let res = roxmltree::Document::parse(&s);
|
||||||
loop {
|
match res {
|
||||||
let event = reader.next();
|
Ok(doc) => {
|
||||||
match event {
|
let region_res = doc.root_element().text();
|
||||||
Err(err) => return Err(Err::XmlParseErr(err)),
|
if let Some(region) = region_res {
|
||||||
Ok(XmlEvent::EndDocument) => return Err(Err::UnexpectedEOF("xml parsing".to_string())),
|
Ok(Region::new(region))
|
||||||
Ok(XmlEvent::Characters(s)) => return Ok(Region::new(&s)),
|
} else {
|
||||||
_ => continue,
|
Ok(Region::empty())
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
Err(e) => Err(Err::XmlParseErr(e)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user