Commit Graph

316 Commits

Author SHA1 Message Date
Sean McArthur
8bf7964875 fix(server): GET requests with no body have None instead of Empty
Closes #1373
2017-11-14 11:52:29 -08:00
Sean McArthur
fe38aa4bc1 feat(server): add const_service and service_fn helpers
- `const_service` creates a `NewService` that clones references to the
  wrapped service.
- `service_fn` creates a `Service` from a function. Useful with closures.
2017-11-09 16:47:35 -08:00
Sean McArthur
68e0df759a chore(server): make AddrIncoming stream item an unnameable type 2017-11-09 16:17:02 -08:00
Sean McArthur
b60d4cda3d chore(server): setup ServerProto pieces to be deprecated
- Adds a `server-proto` feature that is added to default features.
- If `server-proto` feature is not enabled, pieces that will eventually
  be deprecated and optional will be tagged deprecated, but with a note
  about the missing `server-proto` feature.
2017-11-09 15:45:13 -08:00
Sean McArthur
39cf6ef7d2 feat(server): add server::Serve that can use a shared Handle
- Adds `Http::serve_addr_handle` which will bind to an address with a
  provided `Handle`, and return a `Serve`.
- Adds `server::Serve` which is a `Stream` of incoming `Connection`s
  being bound by a `NewService`.
- Renames `Http::no_proto` to `Http::serve_connection`.
2017-11-06 18:59:15 -08:00
Kam Y. Tse
0844dede19 feat(server): allow creating Server with shared Handle
1. impl Future for Server [WIP]
2. add method bind_handle to Http
3. add an example to use shared Handle in multiple server
2017-11-06 18:59:15 -08:00
Sean McArthur
af8d11b2bf chore(server): remove stream generic from new Connection type 2017-10-27 16:04:28 -07:00
Sean McArthur
f7532b71d1 feat(lib): add support to disable tokio-proto internals
For now, this adds `client::Config::no_proto`, `server::Http::no_proto`,
and `server::Server::no_proto` to skip tokio-proto implementations, and
use an internal dispatch system instead.

`Http::no_proto` is similar to `Http::bind_connection`, but returns a
`Connection` that is a `Future` to drive HTTP with the provided service.
Any errors prior to parsing a request, and after delivering a response
(but before flush the response body) will be returned from this future.

See #1342 for more.
2017-10-27 00:02:07 -07:00
Sean McArthur
9c80fdbb9e refactor(lib): rename http_types to http 2017-09-29 18:12:55 -07:00
Sean McArthur
5027435791 refactor(lib): rename internal http module to proto 2017-09-28 18:28:44 -07:00
Sean McArthur
dd54f20b55 feat(server): add experimental pipeline flush aggregation option to Http
By enabling `Http::pipeline`, the connection will aggregate response
writes to try to improve sending more responses in a single syscall.
2017-09-22 15:39:33 -07:00
Michael Smith
16e834d37c feat(server): remove unneeded Send + Sync from Server
Http and Server placed Send + Sync bounds on NewService implementations which
were not actually required given tokio's event loop model. Remove them to reduce
limitations on end users of hyper.
2017-09-22 12:25:53 -07:00
Sam Rijs
0c7d375ba3 feat(lib): implement compatibility with http crate 2017-09-22 12:07:57 -07:00
Sean McArthur
c165db495e perf(server): put inline on all wrapper methods 2017-06-25 11:51:43 -07:00
Corey Farwell
1059eb349a style(lib): address clippy code style warnings
* Remove unnecessary return statements.

* Combine identical `match` arms.

* Collapse nested conditional.

* Use `assert_ne` where applicable.

* Lifetime elision.
2017-06-12 20:16:20 -07:00
David Ross
70948a24b0 fix(http,server): Update tests to use non-deprecated futures methods.
These seem mostly to be renames, with the exception of Unpark -> Notify.
2017-06-02 23:33:19 -07:00
Sander Maijers
c07872951b docs(server): refer to bind method, not serve
Fixes #1180.
2017-05-20 15:08:41 +02:00
Nick Gonzales
864d3e27a4 refactor(http): merge Request and Response from server and client
Request and Response are now visible from:
- hyper::{Request, Response}
- hyper::server::{Request, Response}
- hyper::client::{Request, Response}
They truly exist in the http module, but are re-exported to reduce the number of breaking changes.

