hyperium/http

A general purpose library of common HTTP types

More information about this crate can be found in the MIT license (LICENSE-MIT or

HTTP

A general purpose library of common HTTP types

More information about this crate can be found in the crate documentation.

Usage

To use http, first add this to your Cargo.toml:

Next, add this to your crate:

Examples

Create an HTTP request:

Create an HTTP response:

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Issues

Collection of the latest Issues

robjtede

robjtede

Comment Icon2

Proposal

I noticed you've reserved the http-core crate. Would there be interest in moving some of the primitives from http down to it?

I'm thinking:

  • definitely:
    • Method
    • Version
    • StatusCode
  • possibly:
    • Uri
    • HeaderName
    • HeaderValue

Motivation

These are the types we use and re-export from http in Actix Web.

kiron1

kiron1

Comment Icon0

According to RFC2817, Section 5.2 the URI of the CONNECT method should be only the authority part:

A CONNECT method requests that a proxy establish a tunnel connection on its behalf. The Request-URI portion of the Request-Line is always an 'authority' as defined by URI Generic Syntax [2], which is to say the host name and port number destination of the requested connection separated by a colon:

However with the http 0.2.4 crate it is possible to create a CONNECT request with an invalid URI part.

Example:

Output:

Rust Playground Link

Available options are:

bluss

bluss

Comment Icon2

When I read the HeaderMap code I recognize that it's based on my own code in crate indexmap (at one time formerly "ordermap"). The license is Apache-2 or MIT but it would be nice - if this is true - if authorship information was retained, as it has to be.

HeaderMap source link https://github.com/hyperium/http/blob/e54da7175a9af490a2e04003c5b49ff259222a88/src/header/map.rs

It seems to come all the way from the initial implementation https://github.com/hyperium/http/pull/13

When I read the code I recognize the probe loop, insert split into mulitple phases, the struct Pos, type HashValue etc. We have since refactored and upgraded IndexMap a lot, so they have certainly diverged.

An older version of indexmap source (2016) is here: https://github.com/bluss/indexmap/blob/02a9bf73356eb976ddcb980d1b839db6c2ee122f/src/lib.rs Comparing for example the function do_insert_phase_two in HeaderMap, with insert_phase_2 in indexmap, I'd say the former is derived from the latter. The code includes comments like phase 2 is post-insert where we forward-shift Pos in the indices. which were literally written by me. :slightly_smiling_face:

If you credit me, please write Ulrik Sverdrup "bluss" as the author. Thank you!

Lexo-0

Lexo-0

Comment Icon2

When using the HTTP1.1 protocol, we can convert the entire buffer into bytes:: Bytes, and then convert a portion of it into ByteStr for use (for example, as HeaderName) for zero-copy network programming.I think it's very useful and important

fimbault

fimbault

Comment Icon5

Hi, any plan to include support for parsing and serializing structured headers? (RFC8941)

maxlambrecht

maxlambrecht

Comment Icon6

Trying to parse an URI like #404 or unix:/tmp/agent.sock, that has a schema and not an authority, produces an Error InvalidaUri(InvalidFormat).

There is no restriction defined in the URI standard that would make these URIs invalid.

The use-case I have is connecting to a SPIFFE Workload Endpoint: https://github.com/spiffe/spiffe/blob/master/standards/SPIFFE_Workload_Endpoint.md#4-locating-the-endpoint.

seanmonstar

seanmonstar

B-rfc
Comment Icon4

I wanted to write-up some thoughts on the future direction for the StatusCode::as_str method. The as_str method returns the numeric part of the status code as a string slice. So, StatusCode::OK.as_str() returns "200", and StatusCode::NOT_FOUND.as_str() returns "404", and so forth. This works for all StatusCodes, from 100-999. Since the StatusCode only stores an integer, there's no field to actually borrow the string from, so it is in reality returning a &'static str, even though the method signature doesn't expose that.

There have been several PRs filed to make that part of the signature (that is, change from fn as_str(&self) -> &str to fn as_str(&self) -> &'static str) (#380 #436 #466).

I've personally questioned the value of the method in it's entirety:

I was thinking that perhaps we just axe StatusCode::as_str, because really, how useful can it be? There's the Display impl to get a string, and if you want a fast path for some common status codes, a user can just do that manually (hyper has a fast path for HTTP/1.1 200 OK, for instance).

That comment was prompted as I wondered about the cost of including all the static strings in the binary, when certainly most applications will never need them. Because I don't see value in the method, I've held off from changing it return a &'static str. Instead, I've thought we may just want to deprecate it and chop it for 1.0.

However, I realize I could be wrong, and not considering a large use case for this method. If so, we can just merge one of the PRs and carry on. If I have overlooked something, hopefully we can collect the reasons why to keep the method, with some details about the value it provides versus the cost of having a bunch of extra strings in the binary for everyone.

Versions

Find the latest versions by id

v0.2.6 - Dec 30, 2021

  • Upgrade internal itoa dependency to 1.0.

New Contributors

v0.2.5 - Sep 21, 2021

  • Add is_empty() and len() methods to Extensions.
  • Add version_ref() method to request::Builder.
  • Implement TryFrom<Vec<u8>> and TryFrom<String> for Authority, Uri, PathAndQuery, and HeaderName.
  • Make HeaderValue::from_static a const fn.

v0.2.4 - Apr 07, 2021

  • Fix Uri parsing to allow {, ", and } in paths.

v0.2.3 - Apr 07, 2021

  • Upgrade internal (private) bytes dependency to 1.0.

v0.2.2 - Dec 15, 2020

  • Fix (potential double) panic of (HeaderMap) OccupiedEntry::remove_entry and remove_entry_mult when multiple values are present. ([#446], [#449] dekellum)
  • Safety audits of (priv) ByteStr and refactor of Authority ([#408], [#414] sbosnick)
  • Fix HeaderName to error instead of panic when input is too long ([#432] [#433] acfoltzer)
  • Allow StatusCode to encode values 100-999 without error. Use of the unclassified range 600-999 remains discouraged. ([#144], [#438], [#443] quininer dekellum)
  • Add String and &String fallible conversions to PathAndQuery ([#450] mkindahl)
  • Fix Authority (and Uri) to error instead of panic on unbalanced brackets ([#435], [#445] aeryz)

v0.2.1 - Mar 25, 2020

  • Add extensions_ref and extensions_mut to request::Builder and response::Builder.

v0.2.0 - Dec 02, 2019

  • Add Version::HTTP_3 constant.
  • Add HeaderValue::from_maybe_shared, HeaderValue::from_maybe_shared_unchecked, Uri::from_maybe_shared, Authority::from_maybe_shared, and PathAndQuery::from_maybe_shared.
  • Change request::Builder, response::Builder, and uri::Builder to use by-value methods instead of by-ref.
  • Change from HttpTryFrom trait to std::convert::TryFrom.
  • Change HeaderMap::entry to no longer return a Result.
  • Change HeaderMap::drain iterator to match the behavior of IntoIter.
  • Change Authority::port to return an Option<Port> instead of Option<u16>.
  • Change Uri::scheme to return Option<&Scheme> instead of Option<&str>.
  • Change Uri::authority to return Option<&Authority> instead of Option<&str>.
  • Remove InvalidUriBytes, InvalidHeaderNameBytes, and InvalidHeaderValueBytes error types.
  • Remove HeaderValue::from_shared, HeaderValue::from_shared_unchecked, Uri::from_shared, Authority::from_shared, Scheme::from_shared, and PathAndQuery::from_shared.
  • Remove Authority::port_part.
  • Remove Uri::scheme_part and Uri::authority_part.

Information - Updated Feb 11, 2022

Stars: 740
Forks: 190
Issues: 106

Repositories & Extras

Ease - HTTP clients for Rust

Ease is a library for interacting with RESTful APIs

Ease - HTTP clients for Rust

When you need to pretend you are a REST API, but you're really not

Facade is a Rust-based HTTP transformation layer to seamlessly convert REST calls into GraphQL calls for piecemeal API migrations

When you need to pretend you are a REST API, but you're really not

Rust helpers for serving HTTP GET and HEAD responses with

This crate supplies two ways to respond to HTTP GET and HEAD requests:

Rust helpers for serving HTTP GET and HEAD responses with

When you need to pretend you are a REST API, but you're really not

Vostok is a Rust-Based HTTP Transformation Layer To Seamlessly Convert REST Calls Into GraphQL Calls For Piecemeal API Migrations

When you need to pretend you are a REST API, but you're really not

Eve-rs is a middleware-based rust http framework which is inspired from ExpressJS framework

Let's create a demo application using eve-rs, using an intuative approach to get a better understanding of the framework

Eve-rs is a middleware-based rust http framework which is inspired from ExpressJS framework
Http

375

HTTP mocking for Rust!

Before upgrading, make sure to check out the rustfmt as a general code style

HTTP mocking for Rust!

Rust Urbit HTTP API

This library wraps the Urbit ship http interface exposing it as an easy-to-use Rust crate

Rust Urbit HTTP API

HTTP Server with Rust

Rust http server from scratch

HTTP Server with Rust

ehttp: a minimal Rust HTTP client for both native and WASM

If you want to do HTTP requests and are targetting both native and web (WASM), then this is the crate for you!

ehttp: a minimal Rust HTTP client for both native and WASM

Here lies my attempt to create a multi thread webserver based off of Rust and...

Here lies my attempt to create a multi thread webserver based off of Rust and using HTTP and TCP networking protocols :)

Here lies my attempt to create a multi thread webserver based off of Rust and...

rust-http-server

Multithread HTTP Server developed with Rust

rust-http-server
Facebook Instagram Twitter GitHub Dribbble
Privacy