Commit Graph

90 Commits

Author SHA1 Message Date
danieleades
0eaf304644 style(lib): address most clippy lints 2020-01-03 09:40:32 -08:00
Sean McArthur
4b6099c7aa feat(body): implement HttpBody for Request and Response
When the body type of a `Request` or `Response` implements `HttpBody`,
the `Request` or `Response` itself now implements `HttpBody`.

This allows writing things like `hyper::body::aggregate(req)` instead of
`hyper::body::aggregate(req.into_body())`.

Closes #2067
2019-12-13 10:48:30 -08:00
Sean McArthur
0dc89680cd style(lib): run rustfmt and enforce in CI 2019-12-05 13:55:17 -08:00
Sean McArthur
0b03b73053 feat(lib): rename unstable-stream feature to stream and enable by default
Closes #2034
2019-12-04 17:09:10 -08:00
Sean McArthur
a738d03fd3 chore(dependencies): update to http-body 0.3 2019-12-04 16:48:06 -08:00
Sean McArthur
4d7a2266b8 feat(client): change connectors to return an impl Connection
Instead of returning a tuple `(impl AsyncRead + AsyncWrite, Connected)`,
this adds a new trait, `hyper::client::connect::Connection`, which
allows querying the connection type for a `Connected`.

BREAKING CHANGE: Connectors no longer return a tuple of
  `(T, Connected)`, but a single `T: Connection`.
2019-12-04 16:15:28 -08:00
Sean McArthur
cb3f39c2dc feat(lib): update Tokio, bytes, http, h2, and http-body 2019-12-04 10:56:34 -08:00
Daniel Johnson
71d088d3d0 chore(dependencies): update futures to 0.3.1 2019-11-14 10:04:16 -08:00
Sean McArthur
ca5836f1ec fix(server): ignore expect-continue with no body in debug mode
Closes #1843
2019-10-18 15:44:01 -07:00
Sean McArthur
2d6bbd2cd8 chore(ci): re-enable CI running on beta 2019-10-18 15:16:07 -07:00
Sean McArthur
7e31fd88a8 feat(server): change http1_half_close option default to disabled
Detecting a read hangup is a useful way to determine that a connection
has closed. It's also possible that a client shuts down its read half
without closing the connection, but this is rarer. Thus, by default,
hyper will now assume a read EOF means the connection has closed.

BREAKING CHANGE: The server's behavior will now by default close
  connections when receiving a read EOF. To allow for clients to close
  the read half, call `http1_half_close(true)` when configuring a
  server.
2019-10-18 13:34:23 -07:00
Taiki Endo
053d6497bd chore(dependencies): update tokio, h2, and tower-make 2019-09-23 12:45:37 -07:00
Sean McArthur
62a96c077b feat(body): change Sender::send_data to an async fn.
The previous version is renamed to `try_send_data`.

BREAKING CHANGE: Usage of `send_data` should either be changed to
  async/await or use `try_send_data`.
