Commit Graph

175 Commits

Author SHA1 Message Date
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
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
1ec9b5a327 docs(examples): remove unnecessary Clone and Copy from Echo 2017-06-12 11:22:20 -07:00
Sean McArthur
7f6673c4cd docs(examples): remove distracting derive(Clone, Copy) from Hello 2017-05-12 16:35:27 -07:00
Sean McArthur
4fb7e6ebc6 feat(lib): remove extern Url type usage
BREAKING CHANGE: The `Url` type is no longer used. Any instance in the
  `Client` API has had it replaced with `hyper::Uri`.

  This also means `Error::Uri` has changed types to
  `hyper::error::UriError`.

  The type `hyper::header::parsing::HTTP_VALUE` has been made private,
  as an implementation detail. The function `http_percent_encoding`
  should be used instead.
2017-03-21 11:03:57 -07:00
Eric Chiang
2331e0b3e5 refactor(examples): remove use of depricated futures features
The "Finished" struct and "finished" method have been deprecated[0]
and don't show up in the futures docs. Prefer non-deprecated
features for users exploring the examples.

[0] https://github.com/alexcrichton/futures-rs/blob/0.1.10/src/future/mod.rs#L25
2017-02-08 10:54:23 -08:00
Sean McArthur
352b31f67d docs(examples): print that examples are using only 1 thread 2017-02-01 15:47:07 -08:00
Sean McArthur
8f8b8618cd refactor(examples): remove log crate from server example 2017-01-23 13:31:39 -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
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
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
Sean McArthur
85894bc123 feat(http): add Decoder.try_read and Encoder.try_write 2016-07-14 10:01:57 -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
Sean McArthur
2fbd80ce69 feat(server): add Transport to on_request 2016-06-23 15:29:30 -07:00
Kei Tsuji
341b784106 fix(examples): hello example fix for multithread (#808) 2016-05-27 10:05:27 -07: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
f36c6b255f feat(client): proper proxy and tunneling in Client
Closes #774
2016-05-02 12:33:49 -07:00
Erick Tryzelaar
63608c49c0 fix(examples): "cargo test --features serde-serialization" 2015-08-31 21:49:27 -07: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
64e47b4bbd feat(client): impl Sync for Client
Connector::connect already used &self, and so would require
synchronization to be handled per connector anyway. Adding Sync to the
Client allows users to setup config for a Client once, such as using a
single connection Pool, and then making requests across multiple
threads.

Closes #254

BREAKING CHANGE: Connectors and Protocols passed to the `Client` must
  now also have a `Sync` bounds, but this shouldn't break default usage.
2015-06-12 11:19:54 -07:00
Sean McArthur
71ac65da5b refactor(http): move h1 and h2 into http module 2015-06-02 12:24:56 -07:00
Marko Lalic
6504936023 docs(examples): add an example using an HTTP/2 client 2015-06-02 15:44:12 +02:00
Sean McArthur
c2938fb45f feat(header): add Connection::close() and ::keep_alive() constructors 2015-05-11 19:14:43 -07:00
Sean McArthur
3334fca278 fix(client): dont call close() inside Request
Only call close() in the Response, which should already return a
responding `Connection: close`.

Closes #519
2015-05-09 22:20:13 -07:00
Sean McArthur
d5558b687d feat(server): add Response.send to write a sized body
Closes #446
2015-05-07 11:03:45 -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
a5ce9c59fa fix(header): make test_module of header! optional
Closes #490
2015-05-01 14:27:17 -07: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
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
Sean McArthur
a9887c87f2 test(examples): fix warnings in examples 2015-03-03 21:05:52 -08:00
Sean McArthur
0fd6fcd7c7 feat(hyper): switch to std::io, std::net, and std::path.
All instances of `old_io` and `old_path` were switched to use the new
shiny `std::io`, `std::net`, and `std::path` modules. This means that
`Request` and `Response` implement `Read` and `Write` now.

Because of the changes to `TcpListener`, this also takes the opportunity
to correct the method usage of `Server`. As with other
languages/frameworks, the server is first created with a handler, and
then a host/port is passed to a `listen` method. This reverses what
`Server` used to do.

Closes #347

BREAKING CHANGE: Check the docs. Everything was touched.
2015-03-03 14:32:03 -08:00
Renato Zannon
039e984f68 fix(rustup): Remove uses of the obsolete &a[] syntax 2015-02-21 15:05:50 -08:00
Renato Zannon
b47f936525 fix(rustup): update feature flags 2015-02-21 15:05:50 -08:00
Jonathan Reem
3528fb9b01 feat(server): Rewrite the accept loop into a custom thread pool.
This is a modified and specialized thread pool meant for
managing an acceptor in a multi-threaded way. A single handler
is provided which will be invoked on each stream.

Unlike the old thread pool, this returns a join guard which
will block until the acceptor closes, enabling friendly behavior
for the listening guard.

The task pool itself is also faster as it only pays for message passing
if sub-threads panic. In the optimistic case where there are few panics,
this saves using channels for any other communication.

This improves performance by around 15%, all the way to 105k req/sec
on my machine, which usually gets about 90k.

BREAKING_CHANGE: server::Listening::await is removed.
2015-02-14 13:54:57 -08:00
Sean McArthur
db83e0490b chore(rustup): fix std::env changes 2015-02-13 11:19:19 -08:00
Corey Farwell
00e46d7cda chore(examples): Stop using deprecated std::os::args in example
As per this compiler warning

"warning: use of deprecated item: use std::env::args() instead, #[warn(deprecated)] on by default"
2015-02-11 23:11:14 -05:00
Sean McArthur
05a3a6b70b fix(rustup): fix unused_feature warning in example server 2015-02-01 20:39:09 -08:00
Sean McArthur
3af8b687d4 fix(rustup): switch to unstable features 2015-01-31 12:15:44 -08:00
Christian Stefanescu
f606b6039d fix(rustup): update io import, Writer::write
Make it build with the latest rust-nightly (2015-01-27)

Renamed io import to old_io.
Renamed Writer::write to Writer::write_all
2015-01-28 11:58:45 -08:00
Pyfisch
8d0e5bc302 refactor(headers): export all headers and utils directly under header
Currently headers are exported at many places. For example you can access
`Transfer-Encoding` header at `header`, `header::common` and
`header::common::transfer_encoding`. Per discussion on IRC with
@seanmonstar and @reem, all contents of headers will be exposed at `header`
directly. Parsing utilities will be exposed at `header::parsing`. Header
macros can now be used from other crates.

This breaks much code using headers. It should use everything it needs
directly from `header::`, encodings are exposed at `header::Encoding::`,
connection options are exposed at `header::ConnectionOption`.
2015-01-20 13:04:42 +01:00
Sean McArthur
f7124bb8e2 rustup: sweeping fixes for all the changes in 1.0-alpha
- Some switches to u64 instead of usize
- For now, allow(unstable)
- use associated types for all the Network stuff
2015-01-10 21:29:27 -08:00
cyderize
122e94c8a6 Update for latest rust
Tracks rust nightly.

7 tests fail -- still finding source
2015-01-10 18:37:10 +11:00
Robin Gloster
da0597510a macro syntax changes 2015-01-07 21:30:03 +01:00
Aaron Weiss
be6cc34caf Server programs no longer exit immediately. 2014-12-21 16:23:48 -05:00
Jonathan Reem
618f95e10a (fix) Update examples and benchmarks to remove rust-http. 2014-12-20 03:07:05 -08:00
Sean McArthur
8c83a3358e feat(client): add a new Client struct with super powers
- Includes ergonomic traits like IntoUrl and IntoBody, allowing easy
usage.
- Client can have a RedirectPolicy.
- Client can have a SslVerifier.

Updated benchmarks for client. (Disabled rust-http client bench since it
hangs.)
2014-12-14 11:56:39 -08:00