fn write(&mut self, data: &[u8]) -> Result<usize, WriteError> {
        log::trace!("received {} bytes of data", data.len());

        // Abort the request if it has been canceled.
        if self.shared.response_body_dropped.load() {
            return Ok(0);
        }

        // Now that we've started receiving the response body, we know no more
        // redirects can happen and we can complete the future safely.
        self.flush_response_headers();

        // Create a task context using a waker provided by the agent so we can
        // do an asynchronous write.
        if let Some(waker) = self.response_body_waker.as_ref() {
            let mut context = Context::from_waker(waker);

            match Pin::new(&mut self.response_body_writer).poll_write(&mut context, data) {
                Poll::Pending => Err(WriteError::Pause),
                Poll::Ready(Ok(len)) => Ok(len),
                Poll::Ready(Err(e)) => {
                    if e.kind() == io::ErrorKind::BrokenPipe {
                        log::warn!(
                            "failed to write response body because the response reader was dropped"
                        );
                    } else {
                        log::error!("error writing response body to buffer: {}", e);
                    }
                    Ok(0)
                }
            }
        } else {
            // The request should never be started without calling init first.
            log::error!("request has not been initialized!");
            Ok(0)
        }
    }
/// Gets called by curl when bytes from the response body are received.
Gets called by curl when bytes from the response body are received.
Gets called by curl when bytes from the response body are received .
fn write(&mut self, data: &[u8]) -> Result<usize, WriteError> {
        log::trace!("received {} bytes of data", data.len());
        // Abort the request if it has been canceled.
        if self.shared.response_body_dropped.load() {
            return Ok(0);
        }
        // Now that we've started receiving the response body, we know no more
        // redirects can happen and we can complete the future safely.
        self.flush_response_headers();
        // Create a task context using a waker provided by the agent so we can
        // do an asynchronous write.
        if let Some(waker) = self.response_body_waker.as_ref() {
            let mut context = Context::from_waker(waker);
            match Pin::new(&mut self.response_body_writer).poll_write(&mut context, data) {
                Poll::Pending => Err(WriteError::Pause),
                Poll::Ready(Ok(len)) => Ok(len),
                Poll::Ready(Err(e)) => {
                    if e.kind() == io::ErrorKind::BrokenPipe {
                        log::warn!(
                            "failed to write response body because the response reader was dropped"
                        );
                    } else {
                        log::error!("error writing response body to buffer: {}", e);
                    }
                    Ok(0)
                }
            }
        } else {
            // The request should never be started without calling init first.
            log::error!("request has not been initialized!");
            Ok(0)
        }
    }
fn write ( & mut self , data : & [ u8 ] ) -> Result < usize , WriteError > { log :: trace ! ( " " data len ( ) ) ; // Abort the request if it has been canceled. if self . shared . response_body_dropped . load ( ) { return Ok ( 0 ) ; } // Now that we've started receiving the response body, we know no more // redirects can happen and we can complete the future safely. self . flush_response_headers ( ) ; // Create a task context using a waker provided by the agent so we can // do an asynchronous write. if let Some ( waker ) = self . response_body_waker . as_ref ( ) { let mut context = Context :: from_waker ( waker ) ; match Pin :: new ( & mut self . response_body_writer ) . poll_write ( & mut context , data ) { Poll :: Pending => Err ( WriteError :: Pause ) , Poll :: Ready ( Ok ( len ) ) => Ok ( len ) , Poll :: Ready ( Err ( e ) ) => { if e . kind ( ) == io :: ErrorKind :: BrokenPipe { log :: warn ! ( " " ) ; } else { log :: error ! ( " " e ) ; } Ok ( 0 ) } } } else { // The request should never be started without calling init first. log :: error ! ( " " ) ; Ok ( 0 ) } }
Gets called by curl when bytes from the response body are received.
Gets called by curl when bytes from the response body are received .
&mut self
data
&[u8]