Commit graph

14 commits

Author SHA1 Message Date
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
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
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
David Pedersen
6c1279a415 Version 0.1.1 2021-07-30 17:20:38 +02:00
David Pedersen
ca34b4184a Update changelog for 0.1.0 release 2021-07-30 17:17:25 +02:00
David Pedersen
002e3f92b3
Misc repo setup (#7) 2021-06-12 20:18:21 +02:00