Commit Graph
124 Commits
Author SHA1 Message Date
David Pedersen a8eb26b672 Fix typos in rejection messages 2021-08-05 08:36:42 +02:00
David Pedersen a95b48b70c Deprecate QueryStringMissing (#119)
Since https://github.com/tokio-rs/axum/pull/117 its no longer used. Will
be removed in 0.2.
2021-08-04 17:58:34 +02:00
SunliandDavid Pedersen fb0b3b78eb Fix Query and Form extractors giving bad request error when query string is empty (#117)
Co-Authored-By: David Pedersen <[email protected]>

Co-authored-by: David Pedersen <[email protected]>
2021-08-04 17:13:09 +02:00
David Pedersen 5c12328892 Replace hyper::Server with axum::Server in docs (#118)
* Replace `hyper::Server` with `axum::Server` in docs

* Change readme as well
2021-08-04 15:38:51 +02:00
David Pedersen cffdedc055 Move comments in docs outside code block 2021-08-04 15:07:04 +02:00
David Pedersen 96fac52519 Make docs on required deps more clear 2021-08-04 15:06:47 +02:00
SunliandDavid Pedersen 7cf8dafdce Re-export http crate and hyper::Server (#110)
Co-Authored-By: David Pedersen <[email protected]>

Co-authored-by: David Pedersen <[email protected]>
2021-08-04 12:29:42 +02:00
Jonas Platte d285dfb568 Tell clippy about MSRV (#114)
* Remove unused import

* Tell clippy about MSRV
2021-08-04 12:15:58 +02:00
Jonas Platte 015f6e0c21 Fix typos found by typos-cli (#113) 2021-08-04 12:09:39 +02:00
David Pedersen 9a6bc4e962 Break up extract.rs (#103)
This breaks up `extract.rs` into several smaller submodules. The public
API remains the same.

This is done in prep for adding more tests to extractors which would get
messy if they were all in the same file.
2021-08-03 21:55:48 +02:00
PatatasDelPapa 715e624d8c Remove unused imports from example (#104)
Remove unused imports from the first crate documentation example.
2021-08-03 21:55:27 +02:00
Sunli be68227d73 Use pin-project-lite instead of pin-project (#95) 2021-08-03 09:33:00 +02:00
Sunli ba74787532 Add support for WebSocket protocol negotiation. (#83) 2021-08-03 08:43:37 +02:00
David Pedersen 6a078ddb71 Fix stripping prefix when nesting at / (#91)
* Fix stripping prefix when nesting at `/`

Fixes https://github.com/tokio-rs/axum/issues/88

* changelog
2021-08-02 22:40:33 +02:00
David Pedersen a0f6dccc5e Remove dbg! left in by accident 2021-08-02 09:46:08 +02:00
David Pedersen 55c1a29420 Version 0.1.2 (#80) 2021-08-01 22:13:43 +02:00
David Pedersen 6d787665d6 Server-Sent Events (#75)
Example usage:

```rust
use axum::{prelude::*, sse::{sse, Event, KeepAlive}};
use tokio_stream::StreamExt as _;
use futures::stream::{self, Stream};
use std::{
    time::Duration,
    convert::Infallible,
};

let app = route("/sse", sse(make_stream).keep_alive(KeepAlive::default()));

async fn make_stream(
    // you can also put extractors here
) -> Result<impl Stream<Item = Result<Event, Infallible>>, Infallible> {
    // A `Stream` that repeats an event every second
    let stream = stream::repeat_with(|| Event::default().data("hi!"))
        .map(Ok)
        .throttle(Duration::from_secs(1));

    Ok(stream)
}
```

Implementation is based on [warp's](https://github.com/seanmonstar/warp/blob/master/src/filters/sse.rs)
2021-08-01 21:49:17 +02:00
David Pedersen c232c56de0 Mention required dependencies in docs (#77)
Fixes https://github.com/tokio-rs/axum/issues/70
2021-08-01 21:33:55 +02:00
David Pedersen 69ae7a686a Fix websockets failing on Firefox (#76)
Axum expected the `Connection` header to be _exactly_ `upgrade`. Turns
out thats a bit too strict as this didn't work in Firefox.

Turns out `Connection` just has to contain `upgrade`. At least that is
what [warp does](https://github.com/seanmonstar/warp/blob/master/src/filters/ws.rs#L46).
2021-08-01 21:00:38 +02:00
jtroo 10bedca796 Fix typos in service docs (#74)
This commit fixes some typos and improves the grammar/structure
of some sections.
2021-08-01 20:55:09 +02:00
David Pedersen 2cf28c6794 Improve error message of MissingExtension rejections (#72)
Now includes the name of missing type.
2021-08-01 15:50:57 +02:00
David Pedersen 6f30d4aa6a Improve documentation for router (#71)
Fixes #67
2021-08-01 15:42:50 +02:00
David Pedersen f581e3efb2 Clarify required response body type when routing to tower::Services (#69) 2021-08-01 15:42:12 +02:00
David Pedersen f67abd1ee2 Add extractor for remote connection info (#55)
Fixes https://github.com/tokio-rs/axum/issues/43

With this you can get the remote address like so:

```rust
use axum::{prelude::*, extract::ConnectInfo};
use std::net::SocketAddr;

let app = route("/", get(handler));

async fn handler(ConnectInfo(addr): ConnectInfo<SocketAddr>) -> String {
    format!("Hello {}", addr)
}

// Starting the app with `into_make_service_with_connect_info` is required
// for `ConnectInfo` to work.
let make_svc = app.into_make_service_with_connect_info::<SocketAddr, _>();

hyper::Server::bind(&"0.0.0.0:3000".parse().unwrap())
    .serve(make_svc)
    .await
    .expect("server failed");
```

This API is fully generic and supports whatever transport layer you're using with Hyper. I've updated the unix domain socket example to extract `peer_creds` and `peer_addr`.
2021-07-31 21:36:30 +02:00
David Pedersen 407aa533d7 Return 405 Method Not Allowed for unsupported method for route (#63)
Fixes https://github.com/tokio-rs/axum/issues/61
2021-07-31 21:05:53 +02:00
songww 49dd1ca49a Fix docs typo (#58) 2021-07-31 17:17:33 +02:00
David Pedersen 5407247e90 Implement Deref for extractors (#56)
Fixes https://github.com/tokio-rs/axum/issues/54
2021-07-31 14:54:10 +02:00
David Pedersen d88212c015 Implement Sink and Stream for WebSocket (#52)
Among other things, this makes [`StreamExt::split`](https://docs.rs/futures/0.3.16/futures/stream/trait.StreamExt.html#method.split) accessible so one can read and write at the same time.
2021-07-31 10:51:41 +02:00
Eduardo Canellas 4fbc99c6ef docs: fix typo (#45) 2021-07-31 00:06:27 +02:00
David Pedersen 6c1279a415 Version 0.1.1 2021-07-30 17:20:38 +02:00
David Pedersen 94d2b5f8a6 Misc readme/docs improvements 2021-07-30 15:51:59 +02:00
David Pedersen d843f4378b Make websocket handlers support extractors (#41) 2021-07-30 15:19:53 +02:00
David Pedersen d927c819d3 Clarify docs around body extractors 2021-07-23 00:27:08 +02:00
David Pedersen f25f7f90ff Implement IntoResponse for Body 2021-07-22 21:22:46 +02:00
David Pedersen 1fb80a1129 Implement IntoResponse for HeaderMap 2021-07-22 21:21:53 +02:00
David Pedersen ba9c03d146 Update links 2021-07-22 19:39:08 +02:00
David Pedersen 7c37bb818a Update goals in readme 2021-07-22 15:44:59 +02:00
David Pedersen e4a0199c76 Add missing TOC link 2021-07-22 15:38:55 +02:00
David Pedersen 8faed8120f Docs improvements (#37) 2021-07-22 15:00:33 +02:00
David Pedersen a658c94f23 Use correct error type if Json serialization fails
Fixes https://github.com/davidpdrsn/axum/issues/35
2021-07-22 13:26:14 +02:00
David Pedersen f32d325e55 Make extractors easier to write (#36)
Previously extractors worked directly on `Request<B>` which meant you
had to do weird tricks like `mem::take(req.headers_mut())` to get owned
parts of the request.

This changes that instead to use a new `RequestParts` type that have
methods to "take" each part of the request. Without having to do weird
tricks.

Also removed the need to have `B: Default` for body extractors.
2021-07-22 13:23:50 +02:00
David Pedersen e544fe1c39 More flexible generic responses 2021-07-22 11:14:55 +02:00
David Pedersen 028c472c84 Add Multipart extractor for consuming multipart/form-data requests (#32)
Multipart implementation on top of `multer`
2021-07-14 16:53:37 +02:00
David Pedersen e641caefaf Remove hyper-h1 and hyper-h2 features (#31) 2021-07-14 16:29:06 +02:00
David Pedersen 341ad61240 Clarify body extractors 2021-07-10 23:46:14 +02:00
David Pedersen 62da1eac00 Allow extractor_middleware to extract the body 2021-07-10 23:39:40 +02:00
David Pedersen 2e2f697f80 Minor docs improvements 2021-07-09 23:39:39 +02:00
David Pedersen 1cbd43cfc4 Add extractor_middleware (#29)
Converts an extractor into a middleware so it can be run for many routes
without having to repeat it in the function signature.
2021-07-09 23:38:59 +02:00
David Pedersen 5a5710d290 Rename to axum (#28) 2021-07-09 21:36:14 +02:00
David Pedersen 3cd4a1d6a6 Fix for service as bottom handler (#27)
Would previously fail because of a mismatch in error types.
2021-07-06 09:40:25 +02:00