mysten_network/callback/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use http::{request, response, HeaderMap};

mod body;
mod future;
mod layer;
mod service;

pub use self::{
    body::ResponseBody, future::ResponseFuture, layer::CallbackLayer, service::Callback,
};

pub trait MakeCallbackHandler {
    type Handler: ResponseHandler;

    fn make_handler(&self, request: &request::Parts) -> Self::Handler;
}

pub trait ResponseHandler {
    fn on_response(&mut self, response: &response::Parts);
    fn on_error<E>(&mut self, error: &E)
    where
        E: std::fmt::Display + 'static;

    fn on_body_chunk<B>(&mut self, _chunk: &B)
    where
        B: bytes::Buf,
    {
        // do nothing
    }

    fn on_end_of_stream(&mut self, _trailers: Option<&HeaderMap>) {
        // do nothing
    }
}