-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
122 additions
and
9 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
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,51 @@ | ||
use crate::server::preclude::PixivDownloaderError; | ||
use hyper::body::HttpBody; | ||
use hyper::Body as _Body; | ||
use hyper::HeaderMap; | ||
use std::pin::Pin; | ||
use std::task::{Context, Poll}; | ||
|
||
pub struct HyperBody { | ||
_body: _Body, | ||
} | ||
|
||
impl HyperBody { | ||
pub fn empty() -> Self { | ||
Self { | ||
_body: _Body::empty(), | ||
} | ||
} | ||
} | ||
|
||
impl<T: Into<_Body>> From<T> for HyperBody { | ||
fn from(body: T) -> Self { | ||
Self { _body: body.into() } | ||
} | ||
} | ||
|
||
impl HttpBody for HyperBody { | ||
type Data = bytes::Bytes; | ||
type Error = PixivDownloaderError; | ||
|
||
fn poll_data( | ||
mut self: Pin<&mut Self>, | ||
cx: &mut Context<'_>, | ||
) -> Poll<Option<Result<Self::Data, Self::Error>>> { | ||
Pin::new(&mut self._body) | ||
.poll_data(cx) | ||
.map_err(PixivDownloaderError::from) | ||
} | ||
|
||
fn poll_trailers( | ||
mut self: Pin<&mut Self>, | ||
cx: &mut Context<'_>, | ||
) -> Poll<Result<Option<HeaderMap>, Self::Error>> { | ||
Pin::new(&mut self._body) | ||
.poll_trailers(cx) | ||
.map_err(PixivDownloaderError::from) | ||
} | ||
|
||
fn is_end_stream(&self) -> bool { | ||
self._body.is_end_stream() | ||
} | ||
} |
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,2 @@ | ||
pub mod hyper; | ||
pub mod response; |
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,42 @@ | ||
use crate::error::PixivDownloaderError; | ||
use hyper::body::HttpBody; | ||
use reqwest::Response; | ||
use std::future::Future; | ||
use std::pin::Pin; | ||
use std::task::{Context, Poll}; | ||
|
||
pub struct ResponseBody { | ||
res: Response, | ||
} | ||
|
||
impl ResponseBody { | ||
pub fn new(res: Response) -> Self { | ||
Self { res } | ||
} | ||
} | ||
|
||
impl HttpBody for ResponseBody { | ||
type Data = hyper::body::Bytes; | ||
type Error = PixivDownloaderError; | ||
|
||
fn poll_data( | ||
mut self: Pin<&mut Self>, | ||
cx: &mut Context<'_>, | ||
) -> Poll<Option<Result<Self::Data, Self::Error>>> { | ||
match Pin::new(&mut Box::pin(self.res.chunk())).poll(cx) { | ||
Poll::Ready(f) => match f { | ||
Ok(Some(data)) => Poll::Ready(Some(Ok(data))), | ||
Ok(None) => Poll::Ready(None), | ||
Err(e) => Poll::Ready(Some(Err(PixivDownloaderError::from(e)))), | ||
}, | ||
Poll::Pending => Poll::Pending, | ||
} | ||
} | ||
|
||
fn poll_trailers( | ||
self: Pin<&mut Self>, | ||
_cx: &mut Context<'_>, | ||
) -> Poll<Result<Option<hyper::HeaderMap>, Self::Error>> { | ||
Poll::Ready(Ok(None)) | ||
} | ||
} |
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
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
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