Commit Graph

107 Commits

Author SHA1 Message Date
Anthony Ramine
556447c130 Make use of NLL to clean up handshaking logic (#576) 2022-01-26 11:18:28 +01:00
Sean McArthur
efa113bac6 Add max send buffer per stream option (#580) 2021-12-08 10:03:15 -08:00
Anthony Ramine
87969c1f29 Implement the extended CONNECT protocol from RFC 8441 (#565) 2021-11-24 10:05:10 +01:00
Anthony Ramine
f52d5e6290 Replace HTTP/2.0 by HTTP/2 😅
The protocol is named HTTP/2.
2021-10-20 11:10:25 -07:00
Anthony Ramine
c38c94cb16 Make :status in requests be a stream error 2021-10-19 11:02:44 -07:00
Anthony Ramine
465f0337f8 Refactor errors internals (#556)
h2::Error now knows whether protocol errors happened because the user
sent them, because it was received from the remote peer, or because
the library itself emitted an error because it detected a protocol
violation.

It also keeps track of whether it came from a RST_STREAM or GO_AWAY
frame, and in the case of the latter, it includes the additional
debug data if any.

Fixes #530
2021-09-28 09:04:35 -07:00
Anthony Ramine
fea3ae6ca9 Read body in the example server (#544)
Co-authored-by: Kornel Lesiński <kornel@cloudflare.com>
2021-05-06 20:42:29 +02:00
Josh Soref
bcaaaf6dd9 Spelling fixes in comments (#508) 2021-02-25 08:59:18 -08:00
Eliza Weisman
c1b411fc14 add Connection::max_concurrent_recv_streams (#516)
This commit adds accessors to `client::Connection` and
`server::Connection` that return the current value of the
`SETTINGS_MAX_CONCURRENT_STREAMS` limit that has been sent by this peer
and acknowledged by the remote.

This is analogous to the `max_concurrent_send_streams` methods added in
PR #513. These accessors may be somewhat less useful than the ones for
the values negotiated by the remote, since users who care about this
limit are probably setting the builder parameter. However, it seems
worth having for completeness sake --- and it might be useful for
determining whether or not a configured concurrency limit has been acked
yet...

Part of #512
2021-02-25 08:58:19 -08:00
nickelc
9049e468c8 Remove the obsolent tracing-future dependency (#517) 2021-02-09 05:50:11 -08:00
Eliza Weisman
978c71270a add Connection::max_concurrent_send_streams (#513)
This PR adds accessors to `client::Connection` and `server::Connection`
that return the send stream concurrency limit on that connection, as
negotiated by the remote peer. This is part of issue #512.

I think we probably ought to expose similar accessors for other
settings, but I thought it was better to add each one in a separate,
focused PR.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2021-02-05 09:58:10 -08:00
Eliza Weisman
2c8c847cd5 Replace deprecated compare_and_swap with compare_exchange (#514)
The `compare_and_swap` method on atomics is now deprecated in favor
of `compare_exchange`.

Since the author of #510 closed that PR, this is just #510 with rustfmt run.

I also removed an unnecessary trailing semicolon that the latest rust
compiler now complains about.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>

Co-authored-by: Kornel <kornel@cloudflare.com>
2021-02-05 09:27:27 -08:00
João Oliveira
cbbdd305b1 update to tokio 0.3 (#491) 2020-10-23 10:45:09 -07:00
Eliza Weisman
fc7f63f641 start adding tracing spans to internals (#478)
We've adopted `tracing` for diagnostics, but currently, it is just being
used as a drop-in replacement for the `log` crate. Ideally, we would
want to start emitting more structured diagnostics, using `tracing`'s
`Span`s and structured key-value fields.

A lot of the logging in `h2` is already written in a style that imitates
the formatting of structured key-value logs, but as textual log
messages. Migrating the logs to structured `tracing` events therefore is
pretty easy to do. I've also started adding spans, mostly in the read
path.

Finally, I've updated the tests to use `tracing` rather than
`env_logger`. The tracing setup happens in a macro, so that a span for
each test with the test's name can be generated and entered. This will
make the test output easier to read if multiple tests are run
concurrently with `--nocapture`.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-08-17 17:29:22 -07:00
David Barsky
d3b9f1e36a feat(lib): switch from log to tracing (#475) 2020-07-07 15:55:24 -07:00
Han Xu
96570bb564 fix documentation for server::Connection 2020-05-14 11:16:29 -07:00
Kornel Lesiński
f7b3cf6d29 Handle :scheme and :path in CONNECT
If the :method is CONNECT the :scheme and :path pseudo-header fields MUST be omitted
2020-03-09 11:21:40 -07:00
Sean McArthur
ec751f3696 Remove Unpin requirement for the send Buf 2019-12-06 11:40:08 -08:00
Sean McArthur
881832cde9 Rename unstable-stream feature to stream (#433) 2019-12-03 10:38:50 -08:00
Sean McArthur
eab9c0b410 Update to http 0.2 (#432) 2019-12-02 16:22:26 -08:00
Sean McArthur
4398e169e8 Update to Tokio 0.2 (#428) 2019-11-27 14:53:57 -08:00
Sean McArthur
86e53054a6 Change ReserveCapacity to expanded FlowControl type (#423)
- Adds `FlowControl::available_capacity` method.
- Adds `FlowControl::used_capacity` method.
2019-10-08 11:28:15 -07:00
Sean McArthur
3cfcab016e Remove public Error constructor from io::Error (#420) 2019-10-07 15:29:38 -07:00
Sean McArthur
4c1d797712 Add ability to adjust INITIAL_WINDOW_SIZE setting on an existing connection (#421) 2019-10-07 15:29:23 -07:00
Michael Beaumont
fac165e451 Add server support for push (#327)
Closes #291, closes #185
2019-09-16 11:30:58 -07:00
Sean McArthur
0527f5b72a Rename 'stream' feature to 'unstable-stream' 2019-09-12 12:44:44 -07:00
Sean McArthur
2d90efee17 Prune futures-* dependencies 2019-08-30 14:53:49 -07:00
Sean McArthur
678c90eb0a Update futures and tokio alphas 2019-08-29 15:44:26 -07:00
Gurwinder Singh
85b1f669c0 chore: async_await is stable on nightly 2019-08-21 11:10:03 -07:00
Sean McArthur
a1db5428db Make Stream impls part of optional 'stream' cargo feature (#397) 2019-08-20 16:01:03 -07:00
Sean McArthur
f31ec5d0da Remove deprecated-in-0.1.x APIs 2019-08-20 15:15:04 -07:00
Gurwinder Singh
f46840f3fa chore: cargo fmt, clippy 2019-08-16 22:27:39 -07:00
Gurwinder Singh
b039ef25bc Make handshake an async fn; other cleanup 2019-08-16 18:47:47 -07:00
Gurwinder Singh
c8fefd49f1 Update lib to std-future 2019-08-16 18:47:47 -07:00
Jakub Beránek
db6b841e67 Update crate to Rust 2018 (#383) 2019-07-23 10:18:43 -07:00
Eliza Weisman
0e9fbe4a90 Log protocol error causes at debug (#371)
Currently, there are many cases where `h2` will fail a connection or
stream with a PROTOCOL_ERROR, without recording why the protocol error
occurred. Since protocol errors may result from a bug in `h2` or from a
misbehaving peer, it is important to be able to debug the cause of
protocol errors.

This branch adds a log line to almost all cases where a protocol error
occurs. I've tried to make the new log lines consistent with the
existing logging, and in some cases, changed existing log lines to make
them internally consistent with other log lines in that module. All
receive-side errors that would send a reset are now logged at the debug
level, using a formatting based on the format used in `framed_read`.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2019-06-17 14:14:40 -07:00
Sean McArthur
383593a01e allow servers to receive requests without an :authority header 2019-06-17 12:58:50 -07:00
Alex Touchet
e13645c091 Update repo URLs (#370) 2019-06-04 23:06:13 -07:00
Sean McArthur
a3e59eb7e2 Prevent server Connection from returning same error after calling abrupt shutdown (#352) 2019-04-03 11:41:56 -07:00
Sean McArthur
e3a73f726e Add user PING support (#346)
- Add `share::PingPong`, which can send `Ping`s, and poll for the `Pong`
  from the peer.
2019-02-18 15:59:11 -08:00
Eliza Weisman
4b81e528d5 Log more information when rejecting malformed pseudo-headers (#342)
Currently, when a `h2` server receives a HEADERS frame with malformed
pseudo-headers, it logs which pseudo-heade was malformed at the debug
level before sending a reset. This behaviour is correct. However, it can
be difficult to debug misbehaving clients, as the server's log message
doesn't include the *value* of the invalid pseudo-header, or indicate
*why* it was incorrect. 

This branch changes the log message to include both the value of the
malformed header and the error that caused it to be rejected. 

For example, here is the output from the test
`server::recv_invalid_authority`, before and after making this change.

Before:
```
...
DEBUG 2019-01-23T19:16:28Z: h2::server: malformed headers: malformed authority
...
```

After:
```
...
DEBUG 2019-01-23T19:15:37Z: h2::server: malformed headers: malformed authority ("not:a/good authority"): invalid uri character
...
```

Note that it was necessary to clone the value of each pseudo-header
before passing it to the `uri::{Scheme, Authority, Path}::from_shared`
constructors, so that the value could be logged if those functions
return errors. However, since the pseudo-headers are internally
represented using `Bytes`, this should just increase the reference count
rather than copy the string, so I thought this was acceptable. 

If even a ref-count bump has an undesirable performance overhead, we
could consider using
```rust
if log_enabled!(Level::Debug) {
    // ...
}
```
to only clone if the message will be logged, but this makes the code
somewhat significantly more complicated. Therefore, I decided to punt on
that unless requested by a reviewer.

See also linkerd/linkerd2#2133

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2019-01-23 11:44:32 -08:00
Michael Beaumont
6b23542a55 Add client support for server push (#314)
This patch exposes push promises to the client API.

Closes #252
2018-10-16 12:51:08 -07:00
Eliza Weisman
00ca534c4a Update examples to use new Tokio (#316)
The old `tokio-core` crate is deprecated in favour of the `tokio` crate,
which also provides the new multithreaded Tokio runtime. Although `h2`
is generic over the runtime, the examples do depend on `tokio`. 

This branch update the example code to use the new `tokio` library
rather than `tokio-core`. It also updates the examples in `RustDoc`.

For the most part, this was pretty trivial --- simply replacing
`handle.spawn(...)` with `tokio::spawn(...)` and `core.run(...)` with
`tokio::run(...)`. There were a couple of cases where error and item
types from spawned futures had to be mapped to `(), ()`. Alternatively,
this could have been avoided by using the single-threaded runtime and
calling `block_on` instead to await the value of those futures, but I
thought it was better to reduce the amount of tokio-specific code in the
examples.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2018-09-25 14:33:49 -07:00
Eliza Weisman
f3806d5144 Add stream_id accessors to public API types (#292)
Problem:

Applications may want to access the underlying h2 stream ID for
diagnostics, etc. Stream IDs were not previously exposed in public APIs.

Solution:

Added a new public `share::StreamId` type, which has a more restricted 
API than the internal `frame::StreamId` type. The public API types 
`SendStream`, `RecvStream`, `ReleaseCapacity`, 
`client::ResponseFuture`, and `server::SendResponse` now all have 
`stream_id` methods which return the stream ID of the corresponding 
stream.

Closes #289.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2018-07-12 21:01:57 -07:00
Arvid E. Picciani
74a5e072fe Fix tight loop on aborted connection (#285)
When the underlying IO returns 0 on read, we must stop polling it since
it's closed. Otherwise we'll be stuck in a tight loop.

this fixes https://github.com/sfackler/rust-openssl/issues/949
2018-06-15 16:04:13 -07:00
Arvid E. Picciani
2b59803866 fix doc typo (#286) 2018-06-15 15:40:26 -07:00
Sean McArthur
3a4633d205 add SendResponse::poll_reset and SendStream::poll_reset to listen for reset streams (#279) 2018-05-30 22:57:43 +02:00
Sean McArthur
1c5d4ded50 Add Graceful Shutdown support
If graceful shutdown is initiated, a GOAWAY of the max stream ID - 1 is
sent, followed by a PING frame, to measure RTT. When the PING is ACKed,
the connection sends a new GOAWAY with the proper last processed stream
ID. From there, once all active streams have completely, the connection
will finally close.
2018-03-29 13:51:30 -07:00
Oliver Gould
01d81b46c2 Add initial_connection_window_size to Builders (#249)
There is currently no way to configure the initial target window size
for connections. The `Builder::initial_connection_window_size` utilities
make this configurable so that all new connections have this target
window size set.
2018-03-28 14:46:56 -07:00
Darren Tsung
4595b54cfa Add initial_max_send_streams() as builder option (#242) 2018-03-16 11:58:06 -07:00