Commit Graph

89 Commits

Author SHA1 Message Date
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
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
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
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
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
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
Sean McArthur
fec6e3e873 feat(all): add socket timeouts
Methods added to `Client` and `Server` to control read and write
timeouts of the underlying socket.

Keep-Alive is re-enabled by default on the server, with a default
timeout of 5 seconds.

BREAKING CHANGE: This adds 2 required methods to the `NetworkStream`
  trait, `set_read_timeout` and `set_write_timeout`. Any local
  implementations will need to add them.
2015-11-24 10:58:58 -08:00
Dean4Devil
29fc868064 docs(server): Fixing two small typos 2015-11-12 09:44:54 +01:00
Jonathan Reem
fa0848d421 feat(server): Add hooks for HttpListener and HttpsListener to be started from existing listeners.
This allows Servers to be started on existing TcpListeners.
2015-10-18 19:01:44 -07:00
Sean McArthur
cdaa2547ed fix(server): use a timeout for Server keep-alive
Server keep-alive is now **off** by default. In order to turn it on, the
`keep_alive` method must be called on the `Server` object.

Closes #368
2015-10-09 15:02:05 -07:00
Mike Dilger
6b6182e8c4 feat(server): Add Handler per-connection hooks 2015-09-02 08:45:37 +12:00
Sean McArthur
7d1f154cb7 feat(net): add socket timeouts to Server and Client
While these methods are marked unstable in libstd, this is behind a
feature flag, `timeouts`. The Client and Server both have
`set_read_timeout` and `set_write_timeout` methods, that will affect all
connections with that entity.

BREAKING CHANGE: Any custom implementation of NetworkStream must now
  implement `set_read_timeout` and `set_write_timeout`, so those will
  break. Most users who only use the provided streams should work with
  no changes needed.

Closes #315
2015-07-27 09:57:59 -07:00
Pyfisch
db93ca0697 style(rustfmt): run rustfmt on hyper correct overlong lines 2015-06-29 20:22:22 +02:00
Sean McArthur
53bba6eb7f feat(ssl): redesign SSL usage
BREAKING CHANGE: Server::https was changed to allow any implementation
  of Ssl. Server in general was also changed. HttpConnector no longer
  uses SSL; using HttpsConnector instead.
2015-06-20 14:58:58 -07:00
Sean McArthur
ae5c7276c0 docs(server): greatly expand how to use a Server 2015-06-13 17:02:35 -07:00
Sean McArthur
49b5b8fdfe feat(server): check Response headers for Connection: close in keep_alive loop
BREAKING CHANGE: Usage of Response.deconstruct() and construct() now use
  a &mut Headers, instead of the struct proper.
2015-05-12 17:47:55 -07:00
Sean McArthur
a9dcc59cd9 feat(server): dropping a Response will write out to the underlying stream 2015-05-06 15:12:38 -07:00
Sean McArthur
9ba074d150 refactor(error): remove redundant parts of error names
The old names followed the old style of including the module name and
"Error" in each variant. The new style is to refer to an error from its
owning module, and variants are now scoped to their enum, so there's no
need to include the enum name in the variant name.

BREAKING CHANGE: The terms `Http` and `Error` have been removed from the Error
  type and its variants. `HttpError` should now be accessed as `hyper::Error`,
  and variants like `HttpIoError` should be accessed as `Error::Io`.
2015-05-05 11:53:09 -07:00
Sean McArthur
1e72a8ab3a feat(client): add a Connection Pool
This adds a connection pool to the Client that is used by default. It
accepts any other NetworkConnector, and simply acts as a
NetworkConnector itself. Other Pools can exist by simply providing a
custom NetworkConnector. This Pool is only used by default if you also
use the default connector, which is `HttpConnector`. If you wish to use
the Pool with a custom connector, you'll need to create the Pool with
your custom connector, and then pass that pool to the
Client::with_connector.

This also adds a method to `NetworkStream`, `close`, which can be used
to know when the Stream should be put down, because a server requested
that the connection close instead of be kept alive.

