|
95 | 95 | //! use http::{Request, Response};
|
96 | 96 | //! use std::convert::TryInto as _;
|
97 | 97 | //! use std::error::Error;
|
98 |
| -//! use hyper::{client::HttpConnector, Body}; |
| 98 | +//! use http_body_util::{BodyExt, Full}; |
| 99 | +//! use hyper_util::{ |
| 100 | +//! client::legacy::{Client, connect::HttpConnector}, |
| 101 | +//! rt::tokio::TokioExecutor, |
| 102 | +//! }; |
99 | 103 | //!
|
100 | 104 | //! // `reqwest` is supported through a feature, if you prefer an
|
101 | 105 | //! // alternate http client you can add support by implementing `HttpClient` as
|
102 | 106 | //! // shown here.
|
103 | 107 | //! #[derive(Debug)]
|
104 |
| -//! struct HyperClient(hyper::Client<HttpConnector, Body>); |
| 108 | +//! struct HyperClient(Client<HttpConnector, Full<Bytes>>); |
105 | 109 | //!
|
106 | 110 | //! #[async_trait]
|
107 | 111 | //! impl HttpClient for HyperClient {
|
108 | 112 | //! async fn send(&self, req: Request<Vec<u8>>) -> Result<Response<Bytes>, HttpError> {
|
109 | 113 | //! let resp = self
|
110 | 114 | //! .0
|
111 |
| -//! .request(req.map(|v| Body::from(v))) |
| 115 | +//! .request(req.map(|v| Full::new(Bytes::from(v)))) |
112 | 116 | //! .await?;
|
113 | 117 | //!
|
114 | 118 | //! let response = Response::builder()
|
115 | 119 | //! .status(resp.status())
|
116 | 120 | //! .body({
|
117 |
| -//! hyper::body::to_bytes(resp.into_body()) |
| 121 | +//! resp.collect() |
118 | 122 | //! .await
|
119 | 123 | //! .expect("cannot decode response")
|
| 124 | +//! .to_bytes() |
120 | 125 | //! })
|
121 | 126 | //! .expect("cannot build response");
|
122 | 127 | //!
|
|
127 | 132 | //! fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
|
128 | 133 | //! global::set_text_map_propagator(opentelemetry_zipkin::Propagator::new());
|
129 | 134 | //! let tracer = opentelemetry_zipkin::new_pipeline()
|
130 |
| -//! .with_http_client(HyperClient(hyper::Client::new())) |
| 135 | +//! .with_http_client( |
| 136 | +//! HyperClient( |
| 137 | +//! Client::builder(TokioExecutor::new()) |
| 138 | +//! .build_http() |
| 139 | +//! ) |
| 140 | +//! ) |
131 | 141 | //! .with_service_name("my_app")
|
132 | 142 | //! .with_service_address("127.0.0.1:8080".parse()?)
|
133 | 143 | //! .with_collector_endpoint("http://localhost:9411/api/v2/spans")
|
|
0 commit comments