-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix code coverage analysis in CI (#351)
Fix code coverage step in CI erroring. It seems like the primary issue here is Tarpaulin is trying to run doc tests annotated with `no_run`, which aren't necessarily designed to pass. Just disable doc tests in Tarpaulin to work around this since they don't contribute much to the overall code coverage anyway. I suspect a new Cargo or Rust version at some point caused this issue. See also xd009642/tarpaulin#848.
- Loading branch information
Showing
4 changed files
with
176 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use std::io::Cursor; | ||
|
||
use isahc::{Body, Request}; | ||
|
||
fn main() -> Result<(), isahc::Error> { | ||
let weird_request = Request::head("http://download.opensuse.org/update/tumbleweed/repodata/repomd.xml") | ||
.body(Body::from_reader(Cursor::new(b"")))?; | ||
|
||
let error = isahc::send(weird_request).unwrap_err(); | ||
eprintln!("{}", error); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use std::{error::Error, io, time::Duration}; | ||
|
||
use isahc::{ | ||
config::{Configurable, RedirectPolicy}, | ||
Request, | ||
RequestExt, | ||
}; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
env_logger::init(); | ||
|
||
read_url("https://tynan.com/feed/")?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn read_url(url: &str) -> Result<Vec<u8>, String> { | ||
let client = match Request::get(url) | ||
.timeout(Duration::from_secs(5)) | ||
.header("User-Agent", "el_monitorro/0.1.0") | ||
.redirect_policy(RedirectPolicy::Limit(10)) | ||
.body(()) | ||
{ | ||
Ok(cl) => cl, | ||
Err(er) => { | ||
let msg = format!("{:?}", er); | ||
|
||
return Err(msg); | ||
} | ||
}; | ||
|
||
match client.send() { | ||
Ok(mut response) => { | ||
let mut writer: Vec<u8> = vec![]; | ||
|
||
if let Err(err) = io::copy(response.body_mut(), &mut writer) { | ||
let msg = format!("{:?}", err); | ||
|
||
return Err(msg); | ||
} | ||
|
||
Ok(writer) | ||
} | ||
Err(error) => { | ||
let msg = format!("{:?}", error); | ||
|
||
Err(msg) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
use std::{io::{BufRead, BufReader, Read, Result}, net::TcpListener}; | ||
|
||
use httparse::parse_headers; | ||
|
||
pub(crate) struct Server { | ||
listener: TcpListener, | ||
} | ||
|
||
impl Server { | ||
pub(crate) fn accept(&mut self) -> Result<Connection> { | ||
let (stream, addr) = self.listener.accept()?; | ||
|
||
let mut reader = GrowableBufReader::new(stream); | ||
let mut headers = [httparse::EMPTY_HEADER; 16]; | ||
let mut request = httparse::Request::new(&mut headers); | ||
|
||
loop { | ||
reader.fill_buf_additional(8192)?; | ||
|
||
let result = request.parse(reader.buffer()); | ||
match result { | ||
Ok(httparse::Status::Partial) => continue, | ||
Ok(httparse::Status::Complete(offset)) => { | ||
reader.consume(offset); | ||
}, | ||
Err(_) => unimplemented!(), | ||
} | ||
} | ||
|
||
unimplemented!() | ||
} | ||
} | ||
|
||
pub(crate) struct Connection { | ||
|
||
} | ||
|
||
struct GrowableBufReader<R: Read> { | ||
inner: R, | ||
buffer: Vec<u8>, | ||
low: usize, | ||
high: usize, | ||
} | ||
|
||
impl<R: Read> GrowableBufReader<R> { | ||
fn new(inner: R) -> Self { | ||
Self { | ||
inner, | ||
buffer: Vec::with_capacity(8192), | ||
low: 0, | ||
high: 0, | ||
} | ||
} | ||
|
||
#[inline] | ||
fn available(&self) -> usize { | ||
self.high - self.low | ||
} | ||
|
||
#[inline] | ||
fn buffer(&self) -> &[u8] { | ||
&self.buffer[self.low..self.high] | ||
} | ||
|
||
fn fill_buf_additional(&mut self, max: usize) -> Result<usize> { | ||
self.reserve(max); | ||
let amt = self.inner.read(&mut self.buffer[self.high..])?; | ||
self.high += amt; | ||
|
||
Ok(amt) | ||
} | ||
|
||
fn reserve(&mut self, capacity: usize) { | ||
let desired_buffer_size = self.high + capacity; | ||
|
||
if self.buffer.len() < desired_buffer_size { | ||
self.buffer.resize(desired_buffer_size, 0); | ||
} | ||
} | ||
} | ||
|
||
impl<R: Read> BufRead for GrowableBufReader<R> { | ||
fn fill_buf(&mut self) -> Result<&[u8]> { | ||
if self.available() == 0 { | ||
self.fill_buf_additional(8192)?; | ||
} | ||
|
||
Ok(self.buffer()) | ||
} | ||
|
||
fn consume(&mut self, amt: usize) { | ||
if amt >= self.available() { | ||
self.low = 0; | ||
self.high = 0; | ||
self.buffer.clear(); | ||
} else { | ||
self.low += amt; | ||
} | ||
} | ||
} | ||
|
||
impl<R: Read> Read for GrowableBufReader<R> { | ||
fn read(&mut self, buf: &mut [u8]) -> Result<usize> { | ||
let src = self.fill_buf()?; | ||
let amt = buf.len().min(src.len()); | ||
buf[..amt].copy_from_slice(&src[..amt]); | ||
self.consume(amt); | ||
|
||
Ok(amt) | ||
} | ||
} |