request::new and response::new were renamed to ::from_wire to reduce confusion with Request::new
and Response::new. See issue #1126

Request now has an optional Body, because not all requests have bodies.
Use body_ref() to determine if a body exists.
Use body() to take the body, or construct one if no body exists.

Closes #1155

BREAKING CHANGE: Response::body() now consumes the response
2017-05-01 14:22:07 -06:00
Sean McArthur
d63b7de44f feat(client): Response.status() now returns a StatusCode
Previously, it would return `&StatusCode`. Returning a reference was
actually bigger than the enum itself, and prevented using `Into` on the
return result directly.

BREAKING CHANGE: If you were explicitly checking the status, such as
  with an equality comparison, you will need to use the value instead of a
  reference.
2017-03-31 15:13:55 -07:00
Alex Crichton
8554904dc9 refactor(lib): convert usage of tokio_core::io to tokio_io
This commit updates to the most recent versions (released today) of the various
Tokio libraries in use. Namely the `tokio_core::io` module has now been
deprecated in favor of an external `tokio-io` crate. This commit pulls in that
crate and uses the `AsyncRead + AsyncWrite` abstraction instead of `Io` from
tokio-core.

BREAKING CHANGE: Any external types that were using that had implemented `Io` will need to 
  implement `AsyncRead + AsyncWrite` from tokio_io.
2017-03-17 17:31:44 -07:00
Sean McArthur
dc97dd77f4 feat(server): make Http default its body type to hyper::Chunk 2017-02-22 16:30:20 -08:00
Sean McArthur
a3252c464d feat(server): change Server.run_until Future Error to ()
BREAKING CHANGE: The `run_until` future used to require its `Error` to
  be `hyper::Error`, now it can be `()`.
2017-02-17 13:48:17 -08:00
Sean McArthur
e04bcc12a7 feat(server): make Http compatible with TcpServer
This implements `From<Message> for Request` and `Into<Message> for
Response`, allowing an `Http` instance to be used with a `TcpServer`
from tokio-proto.

Closes #1036

BREAKING CHANGE: This makes `Request.remote_addr` an
  `Option<SocketAddr>`, instead of `SocketAddr`.
2017-02-16 18:26:36 -08:00
Sean McArthur
1b1311a7d3 feat(http): allow specifying custom body streams 2017-02-16 15:06:55 -08:00
Alex Crichton
f45e9c8e4f refactor(server): expose Http that implements ServerProto
The main changes are:

* The entry point is how `Http`, the implementation of `ServerProto`.
  This type has a `new` constructor as well as builder methods to
  configure it.

* A high-level entry point of `Http::bind` was added which returns a
  `Server`. Binding a protocol to a port requires a socket address
  (where to bind) as well as the instance of `NewService`. Internally
  this creates a core and a TCP listener.

* The returned `Server` has a few methods to learn about itself, e.g.
  `local_addr` and `handle`, but mainly has two methods: `run` and
  `run_until`.

* The `Server::run` entry point will execute a server infinitely, never
  having it exit.

* The `Server::run_until` method is intended as a graceful shutdown
  mechanism. When the provided future resolves the server stops
  accepting connections immediately and then waits for a fixed period of
  time for all active connections to get torn down, after which the
  whole server is torn down anyway.

* Finally a `Http::bind_connection` method exists as a low-level entry
  point to spawning a server connection. This is used by `Server::run`
  as is intended for external use in other event loops if necessary or
  otherwise low-level needs.

BREAKING CHANGE: `Server` is no longer the pimary entry point. Instead,
  an `Http` type is created  and then either `bind` to receiver a `Server`,
  or it can be passed to other Tokio things.
2017-01-18 14:09:20 -08:00
Guillaume Gomez
9036443e6b feat(uri): redesign RequestUri type into Uri
Closes #1000

BREAKING CHANGE: The name of `RequestUri` has changed to `Uri`. It is no
  longer an `enum`, but an opaque struct with getter methods.
2017-01-17 16:46:24 -08:00
Sean McArthur
be461b4663 perf(http): introduce MemBuf, a shared read buffer 2017-01-16 10:50:35 -08:00
Sean McArthur
2d2d5574a6 feat(lib): redesign API to use Futures and Tokio
There are many changes involved with this, but let's just talk about
user-facing changes.

