Commit Graph

133 Commits

Author SHA1 Message Date
Sean McArthur
cd9fd52207 refactor(header): Host header internals made private
This allows us to improve the performance. For now, a Cow is used
internally, so clients can set the host to a static value and no longer
need copies.

Later, we can change it to also possibly have a MemSlice.

BREAKING CHANGE: The fields of the `Host` header are no longer
  available. Use the getter methods instead.
2017-01-16 10:50:36 -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
Markus Unterwaditzer
9375addba0 feat(headers): Headers::remove returns the Header
Closes #891

BREAKING CHANGE: `Headers.remove()` used to return a `bool`,
  it now returns `Option<H>`. To determine if a a header exists,
  switch to `Headers.has()`.
2016-08-23 16:46:07 -04:00
Anthony Ramine
de921d08fe chore(version): Update serde to 0.8 2016-08-02 09:39:10 +02:00
Sean McArthur
50ccdaa7e7 feat(header): introduce header::Raw (#869)
The Raw type repesents the raw bytes of a header-value.

Having a special type allows a couple of benefits:

- The exact representation has become private, allowing "uglier"
internals. Specifically, since the common case is for a header to only
have 1 line of bytes, an enum is used to skip allocating a Vec for only
1 line. Additionally, a Cow<'static, [u8]> is used, so static bytes
don't require a copy. Finally, since we can use static bytes, when
parsing, we can compare the incoming bytes against a couple of the most
common header-values, and possibly remove another copy.

- As its own type, the `Headers.set_raw` method can be generic over
`Into<Raw>`, which allows for more ergnomic method calls.

BREAKING CHANGE: `Header::parse_header` now receives `&Raw`, instead of
  a `&[Vec<u8>]`. `Raw` provides several methods to ease using it, but
  may require some changes to existing code.
2016-07-23 12:54:16 -07:00
Sean McArthur
3e66377979 refactor(header): internalize traitobject and typeable 2016-07-14 17:27:59 -07:00
Andre Silva
f38717e422 fix(headers): Remove raw part when getting mutable reference to typed header
If you get a mutable reference to a typed header it is possible to make
the two representations be out of sync. To avoid this, after parsing the
raw part it should be removed.

Fixes #821.
2016-06-20 15:12:30 -07:00
leonardo.yvens
d4a095d75c refactor(multiple): Clippy run 2016-06-12 15:17:15 -03:00
Sean McArthur
d80d61cd78 perf(headers): check for header literals before allocating name 2016-06-01 15:09:54 -07:00
Sean McArthur
9338878576 perf(headers): use a Vec instead of HashMap internally 2016-06-01 11:56:35 -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
Manish Goregaokar
b840963629 docs(*): Clippy fixes with markdown docs 2016-05-05 22:50:23 +05:30
debris
33d5da2136 refactor(headers): updated serde to version 0.7 2016-02-27 15:04:30 +01:00
Corey Farwell
4c7f6f0c1e style(all): Address suggestions made by rust-clippy 2015-12-23 08:59:45 -08:00
Prabhjyot Singh Sodhi
76cbf38423 feat(headers): add PartialEq impl for Headers struct
compare the raw representations of the headers for the lack of a better alternative
helpful when asserting HttpRequest/ HttpResponse in tests elsewhere
2015-09-17 10:40:10 +05:30
Erick Tryzelaar
3a3c8b69a7 refactor(serde): Minor serde micro-optimizations 2015-08-31 21:49:05 -07:00
Patrick Walton
f5f5e1cb2d fix(headers): fix broken deserialization of headers
Sorry about that!
2015-07-23 20:58:35 -07:00
Sean McArthur
da817ba8bf test(header): change test_headers_show to use str.contains 2015-07-23 12:09:55 -07:00
Sean McArthur
a0739e6c96 test(headers): fix test_headers_show() 2015-07-23 11:53:46 -07:00
Sean McArthur
74021a24fe test(headers): remove usage of iter.join() 2015-07-23 11:38:26 -07:00
Sean McArthur
d2e8b5dc3d fix(tests): iter.connect() is now iter.join() 2015-07-22 19:01:33 -07:00
Patrick Walton
87de1b77bc feat(http): add optional serialization of common types via serde
This is behind a Cargo feature to avoid forcing downstream users to
depend on `serde`. It is needed for Servo IPC to work.
2015-07-10 17:45:08 -07:00
Pyfisch
db93ca0697 style(rustfmt): run rustfmt on hyper correct overlong lines 2015-06-29 20:22:22 +02:00
Sean McArthur
306f39c731 chore(logging): add some trace! logging to headers 2015-06-17 11:37:26 -07:00
Ryman
8275f3b9e3 docs(header): fix typos and minor rewording 2015-06-13 16:53:26 +01:00
Sean McArthur
a8e29efdec docs(header): greatly expand on implementing custom headers 2015-06-12 15:20:58 -07:00
Pyfisch
195a89fa91 refactor(headers): errors for parse_header
Header::parse_header() returns now a hyper Result instead of an option
this will enable more precise Error messages in the future, currently
most failures are reported as ::Error::Header.

BREAKING CHANGE: parse_header returns Result instead of Option, related
code did also change
2015-06-10 22:22:56 +02:00
Sean McArthur
7e3858c962 perf(all): replace &str.to_string() with .to_owned() 2015-05-12 23:01:58 -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
Pyfisch
db4d89189a style(headers): Break lines with over 100 characters 2015-05-03 15:45:11 +02:00
Pyfisch
66d54d03e7 refactor(headers): Improve docs, fix nits, make formatting faster
src/header/parsing.rs now uses unsafe get_unchecked() again, I don't
know why it was removed.
2015-05-03 13:56:32 +02:00
Pyfisch
6b59bd28b7 refactor(hyper): Fix a few nits 2015-05-01 11:58:15 +02:00
Pyfisch
308880b455 feat(headers): Implement Content-Language header field
Closes #475
2015-04-27 21:50:57 +02:00
Sean McArthur
4f09b002ff feat(log): clean up logging 2015-04-15 21:08:52 -07:00
Sean McArthur
55b37f0148 test(beta): enable testing on beta rustc 2015-04-15 11:59:23 -07:00
Jonathan Reem
8e0655637e fix(headers): Add CowStr as a temporary hack to build on beta.
We can revert this PR when rust-lang/rust#23995 lands, but it won't
land until after beta is cut.
2015-04-02 22:33:55 -07:00
Sean McArthur
5c2de29a81 chore(stability): remove core feature gate 2015-04-02 17:32:04 -07:00
Jonathan Reem
320d10d50d chore(all): Move downcasting to a stable implementation. 2015-04-02 13:30:41 -07:00
Sean McArthur
ccd4814e69 chore(stability): remove into_cow feature gate 2015-04-02 13:01:49 -07:00
Pyfisch
6cf052bf0f refactor(header): Implement HttpDate, a wrapper for dates
Using `time::Tm` directly in HTTP header fields requires special handling to parse and format
the header values., this stops us from using the header macros. By wrapping `time::Time` in a
`HttpDate`, we can use the `FromStr` and `Display` traits of `HttpDate` like for most other values.

BREAKING_CHANGE: All code using one of the `Date`, `Expires`, `If-Modified-Since`,
`If-Unmodified-Since`, `Last-Modified` header fields needs to wrap `time::Tm`
with `HttpDate`. Removed `FromStr` trait of `Date`, `If-Modified-Sice` and `If-Unmodified-Sice`,
implementing the trait here is inconsistent with other headers.
2015-03-31 17:29:31 +02:00
Sean McArthur
a62323cafe refactor(hyper): remove need for collections feature 2015-03-27 11:50:14 -07:00
Florian Hartwig
3e456f00f9 fix(rustup): rustc 1.0.0-nightly (123a754cb 2015-03-24)
* fix `extern crate` declaration for rustc-serialize
* enable `into_cow` feature
* replace as_slice() calls by as_ref and enable `convert` feature
* use `core` feature in doc tests
2015-03-25 20:55:42 +01:00
Sebastian Thiel
8181de253a fix(rustup): rustc 1.0.0-nightly (ea8b82e90)
This commit fixes `cargo build` and `cargo test`.

Method lookup on traits seems to have changed to force
`impl TraitName` expressions to be more specific. That means that
`method` will not be found anymore on an object of type `&Trait+Send`,
unless you provide an `impl Trait+Send`.

Now `NetworkStream` and `HeaderFormat` trait implementations
are done against `* + Send`, which helps the compiler to find the
respective `downcast*` method implementations once again.
2015-03-20 10:28:35 +01: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
fdc78f8f89 Merge pull request #358 from hyperium/reparsing
feat(headers): adds re-parsing ability when getting typed headers
2015-03-03 20:47:47 -08:00
Hugo Duncan
180d9a92d9 feat(headers): add enum for Charset
Make Charset more strongly typed.
2015-03-03 20:46:41 -08:00
Sean McArthur
d68773c79f feat(headers): add q function to ease creating Quality values 2015-03-03 19:32:37 -08:00
Sean McArthur
df756871ed feat(headers): adds re-parsing ability when getting typed headers
BREAKING CHANGE: added requirement that all HeaderFormat implementations
  must also be fmt::Debug. This likely as easy as slapping
  #[derive(Debug)] on to any custom headers.
2015-03-03 18:51:29 -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
Pyfisch
8f6ce453de refactor(headers): Use u16 based newtype for quality value
Using floating point numbers is problematic because comparison is inexact.
They also take more space than integral numbers in this case.

Add `FromPrimitve`, `ToPrimitive` and `Default` traits to quality newtype.

Closes: #330

BREAKING_CHANGE: Replace f32 quality values in quality items with a
Quality(u16) newtype. Valid values are from 0 to 1000.
2015-02-28 19:44:34 +01:00