Skip to content

Commit

Permalink
Avoid endless loop when loading HTTP sources
Browse files Browse the repository at this point in the history
  • Loading branch information
mmarx committed Jul 10, 2023
1 parent b810af2 commit fa5545e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions nemo/src/io/resource_providers/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct HTTPResource {
/// IRI that this resource was fetched from
url: Resource,
/// Content of the resource
content: String,
content: Vec<u8>,
}

impl HTTPResource {
Expand All @@ -26,14 +26,17 @@ impl HTTPResource {
}

/// Return the content of this resource.
pub fn content(&self) -> &String {
&self.content
pub fn content(&self) -> String {
String::from_utf8(self.content.clone()).expect("is valid UTF-8")
}
}

impl Read for HTTPResource {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
self.content.as_bytes().read(buf)
let amount = self.content.as_slice().read(buf)?;
self.content.drain(0..amount);

Ok(amount)
}
}

Expand All @@ -44,7 +47,7 @@ impl HTTPResourceProvider {

Ok(HTTPResource {
url: url.to_string(),
content,
content: content.into(),
})
}
}
Expand Down

0 comments on commit fa5545e

Please sign in to comment.