diff --git a/Cargo.toml b/Cargo.toml index 66547b30..3624fb1e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,13 @@ [package] -name = "chttp" -version = "0.5.4" +name = "isahc" +version = "0.6.0" description = "The practical HTTP client that is fun to use." authors = ["Stephen M. Coakley "] license = "MIT" keywords = ["http", "request", "client", "async", "curl"] categories = ["web-programming::http-client"] -repository = "https://github.com/sagebind/chttp" -documentation = "https://docs.rs/chttp/" +repository = "https://github.com/sagebind/isahc" +documentation = "https://docs.rs/isahc/" readme = "README.md" edition = "2018" diff --git a/LICENSE b/LICENSE index 6552d1ff..bdc39b32 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017 Stephen M. Coakley +Copyright (c) 2019 Stephen M. Coakley Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 9fd7dd71..6e6d56b1 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -# cHTTP +# Isahc (formerly cHTTP) -The practical HTTP client that is fun to use. +Say hello to Isahc (pronounced like _Isaac_), the practical HTTP client that is fun to use. -[![Crates.io](https://img.shields.io/crates/v/chttp.svg)](https://crates.io/crates/chttp) -[![Documentation](https://docs.rs/chttp/badge.svg)][documentation] +[![Crates.io](https://img.shields.io/crates/v/isahc.svg)](https://crates.io/crates/isahc) +[![Documentation](https://docs.rs/isahc/badge.svg)][documentation] ![License](https://img.shields.io/badge/license-MIT-blue.svg) ## Key features @@ -19,18 +19,30 @@ The practical HTTP client that is fun to use. - Network socket configuration. - Uses the [http] crate as an interface for requests and responses. -## Why cHTTP and not X? + -cHTTP provides an easy-to-use, flexible, and idiomatic Rust API that makes sending HTTP requests a breeze. The goal of cHTTP is to make the easy way _also_ provide excellent performance and correctness for common use cases. +## What is Isahc? -cHTTP uses [libcurl] under the hood to handle the HTTP protocol and networking. Using curl as an engine for an HTTP client is a great choice for a few reasons: +Isahc is an acronym that stands for **I**ncredible **S**treaming **A**synchronous **H**TTP **C**lient, and as the name implies, is an asynchronous HTTP client for the [Rust] language. It uses [libcurl] as an HTTP engine inside, and provides an easy-to-use API on top that integrates with Rust idioms. + +## No, _who_ is Isahc? + +Oh, you mean Isahc the dog! He's an adorable little Siberian husky who loves to play fetch with webservers every day and has a very _cURLy_ tail. He shares a name with the project and acts as the project's mascot. + +You can pet him all day if you like, he doesn't mind. Though, he prefers it if you pet him in a standards-compliant way! + +## Why use Isahc and not X? + +Isahc provides an easy-to-use, flexible, and idiomatic Rust API that makes sending HTTP requests a breeze. The goal of Isahc is to make the easy way _also_ provide excellent performance and correctness for common use cases. + +Isahc uses [libcurl] under the hood to handle the HTTP protocol and networking. Using curl as an engine for an HTTP client is a great choice for a few reasons: - It is a stable, actively developed, and very popular library. - It is well-supported on a diverse list of platforms. - The HTTP protocol has a lot of unexpected gotchas across different servers, and curl has been around the block long enough to handle many of them. - It is well optimized and offers the ability to implement asynchronous requests. -Safe Rust bindings to libcurl are provided by the [curl](https://crates.io/crates/curl) crate, which you can use yourself if you want to use curl directly. cHTTP delivers a lot of value on top of vanilla curl, by offering a simpler, more idiomatic API and doing the hard work of turning the powerful [multi interface] into a futures-based API. +Safe Rust bindings to libcurl are provided by the [curl](https://crates.io/crates/curl) crate, which you can use yourself if you want to use curl directly. Isahc delivers a lot of value on top of vanilla curl, by offering a simpler, more idiomatic API and doing the hard work of turning the powerful [multi interface] into a futures-based API. ## Installation @@ -38,23 +50,23 @@ Install via Cargo by adding to your `Cargo.toml` file: ```toml [dependencies] -chttp = "0.5" +isahc = "0.6" ``` ### Supported Rust versions -The current release is only guaranteed to work with the latest stable Rust compiler. When cHTTP reaches version `1.0`, a more conservative policy will be adopted. +The current release is only guaranteed to work with the latest stable Rust compiler. When Isahc reaches version `1.0`, a more conservative policy will be adopted. ### Feature flags -cHTTP is designed to be as "pay-as-you-need" as possible using Cargo feature +Isahc is designed to be as "pay-as-you-need" as possible using Cargo feature flags and optional dependencies. Unstable features are also initially released behind feature flags until they are stabilized. You can add the feature names below to your `Cargo.toml` file to enable them: ```toml -[dependencies.chttp] -version = "0.5" +[dependencies.isahc] +version = "0.6" features = ["psl"] ``` @@ -69,13 +81,13 @@ Below is a list of all available feature flags and their meanings. ## [Documentation] -Please check out the [documentation] for details on what cHTTP can do and how to use it. +Please check out the [documentation] for details on what Isahc can do and how to use it. To get you started, here is a really simple example that spits out the response body from https://example.org: ```rust // Send a GET request and wait for the response. -let mut response = chttp::get("https://example.org")? +let mut response = isahc::get("https://example.org")? // Read the response body into a string and print it to standard output. let body = response.body_mut().text()?; println!("{}", body); @@ -83,12 +95,15 @@ println!("{}", body); ## License -This library is licensed under the MIT license. See the [LICENSE](LICENSE) file for details. +This project's source code and documentation is licensed under the MIT license. See the [LICENSE](LICENSE) file for details. + +The "Isahc" logo and mascot may only be used as required for reasonable and customary use in describing the Isahc project and in redistribution of the project. [async/await]: https://rust-lang.github.io/async-book/01_getting_started/04_async_await_primer.html -[documentation]: https://docs.rs/chttp +[documentation]: https://docs.rs/isahc [http]: https://github.com/hyperium/http [libcurl]: https://curl.haxx.se/libcurl/ [multi interface]: https://curl.haxx.se/libcurl/c/libcurl-multi.html +[rust]: https://www.rustlang.org [serde]: https://serde.rs diff --git a/benchmarks/Cargo.toml b/benchmarks/Cargo.toml index eef96371..3760e9f3 100644 --- a/benchmarks/Cargo.toml +++ b/benchmarks/Cargo.toml @@ -1,10 +1,10 @@ [package] -name = "chttp-benchmarks" +name = "isahc-benchmarks" version = "0.0.0" edition = "2018" publish = false -[dependencies.chttp] +[dependencies.isahc] path = ".." [dev-dependencies] diff --git a/benchmarks/benches/download.rs b/benchmarks/benches/download.rs index 117dbbec..b83890cc 100644 --- a/benchmarks/benches/download.rs +++ b/benchmarks/benches/download.rs @@ -33,14 +33,14 @@ fn benchmark(c: &mut Criterion) { ) }); - c.bench_function("download 64K: chttp", move |b| { + c.bench_function("download 64K: isahc", move |b| { use std::io::Read; let server = server::spawn(|_| server::static_response(&DATA)); let endpoint = server.endpoint(); b.iter_batched( - || chttp::Client::new(), + || isahc::Client::new(), |client| { let mut body = Vec::new(); diff --git a/examples/async.rs b/examples/async.rs index af5b9378..beff6fd3 100644 --- a/examples/async.rs +++ b/examples/async.rs @@ -3,9 +3,9 @@ #![cfg(feature = "nightly")] #![feature(async_await)] -use chttp::prelude::*; +use isahc::prelude::*; -fn main() -> Result<(), chttp::Error> { +fn main() -> Result<(), isahc::Error> { futures::executor::block_on(async { let mut response = Request::get("http://example.org") .body(())? diff --git a/examples/http2.rs b/examples/http2.rs index 0aa26ae7..77a9fa05 100644 --- a/examples/http2.rs +++ b/examples/http2.rs @@ -1,11 +1,11 @@ -use chttp::prelude::*; +use isahc::prelude::*; -fn main() -> Result<(), chttp::Error> { +fn main() -> Result<(), isahc::Error> { let response = Request::get("https://nghttp2.org") - .preferred_http_version(chttp::http::Version::HTTP_2) + .preferred_http_version(isahc::http::Version::HTTP_2) .body(()) .map_err(Into::into) - .and_then(chttp::send)?; + .and_then(isahc::send)?; println!("{:?}", response.headers()); diff --git a/examples/parallel_requests.rs b/examples/parallel_requests.rs index 506a9cc6..7bc1060a 100644 --- a/examples/parallel_requests.rs +++ b/examples/parallel_requests.rs @@ -1,14 +1,14 @@ -//! In this example, we demonstrate cHTTP's ability to run many requests +//! In this example, we demonstrate Isahc's ability to run many requests //! simultaneously with no extra cost. Concurrent requests may be made in the //! same thread, or from different threads as in this example. //! //! We're using Rayon here to make parallelism easy. -use chttp::prelude::*; +use isahc::prelude::*; use rayon::prelude::*; use std::env; use std::time::Instant; -fn main() -> Result<(), chttp::Error> { +fn main() -> Result<(), isahc::Error> { let count = env::args() .nth(1) .and_then(|s| s.parse::().ok()) diff --git a/examples/simple.rs b/examples/simple.rs index 1357dae2..6859e923 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -1,6 +1,6 @@ -use chttp::prelude::*; +use isahc::prelude::*; -fn main() -> Result<(), chttp::Error> { +fn main() -> Result<(), isahc::Error> { let client = HttpClient::new(); let mut response = client.get("http://example.org")?; diff --git a/examples/version.rs b/examples/version.rs index e42e334c..c83a2f6f 100644 --- a/examples/version.rs +++ b/examples/version.rs @@ -1,8 +1,8 @@ -//! A simple example that prints the version of chttp and libcurl being used. +//! A simple example that prints the version of isahc and libcurl being used. //! //! This example is useful to run on various systems when troubleshooting //! version-related issues. fn main() { - println!("version: {}", chttp::version()); + println!("version: {}", isahc::version()); } diff --git a/media/isahc.svg b/media/isahc.svg new file mode 100644 index 00000000..786c27a3 --- /dev/null +++ b/media/isahc.svg @@ -0,0 +1,243 @@ + + + + + Isahc + + + + + + + + + + + + + + + + + + + image/svg+xml + + Isahc + + + Stephen M. Coakley + + + Mascot for the Isahc project. + + + + (c) Stephen M. Coakley + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/media/isahc.svg.png b/media/isahc.svg.png new file mode 100644 index 00000000..f3582e3b Binary files /dev/null and b/media/isahc.svg.png differ diff --git a/src/body.rs b/src/body.rs index 25331083..6539d9fb 100644 --- a/src/body.rs +++ b/src/body.rs @@ -18,7 +18,7 @@ use std::task::{Context, Poll}; /// types of sources using the [`Into`](std::convert::Into) trait or one of its /// constructor functions. /// -/// Since the entire request life-cycle in cHTTP is asynchronous, bodies must +/// Since the entire request life-cycle in Isahc is asynchronous, bodies must /// also be asynchronous. You can create a body from anything that implements /// [`AsyncRead`], which [`Body`] itself also implements. pub struct Body(Inner); diff --git a/src/client.rs b/src/client.rs index ae034052..55e1c8b2 100644 --- a/src/client.rs +++ b/src/client.rs @@ -17,7 +17,7 @@ use std::time::Duration; lazy_static! { static ref USER_AGENT: String = format!( - "curl/{} chttp/{}", + "curl/{} isahc/{}", curl::Version::get().version(), env!("CARGO_PKG_VERSION") ); @@ -29,9 +29,9 @@ lazy_static! { /// # Examples /// /// ``` -/// use chttp::config::RedirectPolicy; -/// use chttp::http; -/// use chttp::prelude::*; +/// use isahc::config::RedirectPolicy; +/// use isahc::http; +/// use isahc::prelude::*; /// use std::time::Duration; /// /// let client = HttpClient::builder() @@ -39,7 +39,7 @@ lazy_static! { /// .redirect_policy(RedirectPolicy::Limit(10)) /// .preferred_http_version(http::Version::HTTP_2) /// .build()?; -/// # Ok::<(), chttp::Error>(()) +/// # Ok::<(), isahc::Error>(()) /// ``` #[derive(Default)] pub struct HttpClientBuilder { @@ -195,8 +195,8 @@ impl HttpClientBuilder { /// # Examples /// /// ``` - /// # use chttp::config::*; - /// # use chttp::prelude::*; + /// # use isahc::config::*; + /// # use isahc::prelude::*; /// # /// let client = HttpClient::builder() /// .ssl_client_certificate(ClientCertificate::PEM { @@ -207,7 +207,7 @@ impl HttpClientBuilder { /// }), /// }) /// .build()?; - /// # Ok::<(), chttp::Error>(()) + /// # Ok::<(), isahc::Error>(()) /// ``` pub fn ssl_client_certificate(mut self, certificate: ClientCertificate) -> Self { self.defaults.insert(certificate); @@ -263,7 +263,7 @@ impl fmt::Debug for HttpClientBuilder { /// # Examples /// /// ```no_run -/// use chttp::prelude::*; +/// use isahc::prelude::*; /// /// // Create a new client using reasonable defaults. /// let client = HttpClient::default(); @@ -273,13 +273,13 @@ impl fmt::Debug for HttpClientBuilder { /// assert!(response.status().is_success()); /// /// println!("Response:\n{}", response.text()?); -/// # Ok::<(), chttp::Error>(()) +/// # Ok::<(), isahc::Error>(()) /// ``` /// /// Customizing the client configuration: /// /// ```no_run -/// use chttp::{config::RedirectPolicy, prelude::*}; +/// use isahc::{config::RedirectPolicy, prelude::*}; /// use std::time::Duration; /// /// let client = HttpClient::builder() @@ -292,7 +292,7 @@ impl fmt::Debug for HttpClientBuilder { /// /// let response = client.get("https://example.org")?; /// assert!(response.status().is_success()); -/// # Ok::<(), chttp::Error>(()) +/// # Ok::<(), isahc::Error>(()) /// ``` /// /// See the documentation on [`HttpClientBuilder`] for a comprehensive look at @@ -356,12 +356,12 @@ impl HttpClient { /// # Examples /// /// ```no_run - /// use chttp::prelude::*; + /// use isahc::prelude::*; /// /// # let client = HttpClient::default(); /// let mut response = client.get("https://example.org")?; /// println!("{}", response.text()?); - /// # Ok::<(), chttp::Error>(()) + /// # Ok::<(), isahc::Error>(()) /// ``` #[inline] pub fn get(&self, uri: U) -> Result, Error> @@ -390,11 +390,11 @@ impl HttpClient { /// # Examples /// /// ```no_run - /// # use chttp::prelude::*; + /// # use isahc::prelude::*; /// # let client = HttpClient::default(); /// let response = client.head("https://example.org")?; /// println!("Page size: {:?}", response.headers()["content-length"]); - /// # Ok::<(), chttp::Error>(()) + /// # Ok::<(), isahc::Error>(()) /// ``` #[inline] pub fn head(&self, uri: U) -> Result, Error> @@ -423,7 +423,7 @@ impl HttpClient { /// # Examples /// /// ```no_run - /// use chttp::prelude::*; + /// use isahc::prelude::*; /// /// let client = HttpClient::default(); /// @@ -431,7 +431,7 @@ impl HttpClient { /// "speed": "fast", /// "cool_name": true /// }"#)?; - /// # Ok::<(), chttp::Error>(()) + /// # Ok::<(), isahc::Error>(()) #[inline] pub fn post(&self, uri: U, body: impl Into) -> Result, Error> where @@ -460,7 +460,7 @@ impl HttpClient { /// # Examples /// /// ```no_run - /// use chttp::prelude::*; + /// use isahc::prelude::*; /// /// let client = HttpClient::default(); /// @@ -468,7 +468,7 @@ impl HttpClient { /// "speed": "fast", /// "cool_name": true /// }"#)?; - /// # Ok::<(), chttp::Error>(()) + /// # Ok::<(), isahc::Error>(()) /// ``` #[inline] pub fn put(&self, uri: U, body: impl Into) -> Result, Error> @@ -542,7 +542,7 @@ impl HttpClient { /// # Examples /// /// ```no_run - /// use chttp::prelude::*; + /// use isahc::prelude::*; /// /// let client = HttpClient::default(); /// @@ -555,7 +555,7 @@ impl HttpClient { /// /// let response = client.send(request)?; /// assert!(response.status().is_success()); - /// # Ok::<(), chttp::Error>(()) + /// # Ok::<(), isahc::Error>(()) /// ``` #[inline] pub fn send>(&self, request: Request) -> Result, Error> { @@ -569,7 +569,7 @@ impl HttpClient { /// # Examples /// /// ```ignore - /// use chttp::prelude::*; + /// use isahc::prelude::*; /// /// let client = HttpClient::default(); /// diff --git a/src/error.rs b/src/error.rs index 4b0d5ece..ff614c7b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -4,7 +4,7 @@ use std::error::Error as StdError; use std::fmt; use std::io; -/// All possible types of errors that can be returned from cHTTP. +/// All possible types of errors that can be returned from Isahc. #[derive(Debug)] pub enum Error { /// The request was aborted before it could be completed. diff --git a/src/handler.rs b/src/handler.rs index f85f06d5..7c435210 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -318,13 +318,13 @@ impl curl::easy::Handler for RequestHandler { match kind { InfoType::Text => { - log::debug!(target: "chttp::curl", "{}", String::from_utf8_lossy(data).trim_end()) + log::debug!(target: "isahc::curl", "{}", String::from_utf8_lossy(data).trim_end()) } InfoType::HeaderIn | InfoType::DataIn => { - log::trace!(target: "chttp::wire", "<< {}", format_byte_string(data)) + log::trace!(target: "isahc::wire", "<< {}", format_byte_string(data)) } InfoType::HeaderOut | InfoType::DataOut => { - log::trace!(target: "chttp::wire", ">> {}", format_byte_string(data)) + log::trace!(target: "isahc::wire", ">> {}", format_byte_string(data)) } _ => (), } diff --git a/src/lib.rs b/src/lib.rs index 14f64d20..7c3205fc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,6 @@ //! The practical HTTP client that is fun to use. //! -//! Here are some of cHTTP's key features: +//! Here are some of Isahc's key features: //! //! - Full support for HTTP/1.1 and HTTP/2. //! - Configurable request timeouts. @@ -17,11 +17,11 @@ //! simple GET request to an example website: //! //! ```no_run -//! use chttp::prelude::*; +//! use isahc::prelude::*; //! -//! let mut response = chttp::get("https://example.org")?; +//! let mut response = isahc::get("https://example.org")?; //! println!("{}", response.text()?); -//! # Ok::<(), chttp::Error>(()) +//! # Ok::<(), isahc::Error>(()) //! ``` //! //! By default, sending a request will wait for the response, up until the @@ -32,17 +32,17 @@ //! the request body: //! //! ```no_run -//! let response = chttp::post("https://httpbin.org/post", "make me a salad")?; -//! # Ok::<(), chttp::Error>(()) +//! let response = isahc::post("https://httpbin.org/post", "make me a salad")?; +//! # Ok::<(), isahc::Error>(()) //! ``` //! -//! cHTTP provides several other simple functions for common HTTP request types: +//! Isahc provides several other simple functions for common HTTP request types: //! //! ```no_run -//! chttp::put("https://httpbin.org/put", "have a salad")?; -//! chttp::head("https://httpbin.org/get")?; -//! chttp::delete("https://httpbin.org/delete")?; -//! # Ok::<(), chttp::Error>(()) +//! isahc::put("https://httpbin.org/put", "have a salad")?; +//! isahc::head("https://httpbin.org/get")?; +//! isahc::delete("https://httpbin.org/delete")?; +//! # Ok::<(), isahc::Error>(()) //! ``` //! //! If you want to customize the request by adding headers, setting timeouts, @@ -51,7 +51,7 @@ //! [`send`][RequestExt::send]: //! //! ```no_run -//! use chttp::prelude::*; +//! use isahc::prelude::*; //! use std::time::Duration; //! //! let response = Request::post("https://httpbin.org/post") @@ -62,7 +62,7 @@ //! "cool_name": true //! }"#)? //! .send()?; -//! # Ok::<(), chttp::Error>(()) +//! # Ok::<(), isahc::Error>(()) //! ``` //! //! Check out the [examples] directory in the project sources for even more @@ -70,7 +70,7 @@ //! //! # Feature tour //! -//! Below is a brief overview of some notable features of cHTTP. Check out the +//! Below is a brief overview of some notable features of Isahc. Check out the //! rest of the documentation for even more guides and examples. //! //! ## Easy request functions @@ -83,7 +83,7 @@ //! //! ## Request and response traits //! -//! cHTTP includes a number of traits in the [`prelude`] module that extend the +//! Isahc includes a number of traits in the [`prelude`] module that extend the //! [`Request`] and [`Response`] types with a plethora of extra methods that //! make common tasks convenient and allow you to make more advanced //! configuration. @@ -113,23 +113,23 @@ //! first example rewritten to use async/await syntax (nightly Rust only): //! //! ```ignore -//! use chttp::prelude::*; +//! use isahc::prelude::*; //! -//! let mut response = chttp::get_async("https://httpbin.org/get").await?; +//! let mut response = isahc::get_async("https://httpbin.org/get").await?; //! println!("{}", response.text_async().await?); //! ``` //! //! # Logging //! -//! cHTTP logs quite a bit of useful information at various levels using the +//! Isahc logs quite a bit of useful information at various levels using the //! [log] crate. //! -//! If you set the log level to `Trace` for the `chttp::wire` target, cHTTP will +//! If you set the log level to `Trace` for the `isahc::wire` target, Isahc will //! also log all incoming and outgoing data while in flight. This may come in //! handy if you are debugging code and need to see the exact data being sent to //! the server and being received. //! -//! [examples]: https://github.com/sagebind/chttp/tree/master/examples +//! [examples]: https://github.com/sagebind/isahc/tree/master/examples //! [log]: https://docs.rs/log #![deny(unsafe_code)] @@ -178,7 +178,7 @@ pub use crate::{ /// Re-export of the standard HTTP types. pub use http; -/// A "prelude" for importing common cHTTP types. +/// A "prelude" for importing common Isahc types. pub mod prelude { pub use crate::{ Body, @@ -319,17 +319,17 @@ pub fn send_async>(request: Request) -> ResponseFuture<'static> HttpClient::shared().send_async(request) } -/// Gets a human-readable string with the version number of cHTTP and its +/// Gets a human-readable string with the version number of Isahc and its /// dependencies. /// -/// This function can be helpful when troubleshooting issues in cHTTP or one of +/// This function can be helpful when troubleshooting issues in Isahc or one of /// its dependencies. pub fn version() -> &'static str { static FEATURES_STRING: &str = include_str!(concat!(env!("OUT_DIR"), "/features.txt")); lazy_static! { static ref VERSION_STRING: String = format!( - "chttp/{} (features:{}) {}", + "isahc/{} (features:{}) {}", env!("CARGO_PKG_VERSION"), FEATURES_STRING, curl::Version::num(), diff --git a/src/request.rs b/src/request.rs index 1c9cce9a..a3d1d71d 100644 --- a/src/request.rs +++ b/src/request.rs @@ -17,7 +17,7 @@ pub trait RequestBuilderExt { /// # Examples /// /// ```no_run - /// use chttp::prelude::*; + /// use isahc::prelude::*; /// use std::time::Duration; /// /// // This page is too slow and won't respond in time. @@ -26,7 +26,7 @@ pub trait RequestBuilderExt { /// .body(())? /// .send() /// .expect_err("page should time out"); - /// # Ok::<(), chttp::Error>(()) + /// # Ok::<(), isahc::Error>(()) /// ``` fn timeout(&mut self, timeout: Duration) -> &mut Self; @@ -42,8 +42,8 @@ pub trait RequestBuilderExt { /// # Examples /// /// ```no_run - /// use chttp::config::RedirectPolicy; - /// use chttp::prelude::*; + /// use isahc::config::RedirectPolicy; + /// use isahc::prelude::*; /// /// // This URL redirects us to where we want to go. /// let response = Request::get("https://httpbin.org/redirect/1") @@ -57,7 +57,7 @@ pub trait RequestBuilderExt { /// .body(())? /// .send() /// .expect_err("too many redirects"); - /// # Ok::<(), chttp::Error>(()) + /// # Ok::<(), isahc::Error>(()) /// ``` fn redirect_policy(&mut self, policy: RedirectPolicy) -> &mut Self; @@ -131,8 +131,8 @@ pub trait RequestBuilderExt { /// # Examples /// /// ```no_run - /// use chttp::config::{ClientCertificate, PrivateKey}; - /// use chttp::prelude::*; + /// use isahc::config::{ClientCertificate, PrivateKey}; + /// use isahc::prelude::*; /// /// let response = Request::get("localhost:3999") /// .ssl_client_certificate(ClientCertificate::PEM { @@ -144,7 +144,7 @@ pub trait RequestBuilderExt { /// }) /// .body(())? /// .send()?; - /// # Ok::<(), chttp::Error>(()) + /// # Ok::<(), isahc::Error>(()) /// ``` fn ssl_client_certificate(&mut self, certificate: ClientCertificate) -> &mut Self; } @@ -213,7 +213,7 @@ pub trait RequestExt { /// # Examples /// /// ```no_run - /// use chttp::prelude::*; + /// use isahc::prelude::*; /// /// let response = Request::post("https://httpbin.org/post") /// .header("Content-Type", "application/json") @@ -222,7 +222,7 @@ pub trait RequestExt { /// "cool_name": true /// }"#)? /// .send()?; - /// # Ok::<(), chttp::Error>(()) + /// # Ok::<(), isahc::Error>(()) /// ``` fn send(self) -> Result, Error> where diff --git a/src/response.rs b/src/response.rs index 729286d4..c47e6361 100644 --- a/src/response.rs +++ b/src/response.rs @@ -25,11 +25,11 @@ pub trait ResponseExt { /// # Examples /// /// ```no_run - /// use chttp::prelude::*; + /// use isahc::prelude::*; /// - /// chttp::get("https://httpbin.org/image/jpeg")? + /// isahc::get("https://httpbin.org/image/jpeg")? /// .copy_to_file("myimage.jpg")?; - /// # Ok::<(), chttp::Error>(()) + /// # Ok::<(), isahc::Error>(()) /// ``` fn copy_to_file(&mut self, path: impl AsRef) -> io::Result where @@ -46,11 +46,11 @@ pub trait ResponseExt { /// # Examples /// /// ```no_run - /// use chttp::prelude::*; + /// use isahc::prelude::*; /// - /// let text = chttp::get("https://example.org")?.text()?; + /// let text = isahc::get("https://example.org")?.text()?; /// println!("{}", text); - /// # Ok::<(), chttp::Error>(()) + /// # Ok::<(), isahc::Error>(()) /// ``` fn text(&mut self) -> Result where @@ -69,10 +69,10 @@ pub trait ResponseExt { /// # Examples /// /// ```no_run - /// use chttp::prelude::*; + /// use isahc::prelude::*; /// use serde_json::Value; /// - /// let json: Value = chttp::get("https://httpbin.org/json")?.json()?; + /// let json: Value = isahc::get("https://httpbin.org/json")?.json()?; /// println!("author: {}", json["slideshow"]["author"]); /// # Ok::<(), Box>(()) /// ``` diff --git a/tests/headers.rs b/tests/headers.rs index f51e10df..7dc1da32 100644 --- a/tests/headers.rs +++ b/tests/headers.rs @@ -11,17 +11,17 @@ speculate::speculate! { .match_header("accept-encoding", "deflate, gzip") .create(); - chttp::get(server_url()).unwrap(); + isahc::get(server_url()).unwrap(); m.assert(); } test "user agent contains expected format" { let m = mock("GET", "/") - .match_header("user-agent", Matcher::Regex(r"^curl/\S+ chttp/\S+$".into())) + .match_header("user-agent", Matcher::Regex(r"^curl/\S+ isahc/\S+$".into())) .create(); - chttp::get(server_url()).unwrap(); + isahc::get(server_url()).unwrap(); m.assert(); } diff --git a/tests/methods.rs b/tests/methods.rs index 05eb8f71..7376b7f9 100644 --- a/tests/methods.rs +++ b/tests/methods.rs @@ -1,4 +1,4 @@ -use chttp::prelude::*; +use isahc::prelude::*; use mockito::{mock, server_url}; speculate::speculate! { @@ -9,7 +9,7 @@ speculate::speculate! { test "GET request" { let m = mock("GET", "/").create(); - chttp::get(server_url()).unwrap(); + isahc::get(server_url()).unwrap(); m.assert(); } @@ -17,7 +17,7 @@ speculate::speculate! { test "HEAD request" { let m = mock("HEAD", "/").create(); - chttp::head(server_url()).unwrap(); + isahc::head(server_url()).unwrap(); m.assert(); } @@ -25,7 +25,7 @@ speculate::speculate! { test "POST request" { let m = mock("POST", "/").create(); - chttp::post(server_url(), ()).unwrap(); + isahc::post(server_url(), ()).unwrap(); m.assert(); } @@ -33,7 +33,7 @@ speculate::speculate! { test "PUT request" { let m = mock("PUT", "/").create(); - chttp::put(server_url(), ()).unwrap(); + isahc::put(server_url(), ()).unwrap(); m.assert(); } @@ -41,7 +41,7 @@ speculate::speculate! { test "DELETE request" { let m = mock("DELETE", "/").create(); - chttp::delete(server_url()).unwrap(); + isahc::delete(server_url()).unwrap(); m.assert(); } diff --git a/tests/redirects.rs b/tests/redirects.rs index 8fec7e3c..27e59884 100644 --- a/tests/redirects.rs +++ b/tests/redirects.rs @@ -1,5 +1,5 @@ -use chttp::config::RedirectPolicy; -use chttp::prelude::*; +use isahc::config::RedirectPolicy; +use isahc::prelude::*; use mockito::{mock, server_url}; speculate::speculate! { @@ -13,7 +13,7 @@ speculate::speculate! { .with_header("Location", "/2") .create(); - let response = chttp::get(server_url()).unwrap(); + let response = isahc::get(server_url()).unwrap(); assert_eq!(response.status(), 301); assert_eq!(response.headers()["Location"], "/2"); @@ -113,7 +113,7 @@ speculate::speculate! { // Request should error with too many redirects. assert!(match result { - Err(chttp::Error::TooManyRedirects) => true, + Err(isahc::Error::TooManyRedirects) => true, _ => false, }); diff --git a/tests/request_body.rs b/tests/request_body.rs index 8d16e241..b7bd3498 100644 --- a/tests/request_body.rs +++ b/tests/request_body.rs @@ -1,5 +1,5 @@ -use chttp::prelude::*; -use chttp::Body; +use isahc::prelude::*; +use isahc::Body; use mockito::{mock, server_url}; speculate::speculate! { diff --git a/tests/response_body.rs b/tests/response_body.rs index 14007c34..e4adc5d1 100644 --- a/tests/response_body.rs +++ b/tests/response_body.rs @@ -10,7 +10,7 @@ speculate::speculate! { .with_body("hello world") .create(); - let mut response = chttp::get(server_url()).unwrap(); + let mut response = isahc::get(server_url()).unwrap(); let response_text = response.body_mut().text().unwrap(); assert_eq!(response_text, "hello world"); @@ -24,7 +24,7 @@ speculate::speculate! { .with_body(&body) .create(); - let mut response = chttp::get(server_url()).unwrap(); + let mut response = isahc::get(server_url()).unwrap(); let response_text = response.body_mut().text().unwrap(); assert_eq!(response_text, body); @@ -36,7 +36,7 @@ speculate::speculate! { .with_body("hello world") .create(); - let response = chttp::get(server_url()).unwrap(); + let response = isahc::get(server_url()).unwrap(); assert_eq!(response.body().len(), Some(11)); m.assert(); @@ -47,7 +47,7 @@ speculate::speculate! { .with_body_from_fn(|w| w.write_all(b"hello world")) .create(); - let response = chttp::get(server_url()).unwrap(); + let response = isahc::get(server_url()).unwrap(); assert_eq!(response.body().len(), None); m.assert(); diff --git a/tests/status.rs b/tests/status.rs index ab16d225..026e19ad 100644 --- a/tests/status.rs +++ b/tests/status.rs @@ -11,7 +11,7 @@ speculate::speculate! { .with_status(*status as usize) .create(); - let response = chttp::get(server_url()).unwrap(); + let response = isahc::get(server_url()).unwrap(); assert_eq!(response.status(), *status); m.assert(); diff --git a/tests/timeouts.rs b/tests/timeouts.rs index 0337492d..80eaf4fa 100644 --- a/tests/timeouts.rs +++ b/tests/timeouts.rs @@ -1,4 +1,4 @@ -use chttp::prelude::*; +use isahc::prelude::*; use mockito::{mock, server_url}; use std::thread::sleep; use std::time::Duration; @@ -27,7 +27,7 @@ speculate::speculate! { // Client should time-out. match result { - Err(chttp::Error::Timeout) => {} + Err(isahc::Error::Timeout) => {} e => { panic!("expected timeout error, got {:?}", e); }