http-body-0.1.0/.gitignore010064400007650000024000000000221346407272600136360ustar0000000000000000target Cargo.lock http-body-0.1.0/azure-pipelines.yml010064400007650000024000000003111346407272600155060ustar0000000000000000trigger: ["master"] pr: ["master"] jobs: # Check formatting - job: rustfmt pool: vmImage: ubuntu-16.04 steps: - template: ci/azure-rustfmt.yml # Run tests - template: ci/azure-test-all.yml http-body-0.1.0/Cargo.toml.orig010064400007650000024000000013771346434062400145460ustar0000000000000000[package] name = "http-body" # When releasing to crates.io: # - Remove path dependencies # - Update html_root_url. # - Update doc url # - Cargo.toml # - README.md # - Update CHANGELOG.md. # - Create "v0.1.x" git tag. version = "0.1.0" authors = ["Carl Lerche "] readme = "README.md" documentation = "https://docs.rs/http-body/0.1.0/http-body" repository = "https://github.com/hyperium/http-body" homepage = "https://github.com/hyperium/http-body" license = "MIT" description = """ Trait representing an asynchronous, streaming, HTTP request or response body. """ keywords = ["http"] categories = ["web-programming"] [dependencies] bytes = "0.4.11" futures = "0.1.25" http = "0.1.16" tokio-buf = { version = "0.1.0", default-features = false } http-body-0.1.0/Cargo.toml0000644000000022070000000000000110020ustar00# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g. crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] name = "http-body" version = "0.1.0" authors = ["Carl Lerche "] description = "Trait representing an asynchronous, streaming, HTTP request or response body.\n" homepage = "https://github.com/hyperium/http-body" documentation = "https://docs.rs/http-body/0.1.0/http-body" readme = "README.md" keywords = ["http"] categories = ["web-programming"] license = "MIT" repository = "https://github.com/hyperium/http-body" [dependencies.bytes] version = "0.4.11" [dependencies.futures] version = "0.1.25" [dependencies.http] version = "0.1.16" [dependencies.tokio-buf] version = "0.1.0" default-features = false http-body-0.1.0/Cargo.toml.orig0000644000000022100000000000000117330ustar00# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] name = "http-body" version = "0.1.0" authors = ["Carl Lerche "] description = "Trait representing an asynchronous, streaming, HTTP request or response body.\n" homepage = "https://github.com/hyperium/http-body" documentation = "https://docs.rs/http-body/0.1.0/http-body" readme = "README.md" keywords = ["http"] categories = ["web-programming"] license = "MIT" repository = "https://github.com/hyperium/http-body" [dependencies.bytes] version = "0.4.11" [dependencies.futures] version = "0.1.25" [dependencies.http] version = "0.1.16" [dependencies.tokio-buf] version = "0.1.0" default-features = false http-body-0.1.0/CHANGELOG.md010064400007650000024000000000511346434062400134540ustar0000000000000000# 0.1.0 (May 7, 2019) - Initial release http-body-0.1.0/ci/azure-install-rust.yml010064400007650000024000000016431346407272600165630ustar0000000000000000steps: # Linux and macOS. - script: | set -e curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain $RUSTUP_TOOLCHAIN echo "##vso[task.setvariable variable=PATH;]$PATH:$HOME/.cargo/bin" env: RUSTUP_TOOLCHAIN: ${{parameters.rust_version}} displayName: "Install rust (*nix)" condition: not(eq(variables['Agent.OS'], 'Windows_NT')) # Windows. - script: | curl -sSf -o rustup-init.exe https://win.rustup.rs rustup-init.exe -y --default-toolchain %RUSTUP_TOOLCHAIN% set PATH=%PATH%;%USERPROFILE%\.cargo\bin echo "##vso[task.setvariable variable=PATH;]%PATH%;%USERPROFILE%\.cargo\bin" env: RUSTUP_TOOLCHAIN: ${{parameters.rust_version}} displayName: "Install rust (windows)" condition: eq(variables['Agent.OS'], 'Windows_NT') # All platforms. - script: | rustc -Vv cargo -V displayName: Query rust and cargo versions http-body-0.1.0/ci/azure-rustfmt.yml010064400007650000024000000003661346407272600156270ustar0000000000000000steps: - template: azure-install-rust.yml parameters: rust_version: stable - bash: | rustup component add rustfmt displayName: Install rustfmt - bash: | cargo fmt --all -- --check displayName: Check formatting http-body-0.1.0/ci/azure-test-all.yml010064400007650000024000000006041346407272600156430ustar0000000000000000jobs: - job: cargo_test_all displayName: cargo test pool: vmImage: ubuntu-16.04 strategy: matrix: stable: rust_version: stable beta: rust_version: beta nightly: rust_version: nightly steps: - template: azure-install-rust.yml parameters: rust_version: $(rust_version) - script: cargo test displayName: cargo test http-body-0.1.0/LICENSE010064400007650000024000000020461346407272600126630ustar0000000000000000Copyright (c) 2019 Hyper Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. http-body-0.1.0/README.md010064400007650000024000000016541346434062400131340ustar0000000000000000# HTTP Body A trait representing asynchronous operations on an HTTP body. [![Build Status][azure-badge]][azure-url] [azure-badge]: https://dev.azure.com/seanmonstar/http-body/_apis/build/status/hyperium.http-body?branchName=master [azure-url]: https://dev.azure.com/seanmonstar/http-body/_build/latest?definitionId=1&branchName=master More information about this crate can be found in the [crate documentation][dox]. [dox]: https://docs.rs/http-body ## Usage To use `http-body`, first add this to your `Cargo.toml`: ```toml [dependencies] http-body = "0.1.0" ``` Next, add this to your crate: ```rust use http_body::Body; fn main() { // ... } ``` ## License This project is licensed under the [MIT license](LICENSE). ### Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in `http-body` by you, shall be licensed as MIT, without any additional terms or conditions. http-body-0.1.0/src/lib.rs010064400007650000024000000062631346434062400135610ustar0000000000000000#![doc(html_root_url = "https://docs.rs/http-body/0.1.0")] #![deny(missing_debug_implementations, missing_docs, unreachable_pub)] #![cfg_attr(test, deny(warnings))] //! Asynchronous HTTP request or response body. //! //! See [`Body`] for more details. //! //! [`Body`]: trait.Body.html extern crate bytes; extern crate futures; extern crate http; extern crate tokio_buf; use bytes::Buf; use futures::{Async, Poll}; use http::HeaderMap; use tokio_buf::{BufStream, SizeHint}; /// Trait representing a streaming body of a Request or Response. /// /// Data is streamed via the `poll_data` function, which asynchronously yields `T: Buf` values. The /// `size_hint` function provides insight into the total number of bytes that will be streamed. /// /// The `poll_trailers` function returns an optional set of trailers used to finalize the request / /// response exchange. This is mostly used when using the HTTP/2.0 protocol. /// /// # Relation with [`BufStream`]. /// /// The `Body` trait is a superset of the `BufStream` trait. However, `BufStream` is not considered /// a super trait of `Body`. Instead, a `T: Body` can be thought of as containing a `BufStream` as /// well as the HTTP trailers. /// /// There exists is a blanket implementation of `Body` for `T: BufStream`. In other words, any type /// that implements `BufStream` also implements `Body` yielding no trailers. /// /// [`BufStream`]: https://docs.rs/tokio-buf/0.1.1/tokio_buf/trait.BufStream.html /// pub trait Body { /// Values yielded by the `Body`. type Data: Buf; /// The error type this `BufStream` might generate. type Error; /// Attempt to pull out the next data buffer of this stream. fn poll_data(&mut self) -> Poll, Self::Error>; /// Returns the bounds on the remaining length of the stream. /// /// When the **exact** remaining length of the stream is known, the upper bound will be set and /// will equal the lower bound. fn size_hint(&self) -> SizeHint { SizeHint::default() } /// Poll for an optional **single** `HeaderMap` of trailers. /// /// This function should only be called once `poll_data` returns `None`. fn poll_trailers(&mut self) -> Poll, Self::Error>; /// Returns `true` when the end of stream has been reached. /// /// An end of stream means that both `poll_data` and `poll_trailers` will /// return `None`. /// /// A return value of `false` **does not** guarantee that a value will be /// returned from `poll_stream` or `poll_trailers`. fn is_end_stream(&self) -> bool { false } } impl Body for T { type Data = T::Item; type Error = T::Error; fn poll_data(&mut self) -> Poll, Self::Error> { BufStream::poll_buf(self) } fn size_hint(&self) -> SizeHint { BufStream::size_hint(self) } fn poll_trailers(&mut self) -> Poll, Self::Error> { Ok(Async::Ready(None)) } fn is_end_stream(&self) -> bool { let size_hint = self.size_hint(); size_hint .upper() .map(|upper| upper == 0 && upper == size_hint.lower()) .unwrap_or(false) } } http-body-0.1.0/tests/is_end_stream.rs010064400007650000024000000023611346407272600162020ustar0000000000000000extern crate futures; extern crate http_body; extern crate tokio_buf; use futures::Poll; use http_body::Body; use tokio_buf::{BufStream, SizeHint}; struct Mock { size_hint: SizeHint, } impl BufStream for Mock { type Item = ::std::io::Cursor>; type Error = (); fn poll_buf(&mut self) -> Poll, Self::Error> { unimplemented!(); } fn size_hint(&self) -> SizeHint { self.size_hint.clone() } } #[test] fn buf_stream_is_end_stream() { let combos = [ (None, None, false), (Some(123), None, false), (Some(0), Some(123), false), (Some(123), Some(123), false), (Some(0), Some(0), true), ]; for &(lower, upper, is_end_stream) in &combos { let mut size_hint = SizeHint::new(); assert_eq!(0, size_hint.lower()); assert!(size_hint.upper().is_none()); if let Some(lower) = lower { size_hint.set_lower(lower); } if let Some(upper) = upper { size_hint.set_upper(upper); } let mock = Mock { size_hint }; assert_eq!( is_end_stream, mock.is_end_stream(), "size_hint = {:?}", mock.size_hint ); } } http-body-0.1.0/.cargo_vcs_info.json0000644000000001120000000000000127750ustar00{ "git": { "sha1": "44d6d5c2328d9f89d11e565596fc2ef3e26a048a" } }