Closes #363
Closes #41
2015-04-29 12:58:28 -07:00
Mike Dilger
3a1a24270d feat(server): allow consumer to supply an SslContext
Closes #471
2015-04-27 08:22:10 +12:00
Mike Dilger
fef04d282f refactor(server): make with_listener a free function
Allow a Server to operate without requiring the entire Server struct
to move into the with_listener function (instead only the handler
function needs to move). This, allows other members to not move, or
move separately, which will be needed for the next commit.  See #471
2015-04-27 08:19:31 +12:00
Sean McArthur
f9ea2dd594 docs(server): add basic usage example 2015-04-22 12:27:50 -07:00
Jorge Israel Peña
c694b1385b fix(server): JoinHandle type parameter
The new beta adopts the new `JoinHandle` API which has a type parameter.
2015-04-17 14:31:54 -07:00
Sean McArthur
0fb92ee735 feat(debug): add Debug impls for StatusClass, Server, and Listening 2015-04-16 10:04:51 -07:00
Sean McArthur
d9187713b2 fix(server): handle keep-alive closing
Closes #437
2015-04-15 20:12:26 -07:00
Sean McArthur
68d4d63c2a fix(server): join on thread when Listening drops
Closes #447
2015-04-15 16:44:48 -07:00
Jonathan Reem
e864956734 fix(server): Use thread::spawn instead of thread::scoped. 2015-04-15 13:15:05 -07:00
Sean McArthur
04e3b56515 fix(buffer): get_buf to not return consumed part of buffer
Closes #406
2015-03-29 21:20:09 -07:00
Sean McArthur
cb59f609c6 fix(http): read more before triggering TooLargeError
This includes a custom BufReader, since the one in libstd doesn't allow
reading additional data into the buffer without consuming it. This is
required because some connections may send shorter packets, and so we
need to perform multiple reads. After each read, the contents of the
buffer are passed to httparse to see if have a valid message. If so, the
proper amount of bytes are consumed. The additional bytes are left in
the buffer since they are the beginning of the body.

The buffer in this BufReader also grows in size, compared to the libstd
which is sized once. This is because we start with a smaller buffer,
since the majority of messages will be able to include their head in a
packet or 2. Therefore, it's a wasteful performance hit to allocate the
maximum size for every message. However, some headers can be quite big,
and to allow for many of them to be set, we include a maximum size. Once
we've hit the maximum buffer size, and still haven't determined the end
of the headers, a HttpTooLargeError will be returned.

Closes #389
2015-03-27 10:52:07 -07:00
Kevin Butler
eee7a85d3c fix(rustup): static bounds required on Type definition, trivial_casts 2015-03-26 17:02:20 +00:00
Sebastian Thiel
f547080df5 fix(rustup): 1.0.0-nightly (e2fa53e59 2015-03-20)
* replace `char_at()` calls with itertor, as suggested by compiler
* fixed comparison in test
2015-03-21 17:02:13 +01:00
Sean McArthur
5d7be77e4a feat(server): use SocketAddrs instead of Ipv4Addrs 2015-03-20 17:32:51 -07:00
Adrian Heine
1f0bc951c9 fix(rustup): adapt to current rustc
Closes #381.
2015-03-19 09:44:40 +01:00
Sean McArthur
0b7169432b feat(server): add Expect 100-continue support
Adds a new method to `Handler`, with a default implementation of always
responding with a `100 Continue` when sent an expectation.

Closes #369
2015-03-16 15:59:44 -07:00
Sean McArthur
4fd8a6a9dc fix(rustup): update to latest rustc 2015-03-16 12:01:38 -07:00
Sean McArthur
b87bb20f0c perf(http): changes http parsing to use httparse crate
httparse is a http1 stateless push parser. This not only speeds up
parsing right now with sync io, but will also be useful for when we get
async io, since it's push based instead of pull.

BREAKING CHANGE: Several public functions and types in the `http` module
  have been removed. They have been replaced with 2 methods that handle
  all of the http1 parsing.
2015-03-13 16:56:13 -07:00