2019-08-30 16:04:07 -07:00
Sean McArthur
2664cf505f refactor(tests): update to newest tokio-timer 2019-08-29 13:50:55 -07:00
Lucio Franco
79c32f8953 feat(body): Update Payload to be a trait alias of http_body::Body (#1908) 2019-08-22 14:13:27 -07:00
lzutao
fc7f81b67c style(lib): use rust 2018 edition idioms (#1910) 2019-08-21 11:22:07 -07:00
lzutao
ae75b3a732 chore(lib): remove async_await feature gate (#1909)
`async_await` is stabilized in rust-lang/rust#63209.
2019-08-21 11:09:14 -07:00
Lucio Franco
ec520d5602 feat(service): use tower_service::Service for hyper::service 2019-08-20 12:01:06 -07:00
Sean McArthur
53a437c382 chore(tests): fixup re-enabled tests 2019-08-19 17:55:37 -07:00
Jakub Wieczorek
b831ae1870 test(server): Update and re-enable the tests/server.rs test
These tests were temporarily disabled during the migration to the
`std::future::Future` type that's part of the stable Rust now.

This commit updates the tests after the breaking changes and makes them
pass again.
2019-08-19 16:35:01 -07:00
Sean McArthur
5da17df97f chore(lib): individually disable tests and examples that aren't updated 2019-07-12 13:44:03 -07:00
Sean McArthur
01c03db7ea chore(lib): add dyn keyword to trait objects (#1820)
Requires Rust 1.27.
2019-06-03 13:08:13 -07:00
João Oliveira
b342c38f08 fix(server): skip automatic Content-Length header for HTTP 304 responses
Closes #1797
2019-05-07 12:53:25 -07:00
Sean McArthur
42c5efc085 fix(http2): send a GOAWAY when the user's Service::poll_ready errors
The `Error::source()` is searched for an `h2::Error` to allow sending
different error codes in the GOAWAY. If none is found, it defaults to
`INTERNAL_ERROR`.
2019-04-09 12:49:43 -07:00
Sean McArthur
fc18b680a5 feat(http2): check Error::source() for an HTTP2 error code to send in reset 2019-03-25 13:10:41 -07:00
Sean McArthur
e5135dd6f6 fix(dependencies): disable unneeded optional tokio features
Closes #1739
2019-01-07 15:03:20 -08:00
Sean McArthur
138b1f8a7c test(server): remove unneeded mutex for TestService 2018-12-06 11:06:45 -08:00
Sean McArthur
73345be65f feat(server): add http1_half_close(bool) option
This option determines whether a read EOF should close the connection
automatically. The behavior was to always allow read EOF while waiting
to respond, so this option has a default of `true`.

Setting this option to `false` will allow Service futures to be canceled
as soon as disconnect is noticed.

Closes #1716
2018-11-27 12:31:50 -08:00
Sean McArthur
9245e9409a fix(header): fix panic when parsing header names larger than 64kb 2018-11-06 14:37:13 -08:00
Sean McArthur
5ca2905c84 test(server): server test cleanup 2018-10-26 12:50:27 -07:00
lambdasqd
1448e4067b fix(server): properly handle keep-alive for HTTP/1.0
Change behaviour of connection or server response when the request is
version 1.0 and the Connection: keep-alive header is not present.

1. If the response is also version 1.0, then connection is closed if the
server keep-alive header is not present.
2. If the response is version 1.1, then the keep-alive header is added
when downgrading to version 1.0.

Closes #1614
2018-08-15 12:10:03 -07:00
Sean McArthur
195fbb2a37 fix(server): coerce responses with HTTP2 version to HTTP/1.1 when protocol is 1.x 2018-08-10 13:08:08 -07:00
Sean McArthur
853266d873 test(server): add http1_only server test 2018-08-10 13:08:08 -07:00
Sean McArthur
e61fe54093 test(server): fix unused result from block_on 2018-06-25 11:48:52 -07:00
Sean McArthur
6848ba63fb test(server): use current_thread instead of rt::run with http2 tests 2018-06-25 11:35:57 -07:00
Sean McArthur
e4ebf44823 chore(tests): change tests to use current_thread runtime 2018-06-18 12:30:56 -07:00
Josh Leeb-du Toit
9a28268b98 feat(http2): Add content_length() value to incoming h2 Body
- Add `Body::Kind::H2` to contain the content length of the body.
- Update `Body::content_length` to return the content length if `Body::Kind` is `H2`, instead of returning `None`.

Reference: #1556, #1557

Closes #1546
2018-06-18 11:50:12 -07:00
Sean McArthur
fea29b29e2 feat(http1): Add higher-level HTTP upgrade support to Client and Server (#1563)
- Adds `Body::on_upgrade()` that returns an `OnUpgrade` future.
- Adds `hyper::upgrade` module containing types for dealing with
  upgrades.
- Adds `server::conn::Connection::with_upgrades()` method to enable
  these upgrades when using lower-level API (because of a missing
  `Send` bound on the transport generic).
- Client connections are automatically enabled.
- Optimizes request parsing, to make up for extra work to look for
  upgrade requests.
  - Returns a smaller `DecodedLength` type instead of the fatter
    `Decoder`, which should also allow a couple fewer branches.
  - Removes the `Decode::Ignore` wrapper enum, and instead ignoring
    1xx responses is handled directly in the response parsing code.

Ref #1563 

Closes #1395
2018-06-14 13:39:29 -07:00
Laurențiu Nicola
386fc0d70b feat(http2): set Content-Length header on outgoing messages
Closes #1547
2018-06-10 15:22:30 -07:00
Sean McArthur
d7ab016676 fix(server): correctly handle CONNECT requests
- In the higher-level `Server` API, since connection upgrades aren't yet
  supported, returning a 2xx response to a `CONNECT` request is a user
  error. A 500 response is written to the client, the connection is
  closed, and an error is reported back to the user.
- In the lower-level `server::Connection` API, where upgrades *are*
  supported, a 2xx response correctly marks the response as the final
  one, instead of trying to parse more requests afterwards.
2018-06-07 14:59:01 -07:00
Sean McArthur
898e919504 perf(h1): optimize for when Body is only 1 chunk
- When the `Body` is created from a buffer of bytes (such as
  `Body::from("hello")`), we can skip some bookkeeping that is
  normally required for streaming bodies.
- Orthogonally, optimize encoding body chunks when the strategy
  is to flatten into the headers buf, by skipping the EncodedBuf
  enum.
2018-05-31 19:27:24 -07:00
Sean McArthur
26417fc24a perf(h1): improve parsing and encoding of http1 messages 2018-05-15 13:24:58 -07:00
estk
bc6af88a32 feat(server): support HTTP1 and HTTP2 automatically
If an HTTP/1 connection has a parse error, but it starts with the HTTP2 preface, converts the connection automatically into an HTTP2 server connection.

Closes #1486
2018-05-10 14:23:42 -07:00
Evan Simmons
aac250f29d fix(server): panic on max_buf_size too small 2018-04-19 12:27:11 -07:00
Sean McArthur
2dc6202fe7 feat(service): introduce hyper-specific Service
This introduces the `hyper::service` module, which replaces
`tokio-service`.

Since the trait is specific to hyper, its associated
types have been adjusted. It didn't make sense to need to define
`Service<Request=http::Request>`, since we already know the context is
HTTP. Instead, the request and response bodies are associated types now,
and slightly stricter bounds have been placed on `Error`.

The helpers `service_fn` and `service_fn_ok` should be sufficient for
now to ease creating `Service`s.

The `NewService` trait now allows service creation to also be
asynchronous.

These traits are similar to `tower` in nature, and possibly will be
replaced completely by it in the future. For now, hyper defining its own
allows the traits to have better context, and prevents breaking changes
in `tower` from affecting hyper.

Closes #1461

BREAKING CHANGE: The `Service` trait has changed: it has some changed
  associated types, and `call` is now bound to `&mut self`.

  The `NewService` trait has changed: it has some changed associated
  types, and `new_service` now returns a `Future`.

  `Client` no longer implements `Service` for now.

  `hyper::server::conn::Serve` now returns `Connecting` instead of
  `Connection`s, since `new_service` can now return a `Future`. The
  `Connecting` is a future wrapping the new service future, returning
  a `Connection` afterwards. In many cases, `Future::flatten` can be
  used.
2018-04-17 17:09:15 -07:00
Sean McArthur
c4974500ab feat(server): re-design Server as higher-level API
The `hyper::Server` is now a proper higher-level API for running HTTP
servers. There is a related `hyper::server::Builder` type, to construct
a `Server`. All other types (`Http`, `Serve`, etc) were moved into the
"lower-level" `hyper::server::conn` module.

The `Server` is a `Future` representing a listening HTTP server. Options
needed to build one are set on the `Builder`.

As `Server` is just a `Future`, it no longer owns a thread-blocking
executor, and can thus be run next to other servers, clients, or
what-have-you.

Closes #1322
Closes #1263

BREAKING CHANGE: The `Server` is no longer created from `Http::bind`,
  nor is it `run`. It is a `Future` that must be polled by an
  `Executor`.

  The `hyper::server::Http` type has move to
  `hyper::server::conn::Http`.
2018-04-16 14:29:19 -07:00
Sean McArthur
c119097fd0 feat(http2): add HTTP/2 support for Client and Server 2018-04-13 14:23:47 -07:00
Sean McArthur
dfdca25c00 feat(body): rename Entity to Payload
Closes #1464
2018-04-10 15:55:23 -07:00
Sean McArthur
5d3c472228 feat(error): revamp hyper::Error type
**The `Error` is now an opaque struct**, which allows for more variants to
be added freely, and the internal representation to change without being
breaking changes.

For inspecting an `Error`, there are several `is_*` methods to check for
certain classes of errors, such as `Error::is_parse()`. The `cause` can
also be inspected, like before. This likely seems like a downgrade, but
more inspection can be added as needed!

The `Error` now knows about more states, which gives much more context
around when a certain error occurs. This is also expressed in the
description and `fmt` messages.

**Most places where a user would provide an error to hyper can now pass
any error type** (`E: Into<Box<std::error::Error>>`). This error is passed
back in relevant places, and can be useful for logging. This should make
it much clearer about what error a user should provide to hyper: any it
feels is relevant!

Closes #1128
Closes #1130
Closes #1431
Closes #1338

BREAKING CHANGE: `Error` is no longer an enum to pattern match over, or
  to construct. Code will need to be updated accordingly.

  For body streams or `Service`s, inference might be unable to determine
  what error type you mean to return. Starting in Rust 1.26, you could
  just label that as `!` if you never return an error.
2018-04-10 14:29:34 -07:00
Sean McArthur
c210524e94 chore(tests): fix tokio runtime deprecations 2018-04-10 12:56:55 -07:00