- Creating a `Client` and `Server` now needs a Tokio `Core` event loop
to attach to.
- `Request` and `Response` both no longer implement the
`std::io::{Read,Write}` traits, but instead represent their bodies as a
`futures::Stream` of items, where each item is a `Chunk`.
- The `Client.request` method now takes a `Request`, instead of being
used as a builder, and returns a `Future` that resolves to `Response`.
- The `Handler` trait for servers is no more, and instead the Tokio
`Service` trait is used. This allows interoperability with generic
middleware.

BREAKING CHANGE: A big sweeping set of breaking changes.
2017-01-16 10:44:27 -08:00
Dmitry Gritsay
334c4800bb docs(server): fix Response::set_status() documentation 2017-01-07 15:01:37 +02:00
Joe Wilm
934f2c481b fix(http): Connection checks for spurious timeouts
We've been seeing a strange number of timeouts in our benchmarking.
Handling spurious timeouts as in this patch seems to fix it!

Note that managing the `timeout_start` needs to be done carefully. If
the current time is provided in the wrong place, it's possible requests
would never timeout.
2016-10-07 17:59:47 -07:00
Joe Wilm
c32d0e9adf fix(http): stackoverflow in Conn::ready
I've had a couple of instances during stress testing now where
Conn::ready would overflow its stack due to recursing on itself. This
moves subsequent calls to ready() into a loop outside the function.
2016-10-06 18:02:26 -07:00
Ahmed Charles
8b3c120684 feat(server): add path() and query() to Request
Closes #896 
Closes #897

BREAKING CHANGE: `RequestUri::AbsolutePath` variant is changed to a struct variant. Consider using `req.path()` or `req.query()` to get the relevant slice.
2016-08-29 13:45:38 -07:00
Ed Barnard
d67dbc6028 feat(server): Server::new can take one or more listeners
Closes #859
2016-07-18 15:32:38 -07:00
Sean McArthur
976218badc feat(client): add keep_alive_timeout to Client 2016-07-14 19:55:55 -07:00
Sean McArthur
02cb96ac2d feat(server): add idle_timeout to Server
Closes #790
2016-07-14 17:23:13 -07:00
Sean McArthur
40745c5671 refactor(lib): moved LanguageTag export to header
BREAKING CHANGE: LanguageTag used to be at the crate root, but it is now
  in the `hyper::header` module.
2016-07-14 09:59:47 -07:00
Sean McArthur
006f66f34a fix(client): handle when DNS resolves after a timeout triggers
Closes #848
2016-07-13 14:48:11 -07:00
Robin Stocker
61346207aa docs(server): Fix some typos in server module 2016-06-30 11:52:12 -07:00
Sean McArthur
2fbd80ce69 feat(server): add Transport to on_request 2016-06-23 15:29:30 -07:00
Sean McArthur
dabe3ac0b1 Merge pull request #827 from hyperium/enc-dec-get-ref
add get_ref methods to Encoder and Decoder
2016-06-14 20:18:28 +02:00
Sean McArthur
766377cfe7 feat(http): add get_ref methods to Encoder and Decoder 2016-06-14 10:55:37 -07:00
leonardo.yvens
d4a095d75c refactor(multiple): Clippy run 2016-06-12 15:17:15 -03:00
Justin Mayhew
8f1c536007 docs(*): fix typos, Markdown inconsistencies, and stutter 2016-05-20 11:42:29 -03:00
Sean McArthur
d35992d019 feat(lib): switch to non-blocking (asynchronous) IO
BREAKING CHANGE: This breaks a lot of the Client and Server APIs.
  Check the documentation for how Handlers can be used for asynchronous
  events.
2016-05-16 09:51:18 -07:00
Sean McArthur
e7229480ea fix(warnings): remove unused_code warnings from newest nightlies 2016-05-09 11:51:51 -07:00
Sean McArthur
f36c6b255f feat(client): proper proxy and tunneling in Client
Closes #774
2016-05-02 12:33:49 -07:00
Johan Lorenzo
5c8b63028c docs(server): add a warning to Listening::close() in order to reflect #338 2016-02-19 14:25:12 +01:00
Steven Fackler
92ff50f2e5 fix(server): Flush 100-continue messages
Closes #704
2015-12-18 16:00:49 -08:00
Karl Hobley
1077440c4d test(server): Add test for GET request with body 2015-11-29 18:06:44 +00:00
Karl Hobley
0b05c5903e fix(server): Removed check for GET/HEAD request when parsing body
Fixes #698
2015-11-29 18:06:44 +00:00