Commit Graph

289 Commits

Author SHA1 Message Date
Sean McArthur 884c6a2a85 v0.2.8 2022-06-06 15:06:17 -07:00
Sean McArthur 45ff933127 Convert header::name to use MaybeUninit (#555)
Co-authored-by: Steven Bosnick <sbosnick@sympatico.ca>
2022-06-06 14:08:18 -07:00
Nicholas Nethercote fa0c07e303 Fix doc(hidden) errors. (#553)
Compiling with `cargo 1.63.0-nightly (3f052d8ee 2022-05-12)` I get lots
of errors like this:
```
error: `#[doc(hidden)]` is ignored on trait impl items
    --> src/header/map.rs:3296:9
     |
3296 |         #[doc(hidden)]
     |         ^^^^^^^^^^^^^^ help: remove this attribute
     |
note: the lint level is defined here
    --> src/lib.rs:161:9
     |
161  | #![deny(warnings, missing_docs, missing_debug_implementations)]
     |         ^^^^^^^^
     = note: `#[deny(unused_attributes)]` implied by `#[deny(warnings)]`
     = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
     = note: whether the impl item is `doc(hidden)` or not entirely depends on the corresponding trait item
```
This commit removes all these unnecessary attributes so that `http` compiles
again with Nightly.
2022-05-19 15:29:05 -07:00
Sean McArthur 7ebefad283 v0.2.7 2022-04-28 14:17:41 -05:00
Jed Denlea 5894f7d0f2 From impls of PathAndQuery and Authority for Uri (#538)
* From impls of PathAndQuery and Authority for Uri

A Uri may logically hold only an Authority or only a PathAndQuery.
Should an application want to make such Uris, it would be easier to
safely create them by first making just an Authority or just a
PathAndQuery, then cheaply convert them directly into a Uri.

* Fix Uri docs

The doc comments for `impl From<Uri> for Parts` actually described
`Uri::from_parts`.
2022-04-28 07:16:56 -05:00
graves501 f16fad8f74 style: fix typo in code comment (#532) 2022-04-26 15:44:47 -07:00
Jonas Platte 316da9e1fa Add Extensions::extend (#546) 2022-04-26 10:51:25 -04:00
Jed Denlea 49d19ff8a4 Make HeaderName::from_static const (#499)
... plus some clean-up.

It was only after I came up with the scheme using
`const fn from_bytes(&[u8]) -> Option<StandardHeader>`
that I noticed the debug+wasm32-wasi version of `parse_hdr`, which had
something very similar.

While cleaning up that function, I realized it still would still panic
if an attempted name was too long, which had been fixed for all other
targets and profiles in #433.  Then, I thought it would be worth seeing
if the use of `eq!` in the primary version of `parse_hdr` still made any
difference.

And, it would not appear so. At least not on x86_64, nor wasm32-wasi run
via wasmtime.  I've run the benchmarks a number of times now, and it
seems the only significant performance change anywhere is actually that
of `HeaderName::from_static` itself, which now seems to run in about 2/3
the time on average.

Unfortunately, `const fn` still cannot `panic!`, but I've followed the
lead from `HeaderValue::from_static`.  While that version required 1.46,
this new function requires 1.49.  That is almost 8 months old, so
hopefully this isn't too controversial!
2022-04-16 08:40:20 -07:00
Sean McArthur 945ffbfd3e v0.2.6 2021-12-30 15:06:12 -08:00
Bruce Mitchener d2bfc27f87 deps: Update to itoa 1.
In itoa 1, the interface has been slimmed down and the fmt method
is no longer present, so expand to the code that was there previously.
2021-12-14 10:47:23 -08:00
Tshepang Lekhonkhobe 3eb5e80870 remove obsolete comment
See 6059be7a99
2021-11-16 08:20:55 -08:00
Sean McArthur d9ba5572bd v0.2.5 2021-09-21 10:37:20 -07:00
Ben Boeckel 0c7125fb96 extensions: add methods to detect the presence of extensions (#497)
This is useful to know that a `Builder` instance cannot be duplicated
faithfully since the extensions cannot be cloned into a new instance.
2021-08-10 12:43:46 -07:00
Ben Boeckel e59f5add8c request: add Builder::version_ref to query the version in use (#495)
This is needed to manually clone `Builder` instances reliably.
2021-08-10 12:21:55 -07:00
Dave Schuyler 5c5c46ce5e Minor changes to var names in examples (#493)
Using "res" for Response rather than "req".
2021-07-30 14:54:11 -07:00
Jerome Gravel-Niquet ce901ad9ea HeaderValue::from_static can be const (#481)
* HeaderValue::from_static can be const

* bump MSRV to 1.46.0 for const loop
2021-06-09 11:31:55 -07:00
walfie 53826c9ee9 Fix typo in docs (#482) 2021-04-27 17:54:14 -07:00
Arnav Singh 6a91d66523 Add missing TryFrom<String> and TryFrom<Vec<u8>> impls. (#477)
Also fix PathAndQuery's TryFrom<String> impl to not copy the bytes into
a new Bytes.
2021-04-21 06:54:31 -07:00
Stephen M. Coakley f7195c92d7 Add TryFrom implementations for owned types for HeaderName (#479)
`HeaderValue` implements `TryFrom` over both reference and owned types, but `HeaderName` does not. This seemed like an accidental omission to me rather than something intentionally absent. Including this conversion slightly increases ergonomics by allowing you to create a `HeaderMap` from a `HashMap<String, String>` and in similar other constraints.

See also https://github.com/sagebind/isahc/issues/314.
2021-04-16 15:04:34 -07:00
Sean McArthur 8698e76a0e v0.2.4 2021-04-07 13:58:21 -07:00
Anthony Ramine 35fa69a9f1 Allow {, " and } in URI paths (#474) 2021-04-06 14:48:57 -07:00
Sean McArthur 8d373de151 v0.2.3 2021-01-08 10:43:22 -08:00
David Kellum 1dcd1ea866 v0.2.2 2020-12-14 16:10:41 -08:00
David Kellum 200ebdb798 Fixes panic for remove_entry and remove_entry_mult (#449)
* add test case for OccupiedEntry::remove_entry_mult

This is just a self contained test case, currently reproducing the
panic of #446.

* expand test cases for remove_entry_mult

* add multiple remove_entry_mult call tests to show more issues

* test repeated HeaderMap::remove for comparison

* tests showing similar problem with remove_entry on extra values

* fix remove_entry by moving remove_found after remove_all_extra_values

* fix remove_entry_mult by eager collection of extras before remove_found

In order to remove extra values prior to remove_found, we must collect
them eagerly. Eager collection is based on:

    commit 7742356863
    Author:     Sean McArthur <sean@seanmonstar.com>
    AuthorDate: Mon Nov 25 17:34:30 2019 -0800
    Commit:     Sean McArthur <sean@seanmonstar.com>
    CommitDate: Tue Nov 26 10:03:09 2019 -0800

	Make ValueDrain eagerly collect its extra values

...which was reverted in 48f838a77e.

Closes #446
2020-12-11 10:26:23 -08:00
Abdullah Eryuzlu b7fb530866 Return error if multiple brackets exist in the authority (#445)
Closes #435
2020-12-08 14:46:55 -08:00
Mats Kindahl eed07d5c0d Add String and &String convert for PathAndQuery (#450)
When building a URI, it is not possible to provide neither String nor
&String, which is useful when adding a path_and_query from a string
built using format!.

This commit adds implementation of From<String> and From<&String> for
PathAndQuery.
2020-12-08 12:34:27 -08:00
David Kellum d4f2c076ca Allow StatusCode to support 600-999 range
Additionally, reduces the size of the static memory included, and reduces some of the complicated macro usage resulting in faster compiles!

Co-authored-by: quininer <quininer@live.com>
Co-authored-by: David Kellum <dek-oss@gravitext.com>
2020-12-08 12:26:09 -08:00
Adam C. Foltzer 58f6523f49 Return an error rather than panicking when HeaderName is too long (#433)
Fixes #432.

This eliminates an undocumented panic from the `HeaderName` creation functions, returning instead an
`InvalidHeaderName` when the name length exceeds `MAX_HEADER_NAME_LEN`.

I considered making `InvalidHeaderName` a richer error type, but since it was already used for
another type of length error (rejecting zero-length names) I figured it was okay to reuse.

I also redefined `MAX_HEADER_NAME_LEN` slightly, so that it is equal to the largest allowed header
length, rather than one past that value. This was motivated by discovering a bug in my comparison
logic when I went to write the new test exercising the wrong-length error conditions.
2020-08-03 16:28:18 -07:00
Steven Bosnick 2f56485974 Audit the use of unsafe in byte_str.rs (#408)
Add comments describing the invariant that makes the one use of unsafe
sound.
2020-06-24 13:11:02 -07:00
Patrick Lühne 5d08f81a98 Clarify meaning of sensitive header values (#427)
While the documentation mentions that header values can be marked as
sensitive in order to inform outside components that these header values
may require special treatment, it was unclear to me whether doing that
affects the behavior of this crate.

This adds a short note to the documentation to clarify that the main
purpose of the sensitivity flag is to make components building on this
crate to be aware of sensitive data, such that it can be treated with
special care for security purposes.
2020-06-01 10:38:52 -07:00
Steven Bosnick 9cceef63f0 Audit use of unsafe in uri/authority.rs (#414)
* Add unit test for rejecting invalid UTF-8

* Add Authority::from_static() test

* Refactor uri::Authority

Extract the common code from three ways of creating an Authority into a
private create_authority() function.

* Add comments to explain the safety of Authority

The comments describe the preconditions and postconditions that together
ensure that the one use of 'unsafe' in uri/authority.rs is sound.

* Fix typo
2020-05-14 07:58:07 -07:00
Steven Bosnick 6a7d85d7b6 Add comments to describe safety of Scheme
The comments describe the postcondition on parse_exact() that makes the
one use of "unsafe" in Scheme::try_from(&'a [u8]) sound.
2020-05-07 14:59:30 -07:00
Steven Bosnick e3ffd3a4e3 Add tests for directly parsing a Scheme
The tests include an [u8] that is invalid UTF-8.
2020-05-07 14:59:30 -07:00
Steven Bosnick 689fd17504 Document the invariants that make Method safe
The internal InlineExtension and AllocatedExtension types have
invariants that ensure that the two uses of "unsafe" in the "extension"
submodule of "method" are safe. This documents those invariants for
future reference.
2020-05-07 14:57:58 -07:00
Steven Bosnick d37b977fdb Refactor Method internals
Extract the inner types for ExtensionAllocated and ExtensionInline into
a separate extension module that has the supporting functions as
non-public elements.

This refactoring moves the use of "unsafe" into this new "extension"
module and provides a safe wrappers around the two uses of "unsafe".
2020-05-07 14:57:58 -07:00
Steven Bosnick 37f462e9b7 Add tests for valid and invalid Method's
The tests for invalid methods test invalid byte sequences including
invalid utf-8 and valid utf-8 that uses invalid characters for a Method.
The tests for valid methods test both short and long extension methods.

Also extract all of the unit tests into a "test" module.
2020-05-07 14:57:58 -07:00
Sean McArthur ac143cf444 v0.2.1 2020-03-25 12:07:17 -07:00
Sean McArthur 228bef5e04 Remove unnecessary parentheses (#404) 2020-03-25 11:31:41 -07:00
Adam C. Foltzer 13a8a5734b Add extensions_ref() and extensions_mut() to req/resp builders (#403)
A similar capability already exists for many of the other `Parts` fields in these builders, and
is useful for the extensions map as well.
2020-03-25 11:19:15 -07:00
Matt Brubeck 3ee1b58295 HeaderMap: Store pos and hash as u16 (#386)
* HeaderMap: Store pos and hash as u16

HeaderMap currently truncates all hashes to 16 bits, and limits its
capacity to 32768 elements. The comments say this is done in order to
store positions and hashes as u16, to improve cache locality.  However,
they are currently stored as usize.  This patch changes the code to
match the comments.

This does not appear to cause any measurable improvement or regression
in speed in the HeaderMap benchmarks. However, it should at least reduce
the memory footprint of every Headermap.

* Fix overflow check for raw capacity.

The actual maximum capacity is 24578 (i.e. `32768 * 3/4`).

A higher number would cause the raw capacity (i.e. `capacity +
capacity/3` rounded to the next power of 2) to overflow `u16`.
2020-01-27 10:18:11 -08:00
Xidorn Quan 23a5f47c41 Remove unnecessary parentheses to fix warning (#388) 2020-01-27 10:09:35 -08:00
Sean McArthur 0644bfcbf4 Remove deprecated Error::description usage (#387) 2020-01-24 10:57:47 -08:00
Travis Cross d190cf73a4 Remove obsolete allow(warnings) attributes (#373)
We were for a time allowing warnings on two sections of code due to
continued use of `...` pattern syntax.  We had deferred the change to
`..=` syntax so as to support earlier Rust versions.

However, in commit `6059be7a99a264abf9afb8e6b8461413b972e892` we
changed over to `..=` syntax.  The `allow(warnings)` attributes and
the related comments are now obsolete, and we remove them in this
commit.
2019-12-10 13:17:00 -08:00
Sean McArthur c2dabe50fa v0.2.0 2019-12-02 14:04:23 -08:00
Sean McArthur ed4dc57067 Add from_maybe_shared constructors
These constructors don't expose the internal `Bytes` type, but instead
will try to downcast the argument to prevent a copy. If the types don't
match up (a user provides an older version of `Bytes`), the value will
just be copied.

Adds:

- `HeaderValue::from_maybe_shared`
- `HeaderValue::from_maybe_shared_unchecked`
- `Uri::from_maybe_shared`
- `Authority::from_maybe_shared`
- `PathAndQuery::from_maybe_shared`
2019-12-02 13:12:38 -08:00
Sean McArthur 11efef0cb0 remove error type variants suffixed with Bytes
We reserved these extra error types with the goal of possibly returning
the source `Bytes` in the error type, but no one has since need this.
Since the dependency on `bytes` is being made private, it made sense to
remove these otherwise unused error types.

Removes:

- `InvalidUriBytes`
- `InvalidHeaderNameBytes`
- `InvalidHeaderValueBytes`
2019-12-02 13:12:38 -08:00
Sean McArthur bcccb669a4 Make all usage of Bytes private
Removes `from_shared` and `try_from` constructors for all types.
2019-12-02 13:12:38 -08:00
Erin Power 0421354979 Fix Method::is_idempotent 2019-12-02 11:15:56 -08:00
Sean McArthur 356bd8dd87 Change HeaderMap::drain API to match into_iter instead 2019-11-27 12:36:16 -08:00
Sean McArthur 48f838a77e Revert "Make ValueDrain eagerly collect its extra values"
This reverts commit 7742356863.

This patch was for 0.1.x, but is not necessary in 0.2.x due to an
upcoming API change for `Drain`.
2019-11-27 12:36:16 -08